]> git.sesse.net Git - mlt/commitdiff
Add mlt_profile_from_producer().
authorDan Dennedy <dan@dennedy.org>
Sat, 28 May 2011 07:23:48 +0000 (00:23 -0700)
committerDan Dennedy <dan@dennedy.org>
Sat, 28 May 2011 07:23:48 +0000 (00:23 -0700)
This new function contains the auto-profile feature.
Plus setters for Mlt::Profile.

src/framework/mlt_profile.c
src/framework/mlt_profile.h
src/mlt++/MltProfile.cpp
src/mlt++/MltProfile.h

index 04b04cc92744d0ee7de46e692eaa251c26f9322c..542a8f11b896984aabe4dbda80d6abed78ed7cec 100644 (file)
@@ -21,9 +21,7 @@
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  */
 
-#include "mlt_profile.h"
-#include "mlt_factory.h"
-#include "mlt_properties.h"
+#include "mlt.h"
 
 #include <stdlib.h>
 #include <string.h>
@@ -390,3 +388,59 @@ mlt_properties mlt_profile_list( )
 
        return properties;
 }
+
+/** 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 );
+}
index 02638e54a7ec2eed3fa7c7ab64f096e502729684..c545404c840810afc5d1c262e363f246f6d521f6 100644 (file)
@@ -56,4 +56,5 @@ extern double mlt_profile_dar( mlt_profile profile );
 extern void mlt_profile_close( mlt_profile profile );
 extern mlt_profile mlt_profile_clone( mlt_profile profile );
 extern mlt_properties mlt_profile_list( );
+extern void mlt_profile_from_producer( mlt_profile profile, mlt_producer producer );
 #endif
index 47302b7aa788c3013ef4424d68b1f104927aec1f..051a9a42785ea2ea3eaa55c47bd5e5dd2772624b 100644 (file)
@@ -19,6 +19,8 @@
 
 #include "MltProfile.h"
 #include "MltProperties.h"
+#include "MltProducer.h"
+
 using namespace Mlt;
 
 Profile::Profile( ) :
@@ -125,3 +127,45 @@ Properties* Profile::list()
 {
        return new Properties( mlt_profile_list() );
 }
+
+void Profile::from_producer( Producer &producer )
+{
+       mlt_profile_from_producer( instance, producer.get_producer() );
+}
+
+void Profile::set_width( int width )
+{
+       instance->width = width;
+}
+
+void Profile::set_height( int height )
+{
+       instance->height = height;
+}
+
+void Profile::set_sample_aspect( int numerator, int denominator )
+{
+       instance->sample_aspect_num = numerator;
+       instance->sample_aspect_den = denominator;
+}
+
+void Profile::set_progressive( int progressive )
+{
+       instance->progressive = progressive;
+}
+
+void Profile::set_colorspace( int colorspace )
+{
+       instance->colorspace = colorspace;
+}
+
+void Profile::set_frame_rate( int numerator, int denominator )
+{
+       instance->sample_aspect_num = numerator;
+       instance->sample_aspect_den = denominator;
+}
+
+void Profile::set_explicit( int boolean )
+{
+       instance->is_explicit = boolean;
+}
index e51543dbdca91442e24cec1155c97db2708457df..248c83703afbe00197464b983a68d5c3361ab661 100644 (file)
@@ -31,6 +31,7 @@
 namespace Mlt
 {
        class Properties;
+       class Producer;
 
        class MLTPP_DECLSPEC Profile
        {
@@ -58,6 +59,14 @@ namespace Mlt
                        int display_aspect_den() const;
                        double dar() const;
                        static Properties* list();
+                       void from_producer( Producer &producer );
+                       void set_width( int width );
+                       void set_height( int height );
+                       void set_sample_aspect( int numerator, int denominator );
+                       void set_progressive( int progressive );
+                       void set_colorspace( int colorspace );
+                       void set_frame_rate( int numerator, int denominator );
+                       void set_explicit( int boolean );
        };
 }