+
+/** Update the profile using the attributes of a producer.
+ *
+ * Use this to make an "auto-profile." Typically, you need to re-open the producer
+ * after you use this because some producers (e.g. avformat) adjust their framerate
+ * to that of the profile used when you created it.
+ * \public \memberof mlt_profile_s
+ * \param profile the profile to update
+ * \param producer the producer to inspect
+ */
+
+void mlt_profile_from_producer( mlt_profile profile, mlt_producer producer )
+{
+ mlt_frame fr = NULL;
+ uint8_t *buffer;
+ mlt_image_format fmt = mlt_image_yuv422;
+ mlt_properties p;
+ int w = profile->width;
+ int h = profile->height;
+
+ if ( ! mlt_service_get_frame( MLT_PRODUCER_SERVICE(producer), &fr, 0 ) && fr )
+ {
+ mlt_properties_set_double( MLT_FRAME_PROPERTIES( fr ), "consumer_aspect_ratio", mlt_profile_sar( profile ) );
+ if ( ! mlt_frame_get_image( fr, &buffer, &fmt, &w, &h, 0 ) )
+ {
+ // Some source properties are not exposed until after the first get_image call.
+ mlt_frame_close( fr );
+ mlt_service_get_frame( MLT_PRODUCER_SERVICE(producer), &fr, 0 );
+ p = MLT_FRAME_PROPERTIES( fr );
+// mlt_properties_dump(p, stderr);
+ if ( mlt_properties_get_int( p, "meta.media.frame_rate_den" ) && mlt_properties_get_int( p, "meta.media.sample_aspect_den" ) )
+ {
+ profile->width = mlt_properties_get_int( p, "meta.media.width" );
+ profile->height = mlt_properties_get_int( p, "meta.media.height" );
+ profile->progressive = mlt_properties_get_int( p, "meta.media.progressive" );
+ profile->frame_rate_num = mlt_properties_get_int( p, "meta.media.frame_rate_num" );
+ profile->frame_rate_den = mlt_properties_get_int( p, "meta.media.frame_rate_den" );
+ // AVCHD is mis-reported as double frame rate.
+ if ( profile->progressive == 0 && (
+ profile->frame_rate_num / profile->frame_rate_den == 50 ||
+ profile->frame_rate_num / profile->frame_rate_den == 59 ) )
+ profile->frame_rate_num /= 2;
+ 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 );
+ profile->description = strdup( "automatic" );
+ profile->is_explicit = 0;
+ }
+ }
+ }
+ mlt_frame_close( fr );
+ mlt_producer_seek( producer, 0 );
+}