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
283 283
284 // Codec used for encoding, may be NULL284 // Codec used for encoding, may be NULL
285 const AVCodec *enc;285 const AVCodec *enc;
286 // Overrides encoder pixel formats when set.
287 const enum AVPixelFormat *pix_fmts;
288 286
289 int64_t trim_start_us;287 int64_t trim_start_us;
290 int64_t trim_duration_us;288 int64_t trim_duration_us;
@@ -311,6 +309,11 @@ typedef struct OutputFilterOptions { · 20 unmodified lines
311 309
312 int sample_rate;310 int sample_rate;
313 AVChannelLayout ch_layout;311 AVChannelLayout ch_layout;
312
313 const int *formats;
314 const int *sample_rates;
315 const AVChannelLayout *ch_layouts;
316 const AVRational *frame_rates;
314} OutputFilterOptions;317} OutputFilterOptions;
315 318
316typedef struct InputFilter {319typedef struct InputFilter {
fftools/ffmpeg_filter.c+10−15
@@ -819,11 +819,8 @@ int ofilter_bind_ost(OutputFilter *ofilter, OutputStream *ost, · 818 unmodified lines
819 ofp->height = opts->height;819 ofp->height = opts->height;
820 if (opts->format != AV_PIX_FMT_NONE) {820 if (opts->format != AV_PIX_FMT_NONE) {
821 ofp->format = opts->format;821 ofp->format = opts->format;
822 } else if (opts->pix_fmts)822 } else
823 ofp->formats = opts->pix_fmts;823 ofp->formats = opts->formats;
824 else if (opts->enc &&
825 !(ofp->flags & OFILTER_FLAG_DISABLE_CONVERT))
826 ofp->formats = opts->enc->pix_fmts;
827 824
828 fgp->disable_conversions |= !!(ofp->flags & OFILTER_FLAG_DISABLE_CONVERT);825 fgp->disable_conversions |= !!(ofp->flags & OFILTER_FLAG_DISABLE_CONVERT);
829 826
@@ -835,7 +832,7 @@ int ofilter_bind_ost(OutputFilter *ofilter, OutputStream *ost, · 5 unmodified lines
835 ofp->fps.framerate = ost->frame_rate;832 ofp->fps.framerate = ost->frame_rate;
836 ofp->fps.framerate_max = ost->max_frame_rate;833 ofp->fps.framerate_max = ost->max_frame_rate;
837 ofp->fps.framerate_supported = ost->force_fps || !opts->enc ?834 ofp->fps.framerate_supported = ost->force_fps || !opts->enc ?
838 NULL : opts->enc->supported_framerates;835 NULL : opts->frame_rates;
839 836
840 // reduce frame rate for mpeg4 to be within the spec limits837 // reduce frame rate for mpeg4 to be within the spec limits
841 if (opts->enc && opts->enc->id == AV_CODEC_ID_MPEG4)838 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
847 case AVMEDIA_TYPE_AUDIO:844 case AVMEDIA_TYPE_AUDIO:
848 if (opts->format != AV_SAMPLE_FMT_NONE) {845 if (opts->format != AV_SAMPLE_FMT_NONE) {
849 ofp->format = opts->format;846 ofp->format = opts->format;
850 } else if (opts->enc) {847 } else {
851 ofp->formats = opts->enc->sample_fmts;848 ofp->formats = opts->formats;
852 }849 }
853 if (opts->sample_rate) {850 if (opts->sample_rate) {
854 ofp->sample_rate = opts->sample_rate;851 ofp->sample_rate = opts->sample_rate;
855 } else if (opts->enc) {852 } else
856 ofp->sample_rates = opts->enc->supported_samplerates;853 ofp->sample_rates = opts->sample_rates;
857 }
858 if (opts->ch_layout.nb_channels) {854 if (opts->ch_layout.nb_channels) {
859 int ret = set_channel_layout(ofp, opts->enc ? opts->enc->ch_layouts : NULL,855 int ret = set_channel_layout(ofp, opts->ch_layouts, &opts->ch_layout);
860 &opts->ch_layout);
861 if (ret < 0)856 if (ret < 0)
862 return ret;857 return ret;
863 } else if (opts->enc) {858 } else {
864 ofp->ch_layouts = opts->enc->ch_layouts;859 ofp->ch_layouts = opts->ch_layouts;
865 }860 }
866 break;861 break;
867 }862 }
fftools/ffmpeg_mux_init.c+34−1
@@ -952,6 +952,39 @@ ost_bind_filter(const Muxer *mux, MuxStream *ms, OutputFilter *ofilter, · 951 unmodified lines
952 952
953 snprintf(name, sizeof(name), "#%d:%d", mux->of.index, ost->index);953 snprintf(name, sizeof(name), "#%d:%d", mux->of.index, ost->index);
954 954
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
955 // MJPEG encoder exports a full list of supported pixel formats,988 // MJPEG encoder exports a full list of supported pixel formats,
956 // but the full-range ones are experimental-only.989 // but the full-range ones are experimental-only.
957 // Restrict the auto-conversion list unless -strict experimental990 // 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
964 AV_PIX_FMT_NONE };997 AV_PIX_FMT_NONE };
965 998
966 if (enc_ctx->strict_std_compliance > FF_COMPLIANCE_UNOFFICIAL)999 if (enc_ctx->strict_std_compliance > FF_COMPLIANCE_UNOFFICIAL)
967 opts.pix_fmts = mjpeg_formats;1000 opts.formats = mjpeg_formats;
968 }1001 }
969 1002
970 if (threads_manual) {1003 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