aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAnton Khirnov <anton@khirnov.net>2024-04-01 07:50:31 +0200
committerAnton Khirnov <anton@khirnov.net>2024-04-09 10:34:18 +0200
commit17702c5f7bfdd02bda3a29971d6d564c01971988 (patch)
tree6778f94c3195de322e2702705a49c5ff3c2a2636
parent9d5bf2d69e6ad85adbf8a673929192e0b07bc080 (diff)
downloadffmpeg-17702c5f7bfdd02bda3a29971d6d564c01971988.tar.gz
fftools/ffmpeg_filter: move the MJPEG format selection hack to muxer setup
That, if anywhere, is a more appropriate place for it.
-rw-r--r--fftools/ffmpeg.h2
-rw-r--r--fftools/ffmpeg_filter.c29
-rw-r--r--fftools/ffmpeg_mux_init.c24
3 files changed, 29 insertions, 26 deletions
diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h
index 56c2fedcc4..d0e896dbe7 100644
--- a/fftools/ffmpeg.h
+++ b/fftools/ffmpeg.h
@@ -270,6 +270,8 @@ enum OFilterFlags {
typedef struct OutputFilterOptions {
// Codec used for encoding, may be NULL
const AVCodec *enc;
+ // Overrides encoder pixel formats when set.
+ const enum AVPixelFormat *pix_fmts;
int64_t ts_offset;
diff --git a/fftools/ffmpeg_filter.c b/fftools/ffmpeg_filter.c
index 0b78898af0..5661dc960a 100644
--- a/fftools/ffmpeg_filter.c
+++ b/fftools/ffmpeg_filter.c
@@ -788,34 +788,11 @@ int ofilter_bind_ost(OutputFilter *ofilter, OutputStream *ost,
ofp->height = ost->enc_ctx->height;
if (ost->enc_ctx->pix_fmt != AV_PIX_FMT_NONE) {
ofp->format = ost->enc_ctx->pix_fmt;
- } else if (opts->enc) {
+ } else if (opts->pix_fmts)
+ ofp->formats = opts->pix_fmts;
+ else if (opts->enc)
ofp->formats = opts->enc->pix_fmts;
- // MJPEG encoder exports a full list of supported pixel formats,
- // but the full-range ones are experimental-only.
- // Restrict the auto-conversion list unless -strict experimental
- // has been specified.
- if (!strcmp(opts->enc->name, "mjpeg")) {
- // FIXME: YUV420P etc. are actually supported with full color range,
- // yet the latter information isn't available here.
- static const enum AVPixelFormat mjpeg_formats[] =
- { AV_PIX_FMT_YUVJ420P, AV_PIX_FMT_YUVJ422P, AV_PIX_FMT_YUVJ444P,
- AV_PIX_FMT_NONE };
-
- const AVDictionaryEntry *strict = av_dict_get(ost->encoder_opts, "strict", NULL, 0);
- int strict_val = ost->enc_ctx->strict_std_compliance;
-
- if (strict) {
- const AVOption *o = av_opt_find(ost->enc_ctx, strict->key, NULL, 0, 0);
- av_assert0(o);
- av_opt_eval_int(ost->enc_ctx, o, strict->value, &strict_val);
- }
-
- if (strict_val > FF_COMPLIANCE_UNOFFICIAL)
- ofp->formats = mjpeg_formats;
- }
- }
-
fgp->disable_conversions |= !!(ofp->flags & OFILTER_FLAG_DISABLE_CONVERT);
ofp->fps.last_frame = av_frame_alloc();
diff --git a/fftools/ffmpeg_mux_init.c b/fftools/ffmpeg_mux_init.c
index 28090423c6..04642f5c8b 100644
--- a/fftools/ffmpeg_mux_init.c
+++ b/fftools/ffmpeg_mux_init.c
@@ -1384,6 +1384,30 @@ static int ost_add(Muxer *mux, const OptionsContext *o, enum AVMediaType type,
.flags = OFILTER_FLAG_DISABLE_CONVERT * !!keep_pix_fmt,
};
+ // MJPEG encoder exports a full list of supported pixel formats,
+ // but the full-range ones are experimental-only.
+ // Restrict the auto-conversion list unless -strict experimental
+ // has been specified.
+ if (!strcmp(enc->name, "mjpeg")) {
+ // FIXME: YUV420P etc. are actually supported with full color range,
+ // yet the latter information isn't available here.
+ static const enum AVPixelFormat mjpeg_formats[] =
+ { AV_PIX_FMT_YUVJ420P, AV_PIX_FMT_YUVJ422P, AV_PIX_FMT_YUVJ444P,
+ AV_PIX_FMT_NONE };
+
+ const AVDictionaryEntry *strict = av_dict_get(ost->encoder_opts, "strict", NULL, 0);
+ int strict_val = ost->enc_ctx->strict_std_compliance;
+
+ if (strict) {
+ const AVOption *o = av_opt_find(ost->enc_ctx, strict->key, NULL, 0, 0);
+ av_assert0(o);
+ av_opt_eval_int(ost->enc_ctx, o, strict->value, &strict_val);
+ }
+
+ if (strict_val > FF_COMPLIANCE_UNOFFICIAL)
+ opts.pix_fmts = mjpeg_formats;
+ }
+
if (ofilter) {
ost->filter = ofilter;
ret = ofilter_bind_ost(ofilter, ost, ms->sch_idx_enc, &opts);