[FFmpeg-devel] [PATCH 23/23] fftools/ffmpeg_enc: factorize calling enc_init()

Anton Khirnov anton at khirnov.net
Sat Mar 25 21:15:29 EET 2023


It is done in the same way for both audio and video, so can be moved to
enc_frame().
---
 fftools/ffmpeg_enc.c | 13 +++++--------
 1 file changed, 5 insertions(+), 8 deletions(-)

diff --git a/fftools/ffmpeg_enc.c b/fftools/ffmpeg_enc.c
index 1387e05cf6..2f1803a74c 100644
--- a/fftools/ffmpeg_enc.c
+++ b/fftools/ffmpeg_enc.c
@@ -762,10 +762,6 @@ static void do_audio_out(OutputFile *of, OutputStream *ost,
     AVCodecContext *enc = ost->enc_ctx;
     int ret;
 
-    ret = enc_open(ost, frame);
-    if (ret < 0)
-        exit_program(1);
-
     if (frame->pts == AV_NOPTS_VALUE)
         frame->pts = ost->next_pts;
     else {
@@ -967,10 +963,6 @@ static void do_video_out(OutputFile *of,
     InputStream *ist = ost->ist;
     AVFilterContext *filter = ost->filter->filter;
 
-    ret = enc_open(ost, next_picture);
-    if (ret < 0)
-        exit_program(1);
-
     frame_rate = av_buffersink_get_frame_rate(filter);
     if (frame_rate.num > 0 && frame_rate.den > 0)
         duration = 1/(av_q2d(frame_rate) * av_q2d(enc->time_base));
@@ -1062,6 +1054,11 @@ static void do_video_out(OutputFile *of,
 void 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);
 
     if (ost->enc_ctx->codec_type == AVMEDIA_TYPE_VIDEO) do_video_out(of, ost, frame);
     else                                                do_audio_out(of, ost, frame);
-- 
2.39.1



More information about the ffmpeg-devel mailing list