* Copyright (C) 2004-2005 Ushodaya Enterprises Limited
* Author: Charles Yates <charles.yates@pandora.be>
*
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
*
- * This program is distributed in the hope that it will be useful,
+ * This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
*
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "filter_data.h"
return result;
}
+/** Retrieve medatata value
+*/
+
+char* metadata_value(mlt_properties properties, char* name)
+{
+ if (name == NULL) return NULL;
+ char *meta = malloc( strlen(name) + 18 );
+ sprintf( meta, "meta.attr.%s.markup", name);
+ char *result = mlt_properties_get( properties, meta);
+ free(meta);
+ return result;
+}
+
+/** Convert frames to Timecode
+*/
+
+char* frame_to_timecode( int frames , int fps)
+{
+ if (fps == 0) return strdup("-");
+ char *res = malloc(12);
+ 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
*/
{
if ( !strncmp( name + len, "length[", 7 ) )
{
- mlt_properties_set_position( properties, key, length / period );
+ mlt_properties_set_position( properties, key, ( length - period ) / period );
}
else
{
char *value = mlt_properties_get( feed, name + len );
if ( value != NULL )
- mlt_properties_set( properties, key, value );
+ {
+ // 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[512] = ""; // XXX: how much is enough?
+ int ct = 0;
+ int fromStart = ( value[0] == '#' ) ? 1 : 0;
+
+ while ( keywords != NULL )
+ {
+ if ( ct % 2 == fromStart )
+ {
+ // backslash in front of # suppresses substitution
+ if ( keywords[ strlen( keywords ) -1 ] == '\\' )
+ {
+ // keep characters except backslash
+ strncat( result, keywords, strlen( keywords ) -1 );
+ strcat( result, "#" );
+ ct++;
+ }
+ else
+ {
+ strcat( result, keywords );
+ }
+ }
+ else if ( !strcmp( keywords, "timecode" ) )
+ {
+ // special case: replace #timecode# with current frame timecode
+ int pos = mlt_properties_get_int( feed, "position" );
+ char *tc = frame_to_timecode( pos, mlt_properties_get_int( MLT_FRAME_PROPERTIES( frame ), "fps" ) );
+ strcat( result, tc );
+ free( tc );
+ }
+ else
+ {
+ // replace keyword with metadata value
+ char *metavalue = metadata_value( MLT_FRAME_PROPERTIES( frame ), keywords );
+ strcat( result, metavalue ? metavalue : "-" );
+ }
+ keywords = strtok( NULL, "#" );
+ ct++;
+ }
+ mlt_properties_set( properties, key, (char*) result );
+ }
+ else mlt_properties_set( properties, key, value );
+ }
}
}
}
return error;
}
+void process_queue( mlt_deque data_queue, mlt_frame frame, mlt_filter filter )
+{
+ if ( data_queue != NULL )
+ {
+ // Create a new queue for those that we can't handle
+ mlt_deque temp_queue = mlt_deque_init( );
+
+ // Iterate through each entry on the queue
+ while ( mlt_deque_peek_front( data_queue ) != NULL )
+ {
+ // Get the data feed
+ mlt_properties feed = mlt_deque_pop_front( data_queue );
+
+ if ( mlt_properties_get( MLT_FILTER_PROPERTIES( filter ), "debug" ) != NULL )
+ mlt_properties_debug( feed, mlt_properties_get( MLT_FILTER_PROPERTIES( filter ), "debug" ), stderr );
+
+ // Process the data feed...
+ if ( process_feed( feed, filter, frame ) == 0 )
+ mlt_properties_close( feed );
+ else
+ mlt_deque_push_back( temp_queue, feed );
+ }
+
+ // Now put the unprocessed feeds back on the stack
+ while ( mlt_deque_peek_front( temp_queue ) )
+ {
+ // Get the data feed
+ mlt_properties feed = mlt_deque_pop_front( temp_queue );
+
+ // Put it back on the data queue
+ mlt_deque_push_back( data_queue, feed );
+ }
+
+ // Close the temporary queue
+ mlt_deque_close( temp_queue );
+ }
+}
+
/** Get the image.
*/
// Get the frame properties
mlt_properties frame_properties = MLT_FRAME_PROPERTIES( frame );
- // Fetch the data queue
- mlt_deque data_queue = mlt_properties_get_data( frame_properties, "data_queue", NULL );
-
- // Create a new queue for those that we can't handle
- mlt_deque temp_queue = mlt_deque_init( );
-
- // Iterate through each entry on the queue
- while ( data_queue != NULL && mlt_deque_peek_front( data_queue ) != NULL )
- {
- // Get the data feed
- mlt_properties feed = mlt_deque_pop_front( data_queue );
-
- // Process the data feed...
- if ( process_feed( feed, filter, frame ) == 0 )
- mlt_properties_close( feed );
- else
- mlt_deque_push_back( temp_queue, feed );
- }
-
- // Now put the unprocessed feeds back on the stack
- while ( data_queue != NULL && mlt_deque_peek_front( temp_queue ) )
- {
- // Get the data feed
- mlt_properties feed = mlt_deque_pop_front( temp_queue );
-
- // Put it back on the data queue
- mlt_deque_push_back( data_queue, feed );
- }
+ // Track specific
+ process_queue( mlt_properties_get_data( frame_properties, "data_queue", NULL ), frame, filter );
- // Close the temporary queue
- mlt_deque_close( temp_queue );
+ // Global
+ process_queue( mlt_properties_get_data( frame_properties, "global_queue", NULL ), frame, filter );
// Need to get the image
return mlt_frame_get_image( frame, image, format, width, height, 1 );