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
304304 int format;
305305 int width;
306306 int height;
307+ enum AVColorSpace color_space;
308+ enum AVColorRange color_range;
307309
308310 enum VideoSyncMethod vsync_method;
309311
@@ -314,6 +316,8 @@ typedef struct OutputFilterOptions { · 4 unmodified lines
314316 const int *sample_rates;
315317 const AVChannelLayout *ch_layouts;
316318 const AVRational *frame_rates;
319+ const enum AVColorSpace *color_spaces;
320+ const enum AVColorRange *color_ranges;
317321 } OutputFilterOptions;
318322
319323 typedef struct InputFilter {
fftools/ffmpeg_filter.c+26−0
@@ -202,6 +202,8 @@ typedef struct OutputFilterPriv { · 201 unmodified lines
202202 int width, height;
203203 int sample_rate;
204204 AVChannelLayout ch_layout;
205+ enum AVColorSpace color_space;
206+ enum AVColorRange color_range;
205207
206208 // time base in which the output is sent to our downstream
207209 // does not need to match the filtersink's timebase
@@ -220,6 +222,8 @@ typedef struct OutputFilterPriv { · 12 unmodified lines
220222 const int *formats;
221223 const AVChannelLayout *ch_layouts;
222224 const int *sample_rates;
225+ const enum AVColorSpace *color_spaces;
226+ const enum AVColorRange *color_ranges;
223227
224228 AVRational enc_timebase;
225229 int64_t trim_start_us;
@@ -395,6 +399,12 @@ DEF_CHOOSE_FORMAT(sample_fmts, enum AVSampleFormat, format, formats, · 169 unmodified lines
395399 DEF_CHOOSE_FORMAT(sample_rates, int, sample_rate, sample_rates, 0,
396400 "%d", )
397401
402+DEF_CHOOSE_FORMAT(color_spaces, enum AVColorSpace, color_space, color_spaces,
403+ AVCOL_SPC_UNSPECIFIED, "%s", av_color_space_name);
404+
405+DEF_CHOOSE_FORMAT(color_ranges, enum AVColorRange, color_range, color_ranges,
406+ AVCOL_RANGE_UNSPECIFIED, "%s", av_color_range_name);
407+
398408 static void choose_channel_layouts(OutputFilterPriv *ofp, AVBPrint *bprint)
399409 {
400410 if (av_channel_layout_check(&ofp->ch_layout)) {
@@ -639,6 +649,8 @@ static OutputFilter *ofilter_alloc(FilterGraph *fg, enum AVMediaType type) · 238 unmodified lines
639649 ofilter->graph = fg;
640650 ofilter->type = type;
641651 ofp->format = -1;
652+ ofp->color_space = AVCOL_SPC_UNSPECIFIED;
653+ ofp->color_range = AVCOL_RANGE_UNSPECIFIED;
642654 ofp->index = fg->nb_outputs - 1;
643655
644656 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
822834 } else
823835 ofp->formats = opts->formats;
824836
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+
825847 fgp->disable_conversions |= !!(ofp->flags & OFILTER_FLAG_DISABLE_CONVERT);
826848
827849 ofp->fps.last_frame = av_frame_alloc();
@@ -1485,6 +1507,8 @@ static int configure_output_video_filter(FilterGraph *fg, AVFilterGraph *graph, · 657 unmodified lines
14851507 ofp->format != AV_PIX_FMT_NONE || !ofp->formats);
14861508 av_bprint_init(&bprint, 0, AV_BPRINT_SIZE_UNLIMITED);
14871509 choose_pix_fmts(ofp, &bprint);
1510+ choose_color_spaces(ofp, &bprint);
1511+ choose_color_ranges(ofp, &bprint);
14881512 if (!av_bprint_is_complete(&bprint))
14891513 return AVERROR(ENOMEM);
14901514
@@ -1907,6 +1931,8 @@ static int configure_filtergraph(FilterGraph *fg, FilterGraphThread *fgt) · 416 unmodified lines
19071931
19081932 ofp->width = av_buffersink_get_w(sink);
19091933 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);
19101936
19111937 // If the timing parameters are not locked yet, get the tentative values
19121938 // 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
934934 enc_ctx->pix_fmt : enc_ctx->sample_fmt,
935935 .width = enc_ctx->width,
936936 .height = enc_ctx->height,
937+ .color_space = enc_ctx->colorspace,
938+ .color_range = enc_ctx->color_range,
937939 .vsync_method = vsync_method,
938940 .sample_rate = enc_ctx->sample_rate,
939941 .ch_layout = enc_ctx->ch_layout,
@@ -967,6 +969,16 @@ ost_bind_filter(const Muxer *mux, MuxStream *ms, OutputFilter *ofilter, · 27 unmodified lines
967969 if (ret < 0)
968970 return ret;
969971 }
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;
970982 } else {
971983 ret = avcodec_get_supported_config(enc_ctx, NULL,
972984 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