[FFmpeg-devel] [PATCH 14/25] fftools/ffmpeg_mux_init: drop useless new_stream_{data, unknown}

Anton Khirnov anton at khirnov.net
Wed Apr 19 22:52:32 EEST 2023


Their only function is checking that encoding was not specified for
data/unknown-type streams, but the check is broken because enc_ctx will
not be created in ost_add() unless a valid encoder can be found.

Add an actually working check for all types for which encoding is not
supported in choose_encoder().
---
 fftools/ffmpeg_mux_init.c | 38 +++++++++++++++-----------------------
 1 file changed, 15 insertions(+), 23 deletions(-)

diff --git a/fftools/ffmpeg_mux_init.c b/fftools/ffmpeg_mux_init.c
index 59d9a12c1a..28254cb49b 100644
--- a/fftools/ffmpeg_mux_init.c
+++ b/fftools/ffmpeg_mux_init.c
@@ -113,8 +113,21 @@ static int choose_encoder(const OptionsContext *o, AVFormatContext *s,
 
     *enc = NULL;
 
-    if (type == AVMEDIA_TYPE_VIDEO || type == AVMEDIA_TYPE_AUDIO || type == AVMEDIA_TYPE_SUBTITLE) {
-        MATCH_PER_STREAM_OPT(codec_names, str, codec_name, s, ost->st);
+    MATCH_PER_STREAM_OPT(codec_names, str, codec_name, s, ost->st);
+
+    if (type != AVMEDIA_TYPE_VIDEO      &&
+        type != AVMEDIA_TYPE_AUDIO      &&
+        type != AVMEDIA_TYPE_SUBTITLE) {
+        if (codec_name && strcmp(codec_name, "copy")) {
+            const char *type_str = av_get_media_type_string(type);
+            av_log(ost, AV_LOG_FATAL,
+                   "Encoder '%s' specified, but only '-codec copy' supported "
+                   "for %s streams\n", codec_name, type_str);
+            return AVERROR(ENOSYS);
+        }
+        return 0;
+    }
+
         if (!codec_name) {
             ost->par_in->codec_id = av_guess_codec(s->oformat, NULL, s->url,
                                                          NULL, ost->type);
@@ -130,7 +143,6 @@ static int choose_encoder(const OptionsContext *o, AVFormatContext *s,
             *enc = find_codec_or_die(ost, codec_name, ost->type, 1);
             ost->par_in->codec_id = (*enc)->id;
         }
-    }
 
     return 0;
 }
@@ -796,24 +808,6 @@ static void new_stream_audio(Muxer *mux, const OptionsContext *o,
     }
 }
 
-static void new_stream_data(Muxer *mux, const OptionsContext *o,
-                            OutputStream *ost)
-{
-    if (ost->enc_ctx) {
-        av_log(ost, AV_LOG_FATAL, "Data stream encoding not supported yet (only streamcopy)\n");
-        exit_program(1);
-    }
-}
-
-static void new_stream_unknown(Muxer *mux, const OptionsContext *o,
-                               OutputStream *ost)
-{
-    if (ost->enc_ctx) {
-        av_log(ost, AV_LOG_FATAL, "Unknown stream encoding not supported yet (only streamcopy)\n");
-        exit_program(1);
-    }
-}
-
 static void new_stream_attachment(Muxer *mux, const OptionsContext *o,
                                   OutputStream *ost)
 {
@@ -1218,9 +1212,7 @@ static OutputStream *ost_add(Muxer *mux, const OptionsContext *o,
     case AVMEDIA_TYPE_VIDEO:      new_stream_video     (mux, o, ost); break;
     case AVMEDIA_TYPE_AUDIO:      new_stream_audio     (mux, o, ost); break;
     case AVMEDIA_TYPE_SUBTITLE:   new_stream_subtitle  (mux, o, ost); break;
-    case AVMEDIA_TYPE_DATA:       new_stream_data      (mux, o, ost); break;
     case AVMEDIA_TYPE_ATTACHMENT: new_stream_attachment(mux, o, ost); break;
-    default:                      new_stream_unknown   (mux, o, ost); break;
     }
 
     if (type == AVMEDIA_TYPE_VIDEO || type == AVMEDIA_TYPE_AUDIO) {
-- 
2.39.1



More information about the ffmpeg-devel mailing list