History

fftools/ffmpeg_filter: switch to avcodec_get_supported_config()

Niklas Haas committed 2 years ago

Commit 33d5a4e1 parent f3e265c3 files · +49 −18Browse files

Unified · Split

3 files
  1. fftools/ffmpeg.h +5 −2
  2. fftools/ffmpeg_filter.c +10 −15
  3. fftools/ffmpeg_mux_init.c +34 −1
fftools/ffmpeg.h+5−2
@@ -283,8 +283,6 @@ typedef struct OutputFilterOptions { · 282 unmodified lines
283283
284284 // Codec used for encoding, may be NULL
285285 const AVCodec *enc;
286− // Overrides encoder pixel formats when set.
287− const enum AVPixelFormat *pix_fmts;
288286
289287 int64_t trim_start_us;
290288 int64_t trim_duration_us;
@@ -311,6 +309,11 @@ typedef struct OutputFilterOptions { · 20 unmodified lines
311309
312310 int sample_rate;
313311 AVChannelLayout ch_layout;
312+
313+ const int *formats;
314+ const int *sample_rates;
315+ const AVChannelLayout *ch_layouts;
316+ const AVRational *frame_rates;
314317 } OutputFilterOptions;
315318
316319 typedef struct InputFilter {
fftools/ffmpeg_filter.c+10−15
@@ -819,11 +819,8 @@ int ofilter_bind_ost(OutputFilter *ofilter, OutputStream *ost, · 818 unmodified lines
819819 ofp->height = opts->height;
820820 if (opts->format != AV_PIX_FMT_NONE) {
821821 ofp->format = opts->format;
822− } else if (opts->pix_fmts)
823− ofp->formats = opts->pix_fmts;
824− else if (opts->enc &&
825− !(ofp->flags & OFILTER_FLAG_DISABLE_CONVERT))
826− ofp->formats = opts->enc->pix_fmts;
822+ } else
823+ ofp->formats = opts->formats;
827824
828825 fgp->disable_conversions |= !!(ofp->flags & OFILTER_FLAG_DISABLE_CONVERT);
829826
@@ -835,7 +832,7 @@ int ofilter_bind_ost(OutputFilter *ofilter, OutputStream *ost, · 5 unmodified lines
835832 ofp->fps.framerate = ost->frame_rate;
836833 ofp->fps.framerate_max = ost->max_frame_rate;
837834 ofp->fps.framerate_supported = ost->force_fps || !opts->enc ?
838− NULL : opts->enc->supported_framerates;
835+ NULL : opts->frame_rates;
839836
840837 // reduce frame rate for mpeg4 to be within the spec limits
841838 if (opts->enc && opts->enc->id == AV_CODEC_ID_MPEG4)
@@ -847,21 +844,19 @@ int ofilter_bind_ost(OutputFilter *ofilter, OutputStream *ost, · 5 unmodified lines
847844 case AVMEDIA_TYPE_AUDIO:
848845 if (opts->format != AV_SAMPLE_FMT_NONE) {
849846 ofp->format = opts->format;
850− } else if (opts->enc) {
851− ofp->formats = opts->enc->sample_fmts;
847+ } else {
848+ ofp->formats = opts->formats;
852849 }
853850 if (opts->sample_rate) {
854851 ofp->sample_rate = opts->sample_rate;
855− } else if (opts->enc) {
856− ofp->sample_rates = opts->enc->supported_samplerates;
857− }
852+ } else
853+ ofp->sample_rates = opts->sample_rates;
858854 if (opts->ch_layout.nb_channels) {
859− int ret = set_channel_layout(ofp, opts->enc ? opts->enc->ch_layouts : NULL,
860− &opts->ch_layout);
855+ int ret = set_channel_layout(ofp, opts->ch_layouts, &opts->ch_layout);
861856 if (ret < 0)
862857 return ret;
863− } else if (opts->enc) {
864− ofp->ch_layouts = opts->enc->ch_layouts;
858+ } else {
859+ ofp->ch_layouts = opts->ch_layouts;
865860 }
866861 break;
867862 }
fftools/ffmpeg_mux_init.c+34−1
@@ -952,6 +952,39 @@ ost_bind_filter(const Muxer *mux, MuxStream *ms, OutputFilter *ofilter, · 951 unmodified lines
952952
953953 snprintf(name, sizeof(name), "#%d:%d", mux->of.index, ost->index);
954954
955+ if (ost->type == AVMEDIA_TYPE_VIDEO) {
956+ if (!keep_pix_fmt) {
957+ ret = avcodec_get_supported_config(enc_ctx, NULL,
958+ AV_CODEC_CONFIG_PIX_FORMAT, 0,
959+ (const void **) &opts.formats, NULL);
960+ if (ret < 0)
961+ return ret;
962+ }
963+ if (!ost->force_fps) {
964+ ret = avcodec_get_supported_config(enc_ctx, NULL,
965+ AV_CODEC_CONFIG_FRAME_RATE, 0,
966+ (const void **) &opts.frame_rates, NULL);
967+ if (ret < 0)
968+ return ret;
969+ }
970+ } else {
971+ ret = avcodec_get_supported_config(enc_ctx, NULL,
972+ AV_CODEC_CONFIG_SAMPLE_FORMAT, 0,
973+ (const void **) &opts.formats, NULL);
974+ if (ret < 0)
975+ return ret;
976+ ret = avcodec_get_supported_config(enc_ctx, NULL,
977+ AV_CODEC_CONFIG_SAMPLE_RATE, 0,
978+ (const void **) &opts.sample_rates, NULL);
979+ if (ret < 0)
980+ return ret;
981+ ret = avcodec_get_supported_config(enc_ctx, NULL,
982+ AV_CODEC_CONFIG_CHANNEL_LAYOUT, 0,
983+ (const void **) &opts.ch_layouts, NULL);
984+ if (ret < 0)
985+ return ret;
986+ }
987+
955988 // MJPEG encoder exports a full list of supported pixel formats,
956989 // but the full-range ones are experimental-only.
957990 // Restrict the auto-conversion list unless -strict experimental
@@ -964,7 +997,7 @@ ost_bind_filter(const Muxer *mux, MuxStream *ms, OutputFilter *ofilter, · 6 unmodified lines
964997 AV_PIX_FMT_NONE };
965998
966999 if (enc_ctx->strict_std_compliance > FF_COMPLIANCE_UNOFFICIAL)
967− opts.pix_fmts = mjpeg_formats;
1000+ opts.formats = mjpeg_formats;
9681001 }
9691002
9701003 if (threads_manual) {

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t