Skip to content

Commit e7f3279

Browse files
committed
ffmpeg: Allocate InputStream.decoded_frame early
Based on a commit by Andreas Rheinhardt. Signed-off-by: James Almer <[email protected]>
1 parent ee3d6a2 commit e7f3279

File tree

2 files changed

+6
-9
lines changed

2 files changed

+6
-9
lines changed

fftools/ffmpeg.c

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2332,15 +2332,11 @@ static int send_frame_to_filters(InputStream *ist, AVFrame *decoded_frame)
23322332
static int decode_audio(InputStream *ist, AVPacket *pkt, int *got_output,
23332333
int *decode_failed)
23342334
{
2335-
AVFrame *decoded_frame;
2335+
AVFrame *decoded_frame = ist->decoded_frame;
23362336
AVCodecContext *avctx = ist->dec_ctx;
23372337
int ret, err = 0;
23382338
AVRational decoded_frame_tb;
23392339

2340-
if (!ist->decoded_frame && !(ist->decoded_frame = av_frame_alloc()))
2341-
return AVERROR(ENOMEM);
2342-
decoded_frame = ist->decoded_frame;
2343-
23442340
update_benchmark(NULL);
23452341
ret = decode(avctx, decoded_frame, got_output, pkt);
23462342
update_benchmark("decode_audio %d.%d", ist->file_index, ist->st->index);
@@ -2397,7 +2393,7 @@ static int decode_audio(InputStream *ist, AVPacket *pkt, int *got_output,
23972393
static int decode_video(InputStream *ist, AVPacket *pkt, int *got_output, int64_t *duration_pts, int eof,
23982394
int *decode_failed)
23992395
{
2400-
AVFrame *decoded_frame;
2396+
AVFrame *decoded_frame = ist->decoded_frame;
24012397
int i, ret = 0, err = 0;
24022398
int64_t best_effort_timestamp;
24032399
int64_t dts = AV_NOPTS_VALUE;
@@ -2408,9 +2404,6 @@ static int decode_video(InputStream *ist, AVPacket *pkt, int *got_output, int64_
24082404
if (!eof && pkt && pkt->size == 0)
24092405
return 0;
24102406

2411-
if (!ist->decoded_frame && !(ist->decoded_frame = av_frame_alloc()))
2412-
return AVERROR(ENOMEM);
2413-
decoded_frame = ist->decoded_frame;
24142407
if (ist->dts != AV_NOPTS_VALUE)
24152408
dts = av_rescale_q(ist->dts, AV_TIME_BASE_Q, ist->st->time_base);
24162409
if (pkt) {

fftools/ffmpeg_opt.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -889,6 +889,10 @@ static void add_input_streams(OptionsContext *o, AVFormatContext *ic)
889889
exit_program(1);
890890
}
891891

892+
ist->decoded_frame = av_frame_alloc();
893+
if (!ist->decoded_frame)
894+
exit_program(1);
895+
892896
ist->filter_frame = av_frame_alloc();
893897
if (!ist->filter_frame)
894898
exit_program(1);

0 commit comments

Comments
 (0)