@@ -155,14 +155,29 @@ static int convert_image(mlt_frame frame,
155155 if (* format != output_format || out_width ) {
156156 mlt_profile profile = mlt_service_profile (
157157 MLT_PRODUCER_SERVICE (mlt_frame_get_original_producer (frame )));
158- mlt_colorspace profile_colorspace = profile ? profile -> colorspace : mlt_colorspace_bt601 ;
159- const char * colorspace_str = mlt_properties_get (properties , "colorspace" );
160- mlt_colorspace colorspace = mlt_image_colorspace_id (colorspace_str );
161158 int width = mlt_properties_get_int (properties , "width" );
162159 int height = mlt_properties_get_int (properties , "height" );
160+ mlt_colorspace dst_colorspace = profile ? profile -> colorspace : mlt_colorspace_bt601 ;
161+ const char * src_colorspace_str = mlt_properties_get (properties , "colorspace" );
162+ mlt_colorspace src_colorspace = mlt_image_colorspace_id (src_colorspace_str );
163+ if (src_colorspace == mlt_colorspace_unspecified
164+ || src_colorspace == mlt_colorspace_reserved
165+ || src_colorspace == mlt_colorspace_invalid ) {
166+ src_colorspace = mlt_image_default_colorspace (* format , height );
167+ }
163168 int src_full_range = mlt_properties_get_int (properties , "full_range" );
164169 const char * dst_color_range = mlt_properties_get (properties , "consumer.color_range" );
165170 int dst_full_range = mlt_image_full_range (dst_color_range );
171+ // Fix some producers that may not be setting properties correctly
172+ if (output_format == mlt_image_rgb || output_format == mlt_image_rgba
173+ || output_format == mlt_image_rgba64 ) {
174+ dst_full_range = 1 ;
175+ dst_colorspace = mlt_colorspace_rgb ;
176+ }
177+ if (* format == mlt_image_rgb || * format == mlt_image_rgba || * format == mlt_image_rgba64 ) {
178+ src_full_range = 1 ;
179+ src_colorspace = mlt_colorspace_rgb ;
180+ }
166181
167182 if (out_width <= 0 )
168183 out_width = width ;
@@ -178,8 +193,8 @@ static int convert_image(mlt_frame frame,
178193 mlt_image_format_name (output_format ),
179194 out_width ,
180195 out_height ,
181- colorspace ,
182- profile_colorspace ,
196+ src_colorspace ,
197+ dst_colorspace ,
183198 src_full_range ,
184199 dst_full_range ,
185200 mlt_frame_get_position (frame ));
@@ -260,15 +275,11 @@ static int convert_image(mlt_frame frame,
260275 out_height ,
261276 width ,
262277 height ,
263- colorspace ,
264- profile_colorspace ,
278+ src_colorspace ,
279+ dst_colorspace ,
265280 src_full_range ,
266281 dst_full_range )) {
267- // The new colorspace is only valid if destination is YUV.
268- if (output_format == mlt_image_yuv422 || output_format == mlt_image_yuv420p
269- || output_format == mlt_image_yuv422p16 || output_format == mlt_image_yuv420p10
270- || output_format == mlt_image_yuv444p10 )
271- mlt_properties_set_int (properties , "colorspace" , profile_colorspace );
282+ mlt_properties_set_int (properties , "colorspace" , dst_colorspace );
272283 mlt_properties_set_int (properties , "full_range" , dst_full_range );
273284 }
274285 mlt_frame_set_image (frame , output , size , mlt_pool_release );
@@ -344,15 +355,6 @@ static int convert_image(mlt_frame frame,
344355
345356static mlt_frame filter_process (mlt_filter filter , mlt_frame frame )
346357{
347- // Set a default colorspace on the frame if not yet set by the producer.
348- // The producer may still change it during get_image.
349- // This way we do not have to modify each producer to set a valid colorspace.
350- mlt_properties properties = MLT_FRAME_PROPERTIES (frame );
351- if (mlt_properties_get_int (properties , "colorspace" ) <= 0 )
352- mlt_properties_set_int (properties ,
353- "colorspace" ,
354- mlt_service_profile (MLT_FILTER_SERVICE (filter ))-> colorspace );
355-
356358 if (!frame -> convert_image )
357359 frame -> convert_image = convert_image ;
358360
0 commit comments