diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h index 3c5d933e17..ca24b20640 100644 --- a/fftools/ffmpeg.h +++ b/fftools/ffmpeg.h @@ -283,8 +283,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; @@ -311,6 +309,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 4411985548..9effa96aac 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); @@ -835,7 +832,7 @@ int ofilter_bind_ost(OutputFilter *ofilter, OutputStream *ost, 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; + NULL : 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 +844,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 79bdca013f..a2cb0ba294 100644 --- a/fftools/ffmpeg_mux_init.c +++ b/fftools/ffmpeg_mux_init.c @@ -952,6 +952,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, NULL); + 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, NULL); + if (ret < 0) + return ret; + } + } else { + ret = avcodec_get_supported_config(enc_ctx, NULL, + AV_CODEC_CONFIG_SAMPLE_FORMAT, 0, + (const void **) &opts.formats, NULL); + if (ret < 0) + return ret; + ret = avcodec_get_supported_config(enc_ctx, NULL, + AV_CODEC_CONFIG_SAMPLE_RATE, 0, + (const void **) &opts.sample_rates, NULL); + if (ret < 0) + return ret; + ret = avcodec_get_supported_config(enc_ctx, NULL, + AV_CODEC_CONFIG_CHANNEL_LAYOUT, 0, + (const void **) &opts.ch_layouts, NULL); + 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 @@ -964,7 +997,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) {