]> git.sesse.net Git - mlt/commitdiff
Allow display of metadata and timecode
authorj-b-m <j-b-m@d19143bc-622f-0410-bfdd-b5b2a6649095>
Tue, 23 Jan 2007 23:20:50 +0000 (23:20 +0000)
committerj-b-m <j-b-m@d19143bc-622f-0410-bfdd-b5b2a6649095>
Tue, 23 Jan 2007 23:20:50 +0000 (23:20 +0000)
git-svn-id: https://mlt.svn.sourceforge.net/svnroot/mlt/trunk/mlt@948 d19143bc-622f-0410-bfdd-b5b2a6649095

src/modules/core/filter_data_show.c

index fc9fb3ecb7ac18b3e0d2928dfb36b44b4063bf96..b8fcd4cfde90d55f4dd53b671552714665e2fb89 100644 (file)
@@ -83,6 +83,34 @@ static mlt_filter obtain_filter( mlt_filter filter, char *type )
        return result;
 }
 
+/** Retrieve medatata value 
+*/
+
+const char* metadata_value(mlt_properties properties, char* name)
+{
+       if (name == NULL) return "-";
+       char *meta = malloc( strlen(name) + 18 );
+       sprintf( meta, "meta.attr.%s.markup", name);
+       return mlt_properties_get( properties, meta);
+}
+
+/** Convert frames to Timecode 
+*/
+
+const char* frame_to_timecode( int frames , int fps)
+{
+       char *res = malloc(12);
+       if (fps == 0) return "-";
+       int seconds = frames / (int) fps;
+       frames = frames % ((int) fps);
+       int minutes = seconds / 60;
+       seconds = seconds % 60;
+       int hours = minutes / 60;
+       minutes = minutes % 60;
+       sprintf(res, "%.2d:%.2d:%.2d:%.2d", hours, minutes, seconds, frames);
+       return res;
+}
+
 /** Process the frame for the requested type
 */
 
@@ -144,8 +172,39 @@ static int process_feed( mlt_properties feed, mlt_filter filter, mlt_frame frame
                                else
                                {
                                        char *value = mlt_properties_get( feed, name + len );
-                                       if ( value != NULL )
-                                               mlt_properties_set( properties, key, value );
+                                       if ( value != NULL ) {
+                                               // check for metadata keywords in metadata markup if user requested so
+                                               if ( mlt_properties_get_int( filter_properties, "dynamic" ) == 1  && !strcmp( name + strlen( name ) - 6, "markup") )
+                                               {
+                                                       // Find keywords which should be surrounded by '#', like: #title#
+                                                       char* keywords = strtok ( value, "\\#" );
+                                                       char result[] = "";
+                                                       int ct = 0;
+                                                       int fromStart = 0;
+                                                       if ( value[0] == '\\' ) fromStart = 1;
+                                                       
+                                                       while (keywords != NULL) {
+                                                               if (ct % 2 == fromStart) 
+                                                                       strcat( result, keywords);
+                                                               else if (!strcmp(keywords, "timecode")) {
+                                                                       // special case: replace #tc# with current frame timecode
+                                                                       int pos = mlt_properties_get_int( feed, "position" );
+                                                                       const char *tc = frame_to_timecode(pos, mlt_properties_get_int( MLT_FRAME_PROPERTIES( frame ), "fps" ));
+                                                                       strcat( result, tc);
+                                                               }
+                                                               else {
+                                                                       // replace keyword with metadata value
+                                                                       const char * metavalue = metadata_value(MLT_FRAME_PROPERTIES( frame ), keywords);
+                                                                       if (metavalue == NULL) metavalue = "-";
+                                                                       strcat( result, metavalue);
+                                                               }
+                                                               keywords = strtok ( NULL, "\\#" );
+                                                               ct++;
+                                                       }
+                                                       mlt_properties_set( properties, key, (char*) result );
+                                               }
+                                               else mlt_properties_set( properties, key, value );
+                                       }
                                }
                        }
                }