[FFmpeg-devel] [PATCH 06/29] fftools/ffmpeg_filter: auto insert scale filter to convert between different color_ranges if necessary

Paul B Mahol onemda at gmail.com
Sun Dec 10 15:14:13 EET 2017


Signed-off-by: Paul B Mahol <onemda at gmail.com>
---
 fftools/ffmpeg_filter.c | 16 +++++++++++++---
 1 file changed, 13 insertions(+), 3 deletions(-)

diff --git a/fftools/ffmpeg_filter.c b/fftools/ffmpeg_filter.c
index 877fd670e6..e69bfe295c 100644
--- a/fftools/ffmpeg_filter.c
+++ b/fftools/ffmpeg_filter.c
@@ -449,6 +449,7 @@ static int configure_output_video_filter(FilterGraph *fg, OutputFilter *ofilter,
     OutputStream *ost = ofilter->ost;
     OutputFile    *of = output_files[ost->file_index];
     AVFilterContext *last_filter = out->filter_ctx;
+    AVDictionaryEntry *cre = NULL;
     int pad_idx = out->pad_idx;
     int ret;
     char name[255];
@@ -461,7 +462,9 @@ static int configure_output_video_filter(FilterGraph *fg, OutputFilter *ofilter,
     if (ret < 0)
         return ret;
 
-    if (ofilter->width || ofilter->height) {
+    cre = av_dict_get(ost->encoder_opts, "color_range", NULL, 0);
+
+    if (ofilter->width || ofilter->height || (cre && cre->value) || ost->enc->color_range) {
         char args[255];
         AVFilterContext *filter;
         AVDictionaryEntry *e = NULL;
@@ -474,6 +477,12 @@ static int configure_output_video_filter(FilterGraph *fg, OutputFilter *ofilter,
             av_strlcatf(args, sizeof(args), ":%s=%s", e->key, e->value);
         }
 
+        if (cre && cre->value) {
+            av_strlcatf(args, sizeof(args), ":out_range=%s", cre->value);
+        } else if (ost->enc->color_range) {
+            av_strlcatf(args, sizeof(args), ":out_range=%s", av_color_range_name(ost->enc->color_range));
+        }
+
         snprintf(name, sizeof(name), "scaler_out_%d_%d",
                  ost->file_index, ost->index);
         if ((ret = avfilter_graph_create_filter(&filter, avfilter_get_by_name("scale"),
@@ -777,10 +786,11 @@ static int configure_input_video_filter(FilterGraph *fg, InputFilter *ifilter,
     av_bprint_init(&args, 0, 1);
     av_bprintf(&args,
              "video_size=%dx%d:pix_fmt=%d:time_base=%d/%d:"
-             "pixel_aspect=%d/%d:sws_param=flags=%d",
+             "pixel_aspect=%d/%d:sws_param=flags=%d:color_range=%s",
              ifilter->width, ifilter->height, ifilter->format,
              tb.num, tb.den, sar.num, sar.den,
-             SWS_BILINEAR + ((ist->dec_ctx->flags&AV_CODEC_FLAG_BITEXACT) ? SWS_BITEXACT:0));
+             SWS_BILINEAR + ((ist->dec_ctx->flags&AV_CODEC_FLAG_BITEXACT) ? SWS_BITEXACT:0),
+             av_color_range_name(ist->dec_ctx->color_range));
     if (fr.num && fr.den)
         av_bprintf(&args, ":frame_rate=%d/%d", fr.num, fr.den);
     snprintf(name, sizeof(name), "graph %d input from stream %d:%d", fg->index,
-- 
2.11.0



More information about the ffmpeg-devel mailing list