fftools/ffmpeg: Avoid allocating+freeing frame, check allocations
Fixes a potential crash upon av_frame_alloc() failure. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
This commit is contained in:
parent
2d0bfbd0fa
commit
b886512ef2
@ -1291,7 +1291,7 @@ static void do_video_out(OutputFile *of,
|
||||
int forced_keyframe = 0;
|
||||
double pts_time;
|
||||
|
||||
if (i < nb0_frames && ost->last_frame) {
|
||||
if (i < nb0_frames && ost->last_frame->buf[0]) {
|
||||
in_picture = ost->last_frame;
|
||||
} else
|
||||
in_picture = next_picture;
|
||||
@ -1419,13 +1419,10 @@ static void do_video_out(OutputFile *of,
|
||||
do_video_stats(ost, frame_size);
|
||||
}
|
||||
|
||||
if (!ost->last_frame)
|
||||
ost->last_frame = av_frame_alloc();
|
||||
av_frame_unref(ost->last_frame);
|
||||
if (next_picture && ost->last_frame)
|
||||
av_frame_ref(ost->last_frame, next_picture);
|
||||
else
|
||||
av_frame_free(&ost->last_frame);
|
||||
if (next_picture)
|
||||
if (av_frame_ref(ost->last_frame, next_picture) < 0)
|
||||
goto error;
|
||||
|
||||
return;
|
||||
error:
|
||||
|
@ -1905,6 +1905,10 @@ static OutputStream *new_video_stream(OptionsContext *o, AVFormatContext *oc, in
|
||||
ost->avfilter = get_ost_filters(o, oc, ost);
|
||||
if (!ost->avfilter)
|
||||
exit_program(1);
|
||||
|
||||
ost->last_frame = av_frame_alloc();
|
||||
if (!ost->last_frame)
|
||||
exit_program(1);
|
||||
} else {
|
||||
MATCH_PER_STREAM_OPT(copy_initial_nonkeyframes, i, ost->copy_initial_nonkeyframes, oc ,st);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user