From 8d4492759357a003a45b2a8096a468ae27ed0471 Mon Sep 17 00:00:00 2001 From: Dan Dennedy Date: Mon, 2 Dec 2013 20:14:02 -0800 Subject: [PATCH] Add mlt_properties_frames_to_time() and mlt_properties_time_to_frames(). Handy conversion functions for apps. --- src/framework/mlt.vers | 5 +++++ src/framework/mlt_properties.c | 32 ++++++++++++++++++++++++++++++++ src/framework/mlt_properties.h | 4 ++++ src/mlt++/MltProperties.cpp | 10 ++++++++++ src/mlt++/MltProperties.h | 3 +++ src/mlt++/mlt++.vers | 8 ++++++++ 6 files changed, 62 insertions(+) diff --git a/src/framework/mlt.vers b/src/framework/mlt.vers index 45b0b3ff..a0069e41 100644 --- a/src/framework/mlt.vers +++ b/src/framework/mlt.vers @@ -447,3 +447,8 @@ MLT_0.9.0 { mlt_service_filter_count; mlt_service_move_filter; } MLT_0.8.8; + +MLT_0.9.2 { + mlt_properties_frames_to_time; + mlt_properties_time_to_frames; +} MLT_0.9.0; diff --git a/src/framework/mlt_properties.c b/src/framework/mlt_properties.c index 415313d6..c28af8fc 100644 --- a/src/framework/mlt_properties.c +++ b/src/framework/mlt_properties.c @@ -2092,6 +2092,38 @@ char *mlt_properties_get_time( mlt_properties self, const char* name, mlt_time_f return NULL; } +/** Convert a frame count to a time string. + * + * Do not free the returned string. It's lifetime is controlled by the property. + * \public \memberof mlt_properties_s + * \param self a properties list + * \param frames the frame count to convert + * \param format the time format that you want + * \return the time string or NULL if error, e.g. there is no profile + */ + +char *mlt_properties_frames_to_time( mlt_properties self, mlt_position frames, mlt_time_format format ) +{ + const char *name = "_mlt_properties_time"; + mlt_properties_set_position( self, name, frames ); + return mlt_properties_get_time( self, name, format ); +} + +/** Convert a time string to a frame count. + * + * \public \memberof mlt_properties_s + * \param self a properties list + * \param time the time string to convert + * \return a frame count or a negative value if error, e.g. there is no profile + */ + +mlt_position mlt_properties_time_to_frames( mlt_properties self, const char *time ) +{ + const char *name = "_mlt_properties_time"; + mlt_properties_set( self, name, time ); + return mlt_properties_get_position( self, name ); +} + /** Convert a numeric property to a tuple of color components. * * If the property's string is red, green, blue, white, or black, then it diff --git a/src/framework/mlt_properties.h b/src/framework/mlt_properties.h index 7c4900d3..f4a44c0e 100644 --- a/src/framework/mlt_properties.h +++ b/src/framework/mlt_properties.h @@ -88,7 +88,11 @@ extern mlt_properties mlt_properties_parse_yaml( const char *file ); extern char *mlt_properties_serialise_yaml( mlt_properties self ); extern void mlt_properties_lock( mlt_properties self ); extern void mlt_properties_unlock( mlt_properties self ); + extern char *mlt_properties_get_time( mlt_properties, const char* name, mlt_time_format ); +extern char *mlt_properties_frames_to_time( mlt_properties, mlt_position, mlt_time_format ); +extern mlt_position mlt_properties_time_to_frames( mlt_properties, const char* time ); + extern mlt_color mlt_properties_get_color( mlt_properties, const char* name ); extern int mlt_properties_set_color( mlt_properties, const char* name, mlt_color value ); diff --git a/src/mlt++/MltProperties.cpp b/src/mlt++/MltProperties.cpp index 9648e032..3da531a9 100644 --- a/src/mlt++/MltProperties.cpp +++ b/src/mlt++/MltProperties.cpp @@ -337,6 +337,16 @@ char *Properties::get_time( const char *name, mlt_time_format format ) return mlt_properties_get_time( get_properties(), name, format ); } +char *Properties::frames_to_time( int frames, mlt_time_format format ) +{ + return mlt_properties_frames_to_time( get_properties(), frames, format ); +} + +int Properties::time_to_frames( const char *time ) +{ + return mlt_properties_time_to_frames( get_properties(), time ); +} + mlt_color Properties::get_color( const char *name ) { return mlt_properties_get_color( get_properties(), name ); diff --git a/src/mlt++/MltProperties.h b/src/mlt++/MltProperties.h index d2f8e8a3..6c5b8e87 100644 --- a/src/mlt++/MltProperties.h +++ b/src/mlt++/MltProperties.h @@ -97,6 +97,9 @@ namespace Mlt int set_lcnumeric( const char *locale ); const char *get_lcnumeric( ); char *get_time( const char *name, mlt_time_format = mlt_time_smpte ); + char *frames_to_time( int, mlt_time_format = mlt_time_smpte ); + int time_to_frames( const char* time ); + mlt_color get_color( const char *name ); int set( const char *name , mlt_color value ); diff --git a/src/mlt++/mlt++.vers b/src/mlt++/mlt++.vers index 6dfb3629..17ec647d 100644 --- a/src/mlt++/mlt++.vers +++ b/src/mlt++/mlt++.vers @@ -457,3 +457,11 @@ MLTPP_0.9.0 { "Mlt::Service::move_filter(int, int)"; }; } MLTPP_0.8.8; + +MLTPP_0.9.2 { + global: + extern "C++" { + "Mlt::Properties::frames_to_time(int, mlt_time_format)"; + "Mlt::Properties::time_to_frames(char const*)"; + }; +} MLTPP_0.9.0; -- 2.39.5