[FFmpeg-devel] [PATCH 06/25] fftools/ffmpeg: move a check to a more appropriate place

Anton Khirnov anton at khirnov.net
Thu Apr 13 17:12:04 EEST 2023


reap_filters() no longer needs to access the encoding context.
---
 fftools/ffmpeg.c     | 21 +--------------------
 fftools/ffmpeg_enc.c |  7 +++++++
 2 files changed, 8 insertions(+), 20 deletions(-)

diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c
index 700fa5fbe1..4d4cbf6aaf 100644
--- a/fftools/ffmpeg.c
+++ b/fftools/ffmpeg.c
@@ -669,7 +669,6 @@ static int reap_filters(int flush)
     /* Reap all buffers present in the buffer sinks */
     for (OutputStream *ost = ost_iter(NULL); ost; ost = ost_iter(ost)) {
         AVFilterContext *filter;
-        AVCodecContext *enc = ost->enc_ctx;
         int ret = 0;
 
         if (!ost->filter || !ost->filter->graph->graph)
@@ -709,25 +708,7 @@ static int reap_filters(int flush)
                            tb.num, tb.den);
             }
 
-            switch (av_buffersink_get_type(filter)) {
-            case AVMEDIA_TYPE_VIDEO:
-                enc_frame(ost, filtered_frame);
-                break;
-            case AVMEDIA_TYPE_AUDIO:
-                if (!(enc->codec->capabilities & AV_CODEC_CAP_PARAM_CHANGE) &&
-                    avcodec_is_open(enc) &&
-                    enc->ch_layout.nb_channels != filtered_frame->ch_layout.nb_channels) {
-                    av_log(NULL, AV_LOG_ERROR,
-                           "Audio filter graph output is not normalized and encoder does not support parameter changes\n");
-                    break;
-                }
-                enc_frame(ost, filtered_frame);
-                break;
-            default:
-                // TODO support subtitle filters
-                av_assert0(0);
-            }
-
+            enc_frame(ost, filtered_frame);
             av_frame_unref(filtered_frame);
         }
     }
diff --git a/fftools/ffmpeg_enc.c b/fftools/ffmpeg_enc.c
index 0236e50e38..063053623f 100644
--- a/fftools/ffmpeg_enc.c
+++ b/fftools/ffmpeg_enc.c
@@ -789,6 +789,13 @@ static void do_audio_out(OutputFile *of, OutputStream *ost,
     AVCodecContext *enc = ost->enc_ctx;
     int ret;
 
+    if (!(enc->codec->capabilities & AV_CODEC_CAP_PARAM_CHANGE) &&
+        enc->ch_layout.nb_channels != frame->ch_layout.nb_channels) {
+        av_log(ost, AV_LOG_ERROR,
+               "Audio channel count changed and encoder does not support parameter changes\n");
+        return;
+    }
+
     if (frame->pts == AV_NOPTS_VALUE)
         frame->pts = e->next_pts;
     else {
-- 
2.39.1



More information about the ffmpeg-devel mailing list