diff options
author | Niklas Haas <git@haasn.dev> | 2024-04-05 20:47:48 +0200 |
---|---|---|
committer | Anton Khirnov <anton@khirnov.net> | 2024-04-09 15:28:17 +0200 |
commit | 67ae6dee915f4a851d8ff6dfe86d7de142575a4f (patch) | |
tree | f4982b5fd8a8aae4ea322afac3155311e7e35704 | |
parent | 25450457d7facf081f56fc4a9d9dba1012029ca0 (diff) |
fftools/ffmpeg_filter: switch to avcodec_get_supported_config()
Signed-off-by: Anton Khirnov <anton@khirnov.net>
-rw-r--r-- | fftools/ffmpeg.h | 7 | ||||
-rw-r--r-- | fftools/ffmpeg_filter.c | 26 | ||||
-rw-r--r-- | fftools/ffmpeg_mux_init.c | 35 |
3 files changed, 49 insertions, 19 deletions
diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h index 51aee0679a..abd48547e0 100644 --- a/fftools/ffmpeg.h +++ b/fftools/ffmpeg.h @@ -276,8 +276,6 @@ 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 trim_start_us; int64_t trim_duration_us; @@ -304,6 +302,11 @@ typedef struct OutputFilterOptions { int sample_rate; AVChannelLayout ch_layout; + + const int *formats; + const int *sample_rates; + const AVChannelLayout *ch_layouts; + const AVRational *frame_rates; } OutputFilterOptions; typedef struct InputFilter { diff --git a/fftools/ffmpeg_filter.c b/fftools/ffmpeg_filter.c index 9366b71e69..f9bd894bec 100644 --- a/fftools/ffmpeg_filter.c +++ b/fftools/ffmpeg_filter.c @@ -819,11 +819,8 @@ int ofilter_bind_ost(OutputFilter *ofilter, OutputStream *ost, ofp->height = opts->height; if (opts->format != AV_PIX_FMT_NONE) { ofp->format = opts->format; - } else if (opts->pix_fmts) - ofp->formats = opts->pix_fmts; - else if (opts->enc && - !(ofp->flags & OFILTER_FLAG_DISABLE_CONVERT)) - ofp->formats = opts->enc->pix_fmts; + } else + ofp->formats = opts->formats; fgp->disable_conversions |= !!(ofp->flags & OFILTER_FLAG_DISABLE_CONVERT); @@ -834,8 +831,7 @@ int ofilter_bind_ost(OutputFilter *ofilter, OutputStream *ost, ofp->fps.vsync_method = opts->vsync_method; ofp->fps.framerate = ost->frame_rate; ofp->fps.framerate_max = ost->max_frame_rate; - ofp->fps.framerate_supported = ost->force_fps && opts->enc ? - NULL : opts->enc->supported_framerates; + ofp->fps.framerate_supported = opts->frame_rates; // reduce frame rate for mpeg4 to be within the spec limits if (opts->enc && opts->enc->id == AV_CODEC_ID_MPEG4) @@ -847,21 +843,19 @@ int ofilter_bind_ost(OutputFilter *ofilter, OutputStream *ost, case AVMEDIA_TYPE_AUDIO: if (opts->format != AV_SAMPLE_FMT_NONE) { ofp->format = opts->format; - } else if (opts->enc) { - ofp->formats = opts->enc->sample_fmts; + } else { + ofp->formats = opts->formats; } if (opts->sample_rate) { ofp->sample_rate = opts->sample_rate; - } else if (opts->enc) { - ofp->sample_rates = opts->enc->supported_samplerates; - } + } else + ofp->sample_rates = opts->sample_rates; if (opts->ch_layout.nb_channels) { - int ret = set_channel_layout(ofp, opts->enc ? opts->enc->ch_layouts : NULL, - &opts->ch_layout); + int ret = set_channel_layout(ofp, opts->ch_layouts, &opts->ch_layout); if (ret < 0) return ret; - } else if (opts->enc) { - ofp->ch_layouts = opts->enc->ch_layouts; + } else { + ofp->ch_layouts = opts->ch_layouts; } break; } diff --git a/fftools/ffmpeg_mux_init.c b/fftools/ffmpeg_mux_init.c index d4a58469f8..0d3d80dfb9 100644 --- a/fftools/ffmpeg_mux_init.c +++ b/fftools/ffmpeg_mux_init.c @@ -953,6 +953,39 @@ ost_bind_filter(const Muxer *mux, MuxStream *ms, OutputFilter *ofilter, snprintf(name, sizeof(name), "#%d:%d", mux->of.index, ost->index); + if (ost->type == AVMEDIA_TYPE_VIDEO) { + if (!keep_pix_fmt) { + ret = avcodec_get_supported_config(enc_ctx, NULL, + AV_CODEC_CONFIG_PIX_FORMAT, 0, + (const void **) &opts.formats); + if (ret < 0) + return ret; + } + if (!ost->force_fps) { + ret = avcodec_get_supported_config(enc_ctx, NULL, + AV_CODEC_CONFIG_FRAME_RATE, 0, + (const void **) &opts.frame_rates); + if (ret < 0) + return ret; + } + } else { + ret = avcodec_get_supported_config(enc_ctx, NULL, + AV_CODEC_CONFIG_SAMPLE_FORMAT, 0, + (const void **) &opts.formats); + if (ret < 0) + return ret; + ret = avcodec_get_supported_config(enc_ctx, NULL, + AV_CODEC_CONFIG_SAMPLE_RATE, 0, + (const void **) &opts.sample_rates); + if (ret < 0) + return ret; + ret = avcodec_get_supported_config(enc_ctx, NULL, + AV_CODEC_CONFIG_CHANNEL_LAYOUT, 0, + (const void **) &opts.ch_layouts); + if (ret < 0) + return ret; + } + // 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 @@ -965,7 +998,7 @@ ost_bind_filter(const Muxer *mux, MuxStream *ms, OutputFilter *ofilter, AV_PIX_FMT_NONE }; if (enc_ctx->strict_std_compliance > FF_COMPLIANCE_UNOFFICIAL) - opts.pix_fmts = mjpeg_formats; + opts.formats = mjpeg_formats; } if (threads_manual) { |