@@ -55,6 +55,7 @@ typedef struct
5555 int width ;
5656 int height ;
5757 mlt_colorspace colorspace ;
58+ int full_range ;
5859 int reset ;
5960} private_data ;
6061
@@ -377,6 +378,7 @@ static void init_image_filtergraph(mlt_filter filter,
377378 int width ,
378379 int height ,
379380 mlt_colorspace colorspace ,
381+ int full_range ,
380382 double resolution_scale )
381383{
382384 private_data * pdata = (private_data * ) filter -> child ;
@@ -391,12 +393,14 @@ static void init_image_filtergraph(mlt_filter filter,
391393 AVRational timebase = (AVRational ){profile -> frame_rate_den , profile -> frame_rate_num };
392394 AVRational framerate = (AVRational ){profile -> frame_rate_num , profile -> frame_rate_den };
393395 int avcolorspace = mlt_to_av_colorspace (colorspace , pdata -> height );
396+ int color_range = mlt_to_av_color_range (full_range );
394397 int ret ;
395398
396399 pdata -> format = format ;
397400 pdata -> width = width ;
398401 pdata -> height = height ;
399- pdata -> colorspace = avcolorspace ;
402+ pdata -> colorspace = colorspace ;
403+ pdata -> full_range = full_range ;
400404
401405 // Set up formats
402406 pixel_fmts [0 ] = mlt_to_av_image_format (format );
@@ -464,6 +468,11 @@ static void init_image_filtergraph(mlt_filter filter,
464468 mlt_log_error (filter , "Cannot set src colorspace %d\n" , avcolorspace );
465469 goto fail ;
466470 }
471+ ret = av_opt_set_int (pdata -> avbuffsrc_ctx , "range" , color_range , AV_OPT_SEARCH_CHILDREN );
472+ if (ret < 0 ) {
473+ mlt_log_error (filter , "Cannot set src range %d\n" , color_range );
474+ goto fail ;
475+ }
467476 ret = avfilter_init_str (pdata -> avbuffsrc_ctx , NULL );
468477 if (ret < 0 ) {
469478 mlt_log_error (filter , "Cannot init buffer source\n" );
@@ -810,10 +819,12 @@ static int filter_get_image(mlt_frame frame,
810819 double scale = mlt_profile_scale_width (profile , * width );
811820 const char * colorspace_str = mlt_properties_get (frame_properties , "colorspace" );
812821 mlt_colorspace colorspace = mlt_image_colorspace_id (colorspace_str );
822+ int full_range = mlt_properties_get_int (frame_properties , "full_range" );
813823
814824 if (pdata -> reset || pdata -> format != * format || pdata -> width != * width
815- || pdata -> height != * height || pdata -> colorspace != colorspace ) {
816- init_image_filtergraph (filter , * format , * width , * height , colorspace , scale );
825+ || pdata -> height != * height || pdata -> colorspace != colorspace
826+ || pdata -> full_range != full_range ) {
827+ init_image_filtergraph (filter , * format , * width , * height , colorspace , full_range , scale );
817828 pdata -> reset = 0 ;
818829 }
819830
@@ -844,11 +855,7 @@ static int filter_get_image(mlt_frame frame,
844855 pdata -> avinframe -> color_primaries = mlt_to_av_color_primaries (primaries );
845856 const char * color_trc_str = mlt_properties_get (frame_properties , "color_trc" );
846857 pdata -> avinframe -> color_trc = mlt_to_av_color_trc (mlt_image_color_trc_id (color_trc_str ));
847- // Setting full_range here causes full range input to always be down-converted to limited
848- // range when operating in YUV, regardless of the consumer.color_range -- for each avfilter!
849- // pdata->avinframe->color_range = mlt_properties_get_int(frame_properties, "full_range")
850- // ? AVCOL_RANGE_JPEG
851- // : AVCOL_RANGE_MPEG;
858+ pdata -> avinframe -> color_range = mlt_to_av_color_range (full_range );
852859
853860 if (is_rgb (* format )) {
854861 pdata -> avinframe -> colorspace = AVCOL_SPC_RGB ;
0 commit comments