History

fftools/ffmpeg_filter: propagate codec yuv metadata to filters

To convert between color spaces/ranges, if needed by the codec properties.

Niklas Haas committed 2 years ago

Commit a850f801 parent 33d5a4e3 files · +42 −0Browse files

Unified · Split

3 files
  1. fftools/ffmpeg.h +4 −0
  2. fftools/ffmpeg_filter.c +26 −0
  3. fftools/ffmpeg_mux_init.c +12 −0
fftools/ffmpeg.h+4−0
@@ -304,6 +304,8 @@ typedef struct OutputFilterOptions { · 303 unmodified lines
304 int format;304 int format;
305 int width;305 int width;
306 int height;306 int height;
307 enum AVColorSpace color_space;
308 enum AVColorRange color_range;
307 309
308 enum VideoSyncMethod vsync_method;310 enum VideoSyncMethod vsync_method;
309 311
@@ -314,6 +316,8 @@ typedef struct OutputFilterOptions { · 4 unmodified lines
314 const int *sample_rates;316 const int *sample_rates;
315 const AVChannelLayout *ch_layouts;317 const AVChannelLayout *ch_layouts;
316 const AVRational *frame_rates;318 const AVRational *frame_rates;
319 const enum AVColorSpace *color_spaces;
320 const enum AVColorRange *color_ranges;
317} OutputFilterOptions;321} OutputFilterOptions;
318 322
319typedef struct InputFilter {323typedef struct InputFilter {
fftools/ffmpeg_filter.c+26−0
@@ -202,6 +202,8 @@ typedef struct OutputFilterPriv { · 201 unmodified lines
202 int width, height;202 int width, height;
203 int sample_rate;203 int sample_rate;
204 AVChannelLayout ch_layout;204 AVChannelLayout ch_layout;
205 enum AVColorSpace color_space;
206 enum AVColorRange color_range;
205 207
206 // time base in which the output is sent to our downstream208 // time base in which the output is sent to our downstream
207 // does not need to match the filtersink's timebase209 // does not need to match the filtersink's timebase
@@ -220,6 +222,8 @@ typedef struct OutputFilterPriv { · 12 unmodified lines
220 const int *formats;222 const int *formats;
221 const AVChannelLayout *ch_layouts;223 const AVChannelLayout *ch_layouts;
222 const int *sample_rates;224 const int *sample_rates;
225 const enum AVColorSpace *color_spaces;
226 const enum AVColorRange *color_ranges;
223 227
224 AVRational enc_timebase;228 AVRational enc_timebase;
225 int64_t trim_start_us;229 int64_t trim_start_us;
@@ -395,6 +399,12 @@ DEF_CHOOSE_FORMAT(sample_fmts, enum AVSampleFormat, format, formats, · 169 unmodified lines
395DEF_CHOOSE_FORMAT(sample_rates, int, sample_rate, sample_rates, 0,399DEF_CHOOSE_FORMAT(sample_rates, int, sample_rate, sample_rates, 0,
396 "%d", )400 "%d", )
397 401
402DEF_CHOOSE_FORMAT(color_spaces, enum AVColorSpace, color_space, color_spaces,
403 AVCOL_SPC_UNSPECIFIED, "%s", av_color_space_name);
404
405DEF_CHOOSE_FORMAT(color_ranges, enum AVColorRange, color_range, color_ranges,
406 AVCOL_RANGE_UNSPECIFIED, "%s", av_color_range_name);
407
398static void choose_channel_layouts(OutputFilterPriv *ofp, AVBPrint *bprint)408static void choose_channel_layouts(OutputFilterPriv *ofp, AVBPrint *bprint)
399{409{
400 if (av_channel_layout_check(&ofp->ch_layout)) {410 if (av_channel_layout_check(&ofp->ch_layout)) {
@@ -639,6 +649,8 @@ static OutputFilter *ofilter_alloc(FilterGraph *fg, enum AVMediaType type) · 238 unmodified lines
639 ofilter->graph = fg;649 ofilter->graph = fg;
640 ofilter->type = type;650 ofilter->type = type;
641 ofp->format = -1;651 ofp->format = -1;
652 ofp->color_space = AVCOL_SPC_UNSPECIFIED;
653 ofp->color_range = AVCOL_RANGE_UNSPECIFIED;
642 ofp->index = fg->nb_outputs - 1;654 ofp->index = fg->nb_outputs - 1;
643 655
644 snprintf(ofp->log_name, sizeof(ofp->log_name), "%co%d",656 snprintf(ofp->log_name, sizeof(ofp->log_name), "%co%d",
@@ -822,6 +834,16 @@ int ofilter_bind_ost(OutputFilter *ofilter, OutputStream *ost, · 177 unmodified lines
822 } else834 } else
823 ofp->formats = opts->formats;835 ofp->formats = opts->formats;
824 836
837 if (opts->color_space != AVCOL_SPC_UNSPECIFIED)
838 ofp->color_space = opts->color_space;
839 else
840 ofp->color_spaces = opts->color_spaces;
841
842 if (opts->color_range != AVCOL_RANGE_UNSPECIFIED)
843 ofp->color_range = opts->color_range;
844 else
845 ofp->color_ranges = opts->color_ranges;
846
825 fgp->disable_conversions |= !!(ofp->flags & OFILTER_FLAG_DISABLE_CONVERT);847 fgp->disable_conversions |= !!(ofp->flags & OFILTER_FLAG_DISABLE_CONVERT);
826 848
827 ofp->fps.last_frame = av_frame_alloc();849 ofp->fps.last_frame = av_frame_alloc();
@@ -1485,6 +1507,8 @@ static int configure_output_video_filter(FilterGraph *fg, AVFilterGraph *graph, · 657 unmodified lines
1485 ofp->format != AV_PIX_FMT_NONE || !ofp->formats);1507 ofp->format != AV_PIX_FMT_NONE || !ofp->formats);
1486 av_bprint_init(&bprint, 0, AV_BPRINT_SIZE_UNLIMITED);1508 av_bprint_init(&bprint, 0, AV_BPRINT_SIZE_UNLIMITED);
1487 choose_pix_fmts(ofp, &bprint);1509 choose_pix_fmts(ofp, &bprint);
1510 choose_color_spaces(ofp, &bprint);
1511 choose_color_ranges(ofp, &bprint);
1488 if (!av_bprint_is_complete(&bprint))1512 if (!av_bprint_is_complete(&bprint))
1489 return AVERROR(ENOMEM);1513 return AVERROR(ENOMEM);
1490 1514
@@ -1907,6 +1931,8 @@ static int configure_filtergraph(FilterGraph *fg, FilterGraphThread *fgt) · 416 unmodified lines
1907 1931
1908 ofp->width = av_buffersink_get_w(sink);1932 ofp->width = av_buffersink_get_w(sink);
1909 ofp->height = av_buffersink_get_h(sink);1933 ofp->height = av_buffersink_get_h(sink);
1934 ofp->color_space = av_buffersink_get_colorspace(sink);
1935 ofp->color_range = av_buffersink_get_color_range(sink);
1910 1936
1911 // If the timing parameters are not locked yet, get the tentative values1937 // If the timing parameters are not locked yet, get the tentative values
1912 // here but don't lock them. They will only be used if no output frames1938 // here but don't lock them. They will only be used if no output frames
fftools/ffmpeg_mux_init.c+12−0
@@ -934,6 +934,8 @@ ost_bind_filter(const Muxer *mux, MuxStream *ms, OutputFilter *ofilter, · 933 unmodified lines
934 enc_ctx->pix_fmt : enc_ctx->sample_fmt,934 enc_ctx->pix_fmt : enc_ctx->sample_fmt,
935 .width = enc_ctx->width,935 .width = enc_ctx->width,
936 .height = enc_ctx->height,936 .height = enc_ctx->height,
937 .color_space = enc_ctx->colorspace,
938 .color_range = enc_ctx->color_range,
937 .vsync_method = vsync_method,939 .vsync_method = vsync_method,
938 .sample_rate = enc_ctx->sample_rate,940 .sample_rate = enc_ctx->sample_rate,
939 .ch_layout = enc_ctx->ch_layout,941 .ch_layout = enc_ctx->ch_layout,
@@ -967,6 +969,16 @@ ost_bind_filter(const Muxer *mux, MuxStream *ms, OutputFilter *ofilter, · 27 unmodified lines
967 if (ret < 0)969 if (ret < 0)
968 return ret;970 return ret;
969 }971 }
972 ret = avcodec_get_supported_config(enc_ctx, NULL,
973 AV_CODEC_CONFIG_COLOR_SPACE, 0,
974 (const void **) &opts.color_spaces, NULL);
975 if (ret < 0)
976 return ret;
977 ret = avcodec_get_supported_config(enc_ctx, NULL,
978 AV_CODEC_CONFIG_COLOR_RANGE, 0,
979 (const void **) &opts.color_ranges, NULL);
980 if (ret < 0)
981 return ret;
970 } else {982 } else {
971 ret = avcodec_get_supported_config(enc_ctx, NULL,983 ret = avcodec_get_supported_config(enc_ctx, NULL,
972 AV_CODEC_CONFIG_SAMPLE_FORMAT, 0,984 AV_CODEC_CONFIG_SAMPLE_FORMAT, 0,

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