[FFmpeg-devel] [PATCH 08/47] fftools/ffmpeg_enc: return errors from enc_frame() instead of aborting
Anton Khirnov
anton at khirnov.net
Sat Jul 15 13:45:32 EEST 2023
---
fftools/ffmpeg.h | 2 +-
fftools/ffmpeg_enc.c | 6 ++++--
fftools/ffmpeg_filter.c | 12 +++++++++---
3 files changed, 14 insertions(+), 6 deletions(-)
diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h
index 0189bee0f3..38f2b1ef66 100644
--- a/fftools/ffmpeg.h
+++ b/fftools/ffmpeg.h
@@ -815,7 +815,7 @@ void enc_free(Encoder **penc);
int enc_open(OutputStream *ost, AVFrame *frame);
int enc_subtitle(OutputFile *of, OutputStream *ost, const AVSubtitle *sub);
-void enc_frame(OutputStream *ost, AVFrame *frame);
+int enc_frame(OutputStream *ost, AVFrame *frame);
void enc_flush(void);
/*
diff --git a/fftools/ffmpeg_enc.c b/fftools/ffmpeg_enc.c
index 1489b2f179..6130e3e221 100644
--- a/fftools/ffmpeg_enc.c
+++ b/fftools/ffmpeg_enc.c
@@ -1133,17 +1133,19 @@ static void do_video_out(OutputFile *of, OutputStream *ost, AVFrame *frame)
av_frame_move_ref(e->last_frame, frame);
}
-void enc_frame(OutputStream *ost, AVFrame *frame)
+int enc_frame(OutputStream *ost, AVFrame *frame)
{
OutputFile *of = output_files[ost->file_index];
int ret;
ret = enc_open(ost, frame);
if (ret < 0)
- exit_program(1);
+ return ret;
if (ost->enc_ctx->codec_type == AVMEDIA_TYPE_VIDEO) do_video_out(of, ost, frame);
else do_audio_out(of, ost, frame);
+
+ return 0;
}
void enc_flush(void)
diff --git a/fftools/ffmpeg_filter.c b/fftools/ffmpeg_filter.c
index 49e0800e6e..d373d8c002 100644
--- a/fftools/ffmpeg_filter.c
+++ b/fftools/ffmpeg_filter.c
@@ -1722,8 +1722,11 @@ int reap_filters(FilterGraph *fg, int flush)
av_log(fgp, AV_LOG_WARNING,
"Error in av_buffersink_get_frame_flags(): %s\n", av_err2str(ret));
} else if (flush && ret == AVERROR_EOF && ofp->got_frame &&
- av_buffersink_get_type(filter) == AVMEDIA_TYPE_VIDEO)
- enc_frame(ost, NULL);
+ av_buffersink_get_type(filter) == AVMEDIA_TYPE_VIDEO) {
+ ret = enc_frame(ost, NULL);
+ if (ret < 0)
+ return ret;
+ }
break;
}
@@ -1759,8 +1762,11 @@ int reap_filters(FilterGraph *fg, int flush)
if (ost->type == AVMEDIA_TYPE_VIDEO)
fd->frame_rate_filter = av_buffersink_get_frame_rate(filter);
- enc_frame(ost, filtered_frame);
+ ret = enc_frame(ost, filtered_frame);
av_frame_unref(filtered_frame);
+ if (ret < 0)
+ return ret;
+
ofp->got_frame = 1;
}
}
--
2.40.1
More information about the ffmpeg-devel
mailing list