]> git.sesse.net Git - mlt/commitdiff
Add colorspace to auto-profile.
authorDan Dennedy <dan@dennedy.org>
Thu, 14 Oct 2010 02:42:47 +0000 (19:42 -0700)
committerDan Dennedy <dan@dennedy.org>
Thu, 14 Oct 2010 02:42:47 +0000 (19:42 -0700)
src/melt/melt.c
src/modules/avformat/producer_avformat.c

index 749b8613b613aaf943d1e4eedea78d7d5ccf5ef4..041fcca5c9a0809de14ac8a39c8afd7f3c2d42cb 100644 (file)
@@ -363,6 +363,7 @@ static void guess_profile( mlt_producer melt, mlt_profile profile )
                                profile->frame_rate_den = mlt_properties_get_int( p, "meta.media.frame_rate_den" );
                                profile->sample_aspect_num = mlt_properties_get_int( p, "meta.media.sample_aspect_num" );
                                profile->sample_aspect_den = mlt_properties_get_int( p, "meta.media.sample_aspect_den" );
+                               profile->colorspace = mlt_properties_get_int( p, "meta.media.colorspace" );
                                profile->display_aspect_num = (int) ( (double) profile->sample_aspect_num * profile->width / profile->sample_aspect_den + 0.5 );
                                profile->display_aspect_den = profile->height;
                                free( profile->description );
index 12933d5cf75802a082d0a6b133d3269634ac1d13..f53833087377cd7166bb5d208edff08854a5be42 100644 (file)
@@ -282,9 +282,25 @@ static mlt_properties find_default_streams( mlt_properties meta_media, AVFormatC
                                mlt_properties_set( meta_media, key, avcodec_get_pix_fmt_name( codec_context->pix_fmt ) );
                                snprintf( key, sizeof(key), "meta.media.%d.codec.sample_aspect_ratio", i );
                                mlt_properties_set_double( meta_media, key, av_q2d( codec_context->sample_aspect_ratio ) );
-                               snprintf( key, sizeof(key), "meta.media.%d.codec.colorspace", i );
 #if LIBAVCODEC_VERSION_INT > ((52<<16)+(28<<8)+0)
-                               mlt_properties_set_int( meta_media, key, codec_context->colorspace );
+                               snprintf( key, sizeof(key), "meta.media.%d.codec.colorspace", i );
+                               switch ( codec_context->colorspace )
+                               {
+                               case AVCOL_SPC_SMPTE240M:
+                                       mlt_properties_set_int( meta_media, key, 240 );
+                                       break;
+                               case AVCOL_SPC_BT470BG:
+                               case AVCOL_SPC_SMPTE170M:
+                                       mlt_properties_set_int( meta_media, key, 601 );
+                                       break;
+                               case AVCOL_SPC_BT709:
+                                       mlt_properties_set_int( meta_media, key, 709 );
+                                       break;
+                               default:
+                                       // This is a heuristic Charles Poynton suggests in "Digital Video and HDTV"
+                                       mlt_properties_set_int( meta_media, key, codec_context->width * codec_context->height > 750000 ? 709 : 601 );
+                                       break;
+                               }
 #endif
                                break;
                        case CODEC_TYPE_AUDIO:
@@ -1566,7 +1582,7 @@ static int video_codec_init( producer_avformat this, int index, mlt_properties p
                }
 #endif
                // Let apps get chosen colorspace
-               mlt_properties_set_int( properties, "colorspace", this->colorspace );
+               mlt_properties_set_int( properties, "meta.media.colorspace", this->colorspace );
        }
        return this->video_codec && this->video_index > -1;
 }