History

ffmpeg: Allocate InputStream.decoded_frame early

Based on a commit by Andreas Rheinhardt.

James Almer committed 5 years ago

Commit e7f32791 parent ee3d6a22 files · +6 −9Browse files

Unified · Split

2 files
  1. fftools/ffmpeg.c +2 −9
  2. fftools/ffmpeg_opt.c +4 −0
fftools/ffmpeg.c+2−9
@@ -2332,15 +2332,11 @@ static int send_frame_to_filters(InputStream *ist, AVFrame *decoded_frame) · 2331 unmodified lines
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, · 50 unmodified lines
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_ · 4 unmodified lines
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+4−0
@@ -889,6 +889,10 @@ static void add_input_streams(OptionsContext *o, AVFormatContext *ic) · 888 unmodified lines
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);

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t