[FFmpeg-cvslog] fftools/ffmpeg_filter: pass keep_pix_fmt through OutputFilterOptions

Anton Khirnov git at videolan.org
Tue Apr 9 11:54:16 EEST 2024


ffmpeg | branch: master | Anton Khirnov <anton at khirnov.net> | Mon Apr  1 06:29:16 2024 +0200| [e903c31fd159a48bd6bbc8cb9cdd45fd67727650] | committer: Anton Khirnov

fftools/ffmpeg_filter: pass keep_pix_fmt through OutputFilterOptions

Reduces the need to access OutputStream, which will allow decoupling
filtering from encoding in future commits.

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=e903c31fd159a48bd6bbc8cb9cdd45fd67727650
---

 fftools/ffmpeg.h          | 9 +++++++--
 fftools/ffmpeg_filter.c   | 8 +++++---
 fftools/ffmpeg_mux_init.c | 9 +++++----
 3 files changed, 17 insertions(+), 9 deletions(-)

diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h
index 7288a48aa1..300ad8a987 100644
--- a/fftools/ffmpeg.h
+++ b/fftools/ffmpeg.h
@@ -263,11 +263,18 @@ typedef struct InputFilterOptions {
     AVFrame            *fallback;
 } InputFilterOptions;
 
+enum OFilterFlags {
+    OFILTER_FLAG_DISABLE_CONVERT    = (1 << 0),
+};
+
 typedef struct OutputFilterOptions {
     // Codec used for encoding, may be NULL
     const AVCodec      *enc;
 
     int64_t             ts_offset;
+
+    // A combination of OFilterFlags.
+    unsigned            flags;
 } OutputFilterOptions;
 
 typedef struct InputFilter {
@@ -556,8 +563,6 @@ typedef struct OutputStream {
 
     char *attachment_filename;
 
-    int keep_pix_fmt;
-
     /* stats */
     // number of packets send to the muxer
     atomic_uint_least64_t packets_written;
diff --git a/fftools/ffmpeg_filter.c b/fftools/ffmpeg_filter.c
index 8b05262622..5f2dbc387e 100644
--- a/fftools/ffmpeg_filter.c
+++ b/fftools/ffmpeg_filter.c
@@ -214,6 +214,8 @@ typedef struct OutputFilterPriv {
     int64_t                 ts_offset;
     int64_t                 next_pts;
     FPSConvContext          fps;
+
+    unsigned                flags;
 } OutputFilterPriv;
 
 static OutputFilterPriv *ofp_from_ofilter(OutputFilter *ofilter)
@@ -355,11 +357,10 @@ static int choose_pix_fmts(OutputFilter *ofilter, AVBPrint *bprint,
                            const char **dst)
 {
     OutputFilterPriv *ofp = ofp_from_ofilter(ofilter);
-    OutputStream *ost = ofilter->ost;
 
     *dst = NULL;
 
-    if (ost->keep_pix_fmt || ofp->format != AV_PIX_FMT_NONE) {
+    if (ofp->flags & OFILTER_FLAG_DISABLE_CONVERT || ofp->format != AV_PIX_FMT_NONE) {
         *dst = ofp->format == AV_PIX_FMT_NONE ? NULL :
                av_get_pix_fmt_name(ofp->format);
     } else if (ofp->formats) {
@@ -777,6 +778,7 @@ int ofilter_bind_ost(OutputFilter *ofilter, OutputStream *ost,
     ofilter->ost = ost;
     av_freep(&ofilter->linklabel);
 
+    ofp->flags        = opts->flags;
     ofp->ts_offset    = opts->ts_offset;
     ofp->enc_timebase = ost->enc_timebase;
 
@@ -814,7 +816,7 @@ int ofilter_bind_ost(OutputFilter *ofilter, OutputStream *ost,
             }
         }
 
-        fgp->disable_conversions |= ost->keep_pix_fmt;
+        fgp->disable_conversions |= !!(ofp->flags & OFILTER_FLAG_DISABLE_CONVERT);
 
         ofp->fps.last_frame = av_frame_alloc();
         if (!ofp->fps.last_frame)
diff --git a/fftools/ffmpeg_mux_init.c b/fftools/ffmpeg_mux_init.c
index 83eab4276e..d79ae1f491 100644
--- a/fftools/ffmpeg_mux_init.c
+++ b/fftools/ffmpeg_mux_init.c
@@ -580,7 +580,7 @@ static enum AVPixelFormat pix_fmt_parse(OutputStream *ost, const char *name)
 }
 
 static int new_stream_video(Muxer *mux, const OptionsContext *o,
-                            OutputStream *ost)
+                            OutputStream *ost, int *keep_pix_fmt)
 {
     AVFormatContext *oc = mux->fc;
     AVStream *st;
@@ -638,7 +638,7 @@ static int new_stream_video(Muxer *mux, const OptionsContext *o,
 
         MATCH_PER_STREAM_OPT(frame_pix_fmts, str, frame_pix_fmt, oc, st);
         if (frame_pix_fmt && *frame_pix_fmt == '+') {
-            ost->keep_pix_fmt = 1;
+            *keep_pix_fmt = 1;
             if (!*++frame_pix_fmt)
                 frame_pix_fmt = NULL;
         }
@@ -1041,7 +1041,7 @@ static int ost_add(Muxer *mux, const OptionsContext *o, enum AVMediaType type,
     OutputStream *ost;
     const AVCodec *enc;
     AVStream *st;
-    int ret = 0;
+    int ret = 0, keep_pix_fmt = 0;
     const char *bsfs = NULL, *time_base = NULL;
     char *filters = NULL, *next, *codec_tag = NULL;
     double qscale = -1;
@@ -1356,7 +1356,7 @@ static int ost_add(Muxer *mux, const OptionsContext *o, enum AVMediaType type,
                          ms->copy_initial_nonkeyframes, oc, st);
 
     switch (type) {
-    case AVMEDIA_TYPE_VIDEO:      ret = new_stream_video     (mux, o, ost); break;
+    case AVMEDIA_TYPE_VIDEO:      ret = new_stream_video     (mux, o, ost, &keep_pix_fmt); break;
     case AVMEDIA_TYPE_AUDIO:      ret = new_stream_audio     (mux, o, ost); break;
     case AVMEDIA_TYPE_SUBTITLE:   ret = new_stream_subtitle  (mux, o, ost); break;
     }
@@ -1375,6 +1375,7 @@ static int ost_add(Muxer *mux, const OptionsContext *o, enum AVMediaType type,
             .enc = enc,
             .ts_offset = mux->of.start_time == AV_NOPTS_VALUE ?
                          0 : mux->of.start_time,
+            .flags = OFILTER_FLAG_DISABLE_CONVERT * !!keep_pix_fmt,
         };
 
         if (ofilter) {



More information about the ffmpeg-cvslog mailing list