@@ -42,6 +42,8 @@ typedef struct
42
42
int outformat ;
43
43
int width ;
44
44
int height ;
45
+ mlt_colorspace incolorspace ;
46
+ int infullrange ;
45
47
} private_data ;
46
48
47
49
typedef struct
@@ -98,6 +100,8 @@ static void init_image_filtergraph(mlt_link self, AVRational sar)
98
100
enum AVPixelFormat out_pixel_fmts [] = {-1 , -1 };
99
101
AVRational timebase = (AVRational ){profile -> frame_rate_den , profile -> frame_rate_num };
100
102
AVRational framerate = (AVRational ){profile -> frame_rate_num , profile -> frame_rate_den };
103
+ int colorspace = mlt_to_av_colorspace (pdata -> incolorspace , pdata -> height );
104
+ int color_range = mlt_to_av_color_range (pdata -> infullrange );
101
105
AVFilterContext * prev_ctx = NULL ;
102
106
AVFilterContext * avfilter_ctx = NULL ;
103
107
int ret ;
@@ -156,6 +160,16 @@ static void init_image_filtergraph(mlt_link self, AVRational sar)
156
160
mlt_log_error (self , "Cannot set src frame_rate %d/%d\n" , framerate .num , framerate .den );
157
161
goto fail ;
158
162
}
163
+ ret = av_opt_set_int (fdata -> avbuffsrc_ctx , "colorspace" , colorspace , AV_OPT_SEARCH_CHILDREN );
164
+ if (ret < 0 ) {
165
+ mlt_log_error (self , "Cannot set src colorspace %d\n" , colorspace );
166
+ goto fail ;
167
+ }
168
+ ret = av_opt_set_int (fdata -> avbuffsrc_ctx , "range" , color_range , AV_OPT_SEARCH_CHILDREN );
169
+ if (ret < 0 ) {
170
+ mlt_log_error (self , "Cannot set src range %d\n" , color_range );
171
+ goto fail ;
172
+ }
159
173
ret = avfilter_init_str (fdata -> avbuffsrc_ctx , NULL );
160
174
if (ret < 0 ) {
161
175
mlt_log_error (self , "Cannot init buffer source\n" );
@@ -391,12 +405,16 @@ static int link_get_image(mlt_frame frame,
391
405
}
392
406
srcimg .format = validate_format (srcimg .format );
393
407
dstimg .format = validate_format (* format );
408
+ const char * colorspace_str = mlt_properties_get (unique_properties , "colorspace" );
409
+ mlt_colorspace incolorspace = mlt_image_colorspace_id (colorspace_str );
410
+ int infullrange = mlt_properties_get_int (unique_properties , "full_range" );
394
411
395
412
mlt_service_lock (MLT_LINK_SERVICE (self ));
396
413
397
414
if (pdata -> method != method || pdata -> expected_frame != mlt_frame_get_position (frame )
398
415
|| pdata -> informat != srcimg .format || pdata -> width != srcimg .width
399
- || pdata -> height != srcimg .height || pdata -> outformat != dstimg .format ) {
416
+ || pdata -> height != srcimg .height || pdata -> outformat != dstimg .format
417
+ || pdata -> incolorspace != incolorspace || pdata -> infullrange != infullrange ) {
400
418
mlt_log_debug (MLT_LINK_SERVICE (self ),
401
419
"Init: %s->%s\t%d->%d\n" ,
402
420
mlt_deinterlacer_name (pdata -> method ),
@@ -410,6 +428,8 @@ static int link_get_image(mlt_frame frame,
410
428
pdata -> width = srcimg .width ;
411
429
pdata -> height = srcimg .height ;
412
430
pdata -> outformat = dstimg .format ;
431
+ pdata -> incolorspace = incolorspace ;
432
+ pdata -> infullrange = infullrange ;
413
433
init_image_filtergraph (self , av_d2q (mlt_frame_get_aspect_ratio (frame ), 1024 ));
414
434
}
415
435
@@ -555,6 +575,21 @@ static int link_get_frame(mlt_link self, mlt_frame_ptr frame, int index)
555
575
"format" ,
556
576
mlt_properties_get_int (original_producer_properties , "format" ));
557
577
}
578
+ if (mlt_properties_exists (original_producer_properties , "meta.media.colorspace" )) {
579
+ mlt_properties_set (unique_properties ,
580
+ "colorspace" ,
581
+ mlt_properties_get (original_producer_properties ,
582
+ "meta.media.colorspace" ));
583
+ } else if (mlt_properties_exists (MLT_FRAME_PROPERTIES (* frame ), "colorspace" )) {
584
+ mlt_properties_set (unique_properties ,
585
+ "colorspace" ,
586
+ mlt_properties_get (MLT_FRAME_PROPERTIES (* frame ), "colorspace" ));
587
+ }
588
+ if (mlt_properties_exists (MLT_FRAME_PROPERTIES (* frame ), "full_range" )) {
589
+ mlt_properties_set (unique_properties ,
590
+ "full_range" ,
591
+ mlt_properties_get (MLT_FRAME_PROPERTIES (* frame ), "full_range" ));
592
+ }
558
593
559
594
// Pass future frames
560
595
int i = 0 ;
0 commit comments