Beispiel #1
0
static void consumer_close( mlt_consumer parent )
{
	// Get the actual object
	consumer_sdl self = parent->child;

	// Stop the consumer
	mlt_consumer_stop( parent );

	// Now clean up the rest
	mlt_consumer_close( parent );

	// Close the queue
	mlt_deque_close( self->queue );

	// Destroy mutexes
	pthread_mutex_destroy( &self->audio_mutex );
	pthread_cond_destroy( &self->audio_cond );
	pthread_mutex_destroy( &self->video_mutex );
	pthread_cond_destroy( &self->video_cond );
	pthread_mutex_destroy( &self->refresh_mutex );
	pthread_cond_destroy( &self->refresh_cond );

	// Finally clean up this
	free( self );
}
Beispiel #2
0
static void foreach_consumer_stop( mlt_consumer consumer )
{
    mlt_properties properties = MLT_CONSUMER_PROPERTIES( consumer );
    mlt_consumer nested = NULL;
    char key[30];
    int index = 0;
    struct timespec tm = { 0, 1000 * 1000 };

    do {
        snprintf( key, sizeof(key), "%d.consumer", index++ );
        nested = mlt_properties_get_data( properties, key, NULL );
        if ( nested )
        {
            // Let consumer with terminate_on_pause stop on their own
            if ( mlt_properties_get_int( MLT_CONSUMER_PROPERTIES(nested), "terminate_on_pause" ) )
            {
                // Send additional dummy frame to unlatch nested consumer's threads
                mlt_consumer_put_frame( nested, mlt_frame_init( MLT_CONSUMER_SERVICE(consumer) ) );
                // wait for stop
                while ( !mlt_consumer_is_stopped( nested ) )
                    nanosleep( &tm, NULL );
            }
            else
            {
                mlt_consumer_stop( nested );
            }
        }
    } while ( nested );
}
Beispiel #3
0
static void consumer_close( mlt_consumer consumer )
{
    mlt_consumer_stop( consumer );

    // Close the parent
    mlt_consumer_close( consumer );
    free( consumer );
}
Beispiel #4
0
static void consumer_close( mlt_consumer consumer )
{
	// Stop the consumer
	mlt_consumer_stop( consumer );

	// Close the parent
	mlt_consumer_close( consumer );

	// Free the memory
	free( consumer );
}
Beispiel #5
0
static void close( mlt_consumer consumer )
{
	// Stop the consumer
	mlt_consumer_stop( consumer );

	// Close the parent
	consumer->close = NULL;
	mlt_consumer_close( consumer );

	// Free the memory
	delete (DeckLinkConsumer*) consumer->child;
}
Beispiel #6
0
static void producer_close( mlt_producer self )
{
	context cx = mlt_properties_get_data( MLT_PRODUCER_PROPERTIES( self ), "context", NULL );
	
	// Shut down all the encapsulated services
	if ( cx )
	{
		mlt_consumer_stop( cx->consumer );
		mlt_consumer_close( cx->consumer );
		mlt_producer_close( cx->producer );
		mlt_profile_close( cx->profile );
	}
	
	self->close = NULL;
	mlt_producer_close( self );
	free( self );
}
Beispiel #7
0
static void consumer_close( mlt_consumer parent )
{
	// Get the actual object
	consumer_sdl self = parent->child;

	// Stop the consumer
	mlt_consumer_stop( parent );

	// Close the child consumers
	mlt_consumer_close( self->play );
	mlt_consumer_close( self->still );

	// Now clean up the rest
	mlt_consumer_close( parent );

	// Finally clean up self
	free( self );
}
Beispiel #8
0
void MltRuntime::stop_ulk() throw (Exception)
{
	if (status == StatusRunning) {
		mlt_consumer_purge(consumer);
		mlt_consumer_stop(consumer);

		while ( mlt_consumer_is_stopped(consumer) == 0) {
			struct timespec req = {1,0};
			nanosleep(&req,NULL);
		}
		status = StatusStopped;
	}

	if (consumer) {
		mlt_consumer_close(consumer);
		consumer = NULL;
	}
}
Beispiel #9
0
static void consumer_close( mlt_consumer consumer )
{
	mlt_properties consumer_properties = MLT_CONSUMER_PROPERTIES( consumer );
	avsync_stats* stats = mlt_properties_get_data( consumer_properties, "_stats", NULL );

	// Stop the consumer
	mlt_consumer_stop( consumer );

	// Close the file
	if( stats->out_file != stdout )
	{
		fclose( stats->out_file );
	}

	// Clean up memory
	mlt_pool_release( stats );

	// Close the parent
	mlt_consumer_close( consumer );

	// Free the memory
	free( consumer );
}
Beispiel #10
0
static void *consumer_thread( void *arg )
{
	// Identify the arg
	consumer_sdl self = arg;

	// Get the consumer
	mlt_consumer consumer = &self->parent;

	// Get the properties
	mlt_properties properties = MLT_CONSUMER_PROPERTIES( consumer );

	// internal intialization
	mlt_frame frame = NULL;
	int last_position = -1;
	int eos = 0;
	int eos_threshold = 20;
	if ( self->play )
		eos_threshold = eos_threshold + mlt_properties_get_int( MLT_CONSUMER_PROPERTIES( self->play ), "buffer" );

	// Determine if the application is dealing with the preview
	int preview_off = mlt_properties_get_int( properties, "preview_off" );

	pthread_mutex_lock( &self->refresh_mutex );
	self->refresh_count = 0;
	pthread_mutex_unlock( &self->refresh_mutex );

	// Loop until told not to
	while( self->running )
	{
		// Get a frame from the attached producer
		frame = mlt_consumer_get_frame( consumer );

		// Ensure that we have a frame
		if ( self->running && frame != NULL )
		{
			// Get the speed of the frame
			double speed = mlt_properties_get_double( MLT_FRAME_PROPERTIES( frame ), "_speed" );

			// Lock during the operation
			mlt_service_lock( MLT_CONSUMER_SERVICE( consumer ) );

			// Get refresh request for the current frame
			int refresh = mlt_properties_get_int( properties, "refresh" );

			// Decrement refresh and clear changed
			mlt_events_block( properties, properties );
			mlt_properties_set_int( properties, "refresh", 0 );
			mlt_events_unblock( properties, properties );

			// Unlock after the operation
			mlt_service_unlock( MLT_CONSUMER_SERVICE( consumer ) );

			// Set the changed property on this frame for the benefit of still
			mlt_properties_set_int( MLT_FRAME_PROPERTIES( frame ), "refresh", refresh );

			// Make sure the recipient knows that this frame isn't really rendered
			mlt_properties_set_int( MLT_FRAME_PROPERTIES( frame ), "rendered", 0 );

			// Optimisation to reduce latency
			if ( speed == 1.0 )
			{
				if ( last_position != -1 && last_position + 1 != mlt_frame_get_position( frame ) )
					mlt_consumer_purge( self->play );
				last_position = mlt_frame_get_position( frame );
			}
			else
			{
				//mlt_consumer_purge( self->play );
				last_position = -1;
			}

			// If we aren't playing normally, then use the still
			if ( speed != 1 )
			{
				mlt_producer producer = MLT_PRODUCER( mlt_service_get_producer( MLT_CONSUMER_SERVICE( consumer ) ) );
				mlt_position duration = producer? mlt_producer_get_playtime( producer ) : -1;
				int pause = 0;

#ifndef SKIP_WAIT_EOS
				if ( self->active == self->play )
				{
					// Do not interrupt the play consumer near the end
					if ( duration - self->last_position > eos_threshold )
					{
						// Get a new frame at the sought position
						mlt_frame_close( frame );
						if ( producer )
							mlt_producer_seek( producer, self->last_position );
						frame = mlt_consumer_get_frame( consumer );
						pause = 1;
					}
					else
					{
						// Send frame with speed 0 to stop it
						if ( frame && !mlt_consumer_is_stopped( self->play ) )
						{
							mlt_consumer_put_frame( self->play, frame );
							frame = NULL;
							eos = 1;
						}

						// Check for end of stream
						if ( mlt_consumer_is_stopped( self->play ) )
						{
							// Stream has ended
							mlt_log_verbose( MLT_CONSUMER_SERVICE( consumer ), "END OF STREAM\n" );
							pause = 1;
							eos = 0; // reset eos indicator
						}
						else
						{
							// Prevent a tight busy loop
							struct timespec tm = { 0, 100000L }; // 100 usec
							nanosleep( &tm, NULL );
						}
					}
				}
#else
				pause = self->active == self->play;
#endif
				if ( pause )
				{
					// Start the still consumer
					if ( !mlt_consumer_is_stopped( self->play ) )
						mlt_consumer_stop( self->play );
					self->last_speed = speed;
					self->active = self->still;
					self->ignore_change = 0;
					mlt_consumer_start( self->still );
				}
				// Send the frame to the active child
				if ( frame && !eos )
				{
					mlt_properties_set_int( MLT_FRAME_PROPERTIES( frame ), "refresh", 1 );
					if ( self->active )
						mlt_consumer_put_frame( self->active, frame );
				}
				if ( pause && speed == 0.0 )
				{
					mlt_events_fire( properties, "consumer-sdl-paused", NULL );
				}
			}
			// Allow a little grace time before switching consumers on speed changes
			else if ( self->ignore_change -- > 0 && self->active != NULL && !mlt_consumer_is_stopped( self->active ) )
			{
				mlt_consumer_put_frame( self->active, frame );
			}
			// Otherwise use the normal player
			else
			{
				if ( !mlt_consumer_is_stopped( self->still ) )
					mlt_consumer_stop( self->still );
				if ( mlt_consumer_is_stopped( self->play ) )
				{
					self->last_speed = speed;
					self->active = self->play;
					self->ignore_change = 0;
					mlt_consumer_start( self->play );
				}
				if ( self->play )
					mlt_consumer_put_frame( self->play, frame );
			}

			// Copy the rectangle info from the active consumer
			if ( self->running && preview_off == 0 && self->active )
			{
				mlt_properties active = MLT_CONSUMER_PROPERTIES( self->active );
				mlt_service_lock( MLT_CONSUMER_SERVICE( consumer ) );
				mlt_properties_set_int( properties, "rect_x", mlt_properties_get_int( active, "rect_x" ) );
				mlt_properties_set_int( properties, "rect_y", mlt_properties_get_int( active, "rect_y" ) );
				mlt_properties_set_int( properties, "rect_w", mlt_properties_get_int( active, "rect_w" ) );
				mlt_properties_set_int( properties, "rect_h", mlt_properties_get_int( active, "rect_h" ) );
				mlt_service_unlock( MLT_CONSUMER_SERVICE( consumer ) );
			}

			if ( self->active == self->still )
			{
				pthread_mutex_lock( &self->refresh_mutex );
				if ( self->running && speed == 0 && self->refresh_count <= 0 )
				{
					mlt_events_fire( properties, "consumer-sdl-paused", NULL );
					pthread_cond_wait( &self->refresh_cond, &self->refresh_mutex );
				}
				self->refresh_count --;
				pthread_mutex_unlock( &self->refresh_mutex );
			}
		}
		else
		{
			if ( frame ) mlt_frame_close( frame );
			mlt_consumer_put_frame( self->active, NULL );
			self->running = 0;
		}
	}

	if ( self->play ) mlt_consumer_stop( self->play );
	if ( self->still ) mlt_consumer_stop( self->still );

	return NULL;
}
Beispiel #11
0
int main( int argc, char **argv )
{
    int i;
    mlt_consumer consumer = NULL;
    FILE *store = NULL;
    char *name = NULL;
    mlt_profile profile = NULL;
    int is_progress = 0;
    int is_silent = 0;
    mlt_profile backup_profile;

    // Handle abnormal exit situations.
    signal( SIGSEGV, abnormal_exit_handler );
    signal( SIGILL, abnormal_exit_handler );
    signal( SIGABRT, abnormal_exit_handler );

    // Construct the factory
    mlt_repository repo = mlt_factory_init( NULL );

#if defined(WIN32) && !defined(MELT_NOSDL)
    is_silent = 1;
#endif

    for ( i = 1; i < argc; i ++ )
    {
        // Check for serialisation switch
        if ( !strcmp( argv[ i ], "-serialise" ) )
        {
            name = argv[ ++ i ];
            if ( name != NULL && strstr( name, ".melt" ) )
                store = fopen( name, "w" );
            else
            {
                if ( name == NULL || name[0] == '-' )
                    store = stdout;
                name = NULL;
            }
        }
        // Look for the profile option
        else if ( !strcmp( argv[ i ], "-profile" ) )
        {
            const char *pname = argv[ ++ i ];
            if ( pname && pname[0] != '-' )
                profile = mlt_profile_init( pname );
        }
        else if ( !strcmp( argv[ i ], "-progress" ) )
        {
            is_progress = 1;
        }
        else if ( !strcmp( argv[ i ], "-progress2" ) )
        {
            is_progress = 2;
        }
        // Look for the query option
        else if ( !strcmp( argv[ i ], "-query" ) )
        {
            const char *pname = argv[ ++ i ];
            if ( pname && pname[0] != '-' )
            {
                if ( !strcmp( pname, "consumers" ) || !strcmp( pname, "consumer" ) )
                    query_services( repo, consumer_type );
                else if ( !strcmp( pname, "filters" ) || !strcmp( pname, "filter" ) )
                    query_services( repo, filter_type );
                else if ( !strcmp( pname, "producers" ) || !strcmp( pname, "producer" ) )
                    query_services( repo, producer_type );
                else if ( !strcmp( pname, "transitions" ) || !strcmp( pname, "transition" ) )
                    query_services( repo, transition_type );
                else if ( !strcmp( pname, "profiles" ) || !strcmp( pname, "profile" ) )
                    query_profiles();
                else if ( !strcmp( pname, "presets" ) || !strcmp( pname, "preset" ) )
                    query_presets();
                else if ( !strncmp( pname, "format", 6 ) )
                    query_formats();
                else if ( !strncmp( pname, "acodec", 6 ) || !strcmp( pname, "audio_codecs" ) )
                    query_acodecs();
                else if ( !strncmp( pname, "vcodec", 6 ) || !strcmp( pname, "video_codecs" ) )
                    query_vcodecs();

                else if ( !strncmp( pname, "consumer=", 9 ) )
                    query_metadata( repo, consumer_type, "consumer", strchr( pname, '=' ) + 1 );
                else if ( !strncmp( pname, "filter=", 7 ) )
                    query_metadata( repo, filter_type, "filter", strchr( pname, '=' ) + 1 );
                else if ( !strncmp( pname, "producer=", 9 ) )
                    query_metadata( repo, producer_type, "producer", strchr( pname, '=' ) + 1 );
                else if ( !strncmp( pname, "transition=", 11 ) )
                    query_metadata( repo, transition_type, "transition", strchr( pname, '=' ) + 1 );
                else if ( !strncmp( pname, "profile=", 8 ) )
                    query_profile( strchr( pname, '=' ) + 1 );
                else if ( !strncmp( pname, "preset=", 7 ) )
                    query_preset( strchr( pname, '=' ) + 1 );
                else
                    goto query_all;
            }
            else
            {
query_all:
                query_services( repo, consumer_type );
                query_services( repo, filter_type );
                query_services( repo, producer_type );
                query_services( repo, transition_type );
                fprintf( stdout, "# You can query the metadata for a specific service using:\n"
                         "# -query <type>=<identifer>\n"
                         "# where <type> is one of: consumer, filter, producer, or transition.\n" );
            }
            goto exit_factory;
        }
        else if ( !strcmp( argv[ i ], "-silent" ) )
        {
            is_silent = 1;
        }
        else if ( !strcmp( argv[ i ], "-verbose" ) )
        {
            mlt_log_set_level( MLT_LOG_VERBOSE );
        }
        else if ( !strcmp( argv[ i ], "-version" ) || !strcmp( argv[ i ], "--version" ) )
        {
            fprintf( stdout, "%s " VERSION "\n"
                     "Copyright (C) 2002-2013 Ushodaya Enterprises Limited\n"
                     "<http://www.mltframework.org/>\n"
                     "This is free software; see the source for copying conditions.  There is NO\n"
                     "warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n",
                     basename( argv[0] ) );
            goto exit_factory;
        }
        else if ( !strcmp( argv[ i ], "-debug" ) )
        {
            mlt_log_set_level( MLT_LOG_DEBUG );
        }
    }
    if ( !is_silent && !isatty( STDIN_FILENO ) && !is_progress )
        is_progress = 1;

    // Create profile if not set explicitly
    if ( getenv( "MLT_PROFILE" ) )
        profile = mlt_profile_init( NULL );
    if ( profile == NULL )
        profile = mlt_profile_init( NULL );
    else
        profile->is_explicit = 1;

    // Look for the consumer option to load profile settings from consumer properties
    backup_profile = mlt_profile_clone( profile );
    load_consumer( &consumer, profile, argc, argv );

    // If the consumer changed the profile, then it is explicit.
    if ( backup_profile && !profile->is_explicit && (
                profile->width != backup_profile->width ||
                profile->height != backup_profile->height ||
                profile->sample_aspect_num != backup_profile->sample_aspect_num ||
                profile->sample_aspect_den != backup_profile->sample_aspect_den ||
                profile->frame_rate_den != backup_profile->frame_rate_den ||
                profile->frame_rate_num != backup_profile->frame_rate_num ||
                profile->colorspace != backup_profile->colorspace ) )
        profile->is_explicit = 1;
    mlt_profile_close( backup_profile );

    // Get melt producer
    if ( argc > 1 )
        melt = mlt_factory_producer( profile, "melt", &argv[ 1 ] );

    if ( melt )
    {
        // Generate an automatic profile if needed.
        if ( ! profile->is_explicit )
        {
            mlt_profile_from_producer( profile, melt );
            mlt_producer_close( melt );
            melt = mlt_factory_producer( profile, "melt", &argv[ 1 ] );
        }

        // Reload the consumer with the fully qualified profile.
        // The producer or auto-profile could have changed the profile.
        load_consumer( &consumer, profile, argc, argv );

        // See if producer has consumer already attached
        if ( !store && !consumer )
        {
            consumer = MLT_CONSUMER( mlt_service_consumer( MLT_PRODUCER_SERVICE( melt ) ) );
            if ( consumer )
            {
                mlt_properties_inc_ref( MLT_CONSUMER_PROPERTIES(consumer) ); // because we explicitly close it
                mlt_properties_set_data( MLT_CONSUMER_PROPERTIES(consumer),
                                         "transport_callback", transport_action, 0, NULL, NULL );
            }
        }

        // If we have no consumer, default to sdl
        if ( store == NULL && consumer == NULL )
            consumer = create_consumer( profile, NULL );
    }

    // Set transport properties on consumer and produder
    if ( consumer != NULL && melt != NULL )
    {
        mlt_properties_set_data( MLT_CONSUMER_PROPERTIES( consumer ), "transport_producer", melt, 0, NULL, NULL );
        mlt_properties_set_data( MLT_PRODUCER_PROPERTIES( melt ), "transport_consumer", consumer, 0, NULL, NULL );
        if ( is_progress )
            mlt_properties_set_int(  MLT_CONSUMER_PROPERTIES( consumer ), "progress", is_progress );
        if ( is_silent )
            mlt_properties_set_int(  MLT_CONSUMER_PROPERTIES( consumer ), "silent", is_silent );
    }

    if ( argc > 1 && melt != NULL && mlt_producer_get_length( melt ) > 0 )
    {
        // Parse the arguments
        for ( i = 1; i < argc; i ++ )
        {
            if ( !strcmp( argv[ i ], "-jack" ) )
            {
                setup_jack_transport( consumer, profile );
            }
            else if ( !strcmp( argv[ i ], "-serialise" ) )
            {
                if ( store != stdout )
                    i ++;
            }
            else
            {
                if ( store != NULL )
                    fprintf( store, "%s\n", argv[ i ] );

                i ++;

                while ( argv[ i ] != NULL && argv[ i ][ 0 ] != '-' )
                {
                    if ( store != NULL )
                        fprintf( store, "%s\n", argv[ i ] );
                    i += 1;
                }

                i --;
            }
        }

        if ( consumer != NULL && store == NULL )
        {
            // Get melt's properties
            mlt_properties melt_props = MLT_PRODUCER_PROPERTIES( melt );

            // Get the last group
            mlt_properties group = mlt_properties_get_data( melt_props, "group", 0 );

            // Apply group settings
            mlt_properties properties = MLT_CONSUMER_PROPERTIES( consumer );
            mlt_properties_inherit( properties, group );

            // Connect consumer to melt
            mlt_consumer_connect( consumer, MLT_PRODUCER_SERVICE( melt ) );

            // Start the consumer
            mlt_events_listen( properties, consumer, "consumer-fatal-error", ( mlt_listener )on_fatal_error );
            if ( mlt_consumer_start( consumer ) == 0 )
            {
                // Try to exit gracefully upon these signals
                signal( SIGINT, stop_handler );
                signal( SIGTERM, stop_handler );
#ifndef WIN32
                signal( SIGHUP, stop_handler );
                signal( SIGPIPE, stop_handler );
#endif

                // Transport functionality
                transport( melt, consumer );

                // Stop the consumer
                mlt_consumer_stop( consumer );
            }
        }
        else if ( store != NULL && store != stdout && name != NULL )
        {
            fprintf( stderr, "Project saved as %s.\n", name );
            fclose( store );
        }
    }
    else
    {
        show_usage( argv[0] );
    }

    // Disconnect producer from consumer to prevent ref cycles from closing services
    if ( consumer )
    {
        mlt_consumer_connect( consumer, NULL );
        mlt_events_fire( MLT_CONSUMER_PROPERTIES(consumer), "consumer-cleanup", NULL);
    }

    // Close the producer
    if ( melt != NULL )
        mlt_producer_close( melt );

    // Close the consumer
    if ( consumer != NULL )
        mlt_consumer_close( consumer );

    // Close the factory
    mlt_profile_close( profile );

exit_factory:

// Workaround qmelt on OS X from crashing at exit.
#if !defined(__MACH__) || !defined(QT_GUI_LIB)
    mlt_factory_close( );
#endif

    return 0;
}
Beispiel #12
0
int inigo( int argc, char **argv )
{
	int i;
	mlt_consumer consumer = NULL;
	mlt_producer melt = NULL;
	FILE *store = NULL;
	char *name = NULL;
	mlt_profile profile = NULL;
	int is_progress = 0;
	int is_silent = 0;

	// Construct the factory
	mlt_repository repo = mlt_factory_init( NULL );

	for ( i = 1; i < argc; i ++ )
	{
//		fprintf(stderr, "argv[%d] = %s\n", i, argv[i]);
		
		// Check for serialisation switch
		if ( !strcmp( argv[ i ], "-serialise" ) )
		{
			name = argv[ ++ i ];
			if ( name != NULL && strstr( name, ".melt" ) )
				store = fopen( name, "w" );
			else
			{
				if ( name == NULL || name[0] == '-' )
					store = stdout;
				name = NULL;
			}
		}
		// Look for the profile option
		else if ( !strcmp( argv[ i ], "-profile" ) )
		{
			const char *pname = argv[ ++ i ];
			if ( pname && pname[0] != '-' )
				profile = mlt_profile_init( pname );
		}
		else if ( !strcmp( argv[ i ], "-progress" ) )
		{
			is_progress = 1;
		}
		// Look for the query option
		else if ( !strcmp( argv[ i ], "-query" ) )
		{
			const char *pname = argv[ ++ i ];
			if ( pname && pname[0] != '-' )
			{
				if ( !strcmp( pname, "consumers" ) || !strcmp( pname, "consumer" ) )
					query_services( repo, consumer_type );
				else if ( !strcmp( pname, "filters" ) || !strcmp( pname, "filter" ) )
					query_services( repo, filter_type );
				else if ( !strcmp( pname, "producers" ) || !strcmp( pname, "producer" ) )
					query_services( repo, producer_type );
				else if ( !strcmp( pname, "transitions" ) || !strcmp( pname, "transition" ) )
					query_services( repo, transition_type );
				
				else if ( !strncmp( pname, "consumer=", 9 ) )
					query_metadata( repo, consumer_type, "consumer", strchr( pname, '=' ) + 1 );
				else if ( !strncmp( pname, "filter=", 7 ) )
					query_metadata( repo, filter_type, "filter", strchr( pname, '=' ) + 1 );
				else if ( !strncmp( pname, "producer=", 9 ) )
					query_metadata( repo, producer_type, "producer", strchr( pname, '=' ) + 1 );
				else if ( !strncmp( pname, "transition=", 11 ) )
					query_metadata( repo, transition_type, "transition", strchr( pname, '=' ) + 1 );
				else
					goto query_all;
			}
			else
			{
query_all:
				query_services( repo, consumer_type );
				query_services( repo, filter_type );
				query_services( repo, producer_type );
				query_services( repo, transition_type );
				fprintf( stderr, "# You can query the metadata for a specific service using:\n"
					"# -query <type>=<identifer>\n"
					"# where <type> is one of: consumer, filter, producer, or transition.\n" );
			}
			goto exit_factory;
		}
		else if ( !strcmp( argv[ i ], "-silent" ) )
		{
			is_silent = 1;
		}
		else if ( !strcmp( argv[ i ], "-verbose" ) )
		{
			mlt_log_set_level( MLT_LOG_VERBOSE );
		}
		else if ( !strcmp( argv[ i ], "-version" ) || !strcmp( argv[ i ], "--version" ) )
		{
			fprintf( stderr, "MLT %s 0.5\n"
				"Copyright (C) 2002-2009 Ushodaya Enterprises Limited\n"
				"<http://www.mltframework.org/>\n"
				"This is free software; see the source for copying conditions.  There is NO\n"
				"warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n",
				basename( argv[0] ) );
			goto exit_factory;
		}
		else if ( !strcmp( argv[ i ], "-debug" ) )
		{
			mlt_log_set_level( MLT_LOG_DEBUG );
		}
	}

	// Create profile if not set explicitly
	if ( profile == NULL )
		profile = mlt_profile_init( NULL );

	// Look for the consumer option
	for ( i = 1; i < argc; i ++ )
	{
		if ( !strcmp( argv[ i ], "-consumer" ) )
		{
			consumer = create_consumer( profile, argv[ ++ i ] );
			if ( consumer )
			{
				mlt_properties properties = MLT_CONSUMER_PROPERTIES( consumer );
				while ( argv[ i + 1 ] != NULL && strstr( argv[ i + 1 ], "=" ) )
					mlt_properties_parse( properties, argv[ ++ i ] );
			}
		}
	}

	// If we have no consumer, default to sdl
	if ( store == NULL && consumer == NULL )
		consumer = create_consumer( profile, NULL );

	// Get melt producer
	if ( argc > 1 )
		melt = mlt_factory_producer( profile, "melt", &argv[ 1 ] );

	// Set transport properties on consumer and produder
	if ( consumer != NULL && melt != NULL )
	{
		mlt_properties_set_data( MLT_CONSUMER_PROPERTIES( consumer ), "transport_producer", melt, 0, NULL, NULL );
		mlt_properties_set_data( MLT_PRODUCER_PROPERTIES( melt ), "transport_consumer", consumer, 0, NULL, NULL );
		if ( is_progress )
			mlt_properties_set_int(  MLT_CONSUMER_PROPERTIES( consumer ), "progress", is_progress );
		if ( is_silent )
			mlt_properties_set_int(  MLT_CONSUMER_PROPERTIES( consumer ), "silent", is_silent );
	}

	if ( argc > 1 && melt != NULL && mlt_producer_get_length( melt ) > 0 )
	{
		// Parse the arguments
		for ( i = 1; i < argc; i ++ )
		{
			if ( !strcmp( argv[ i ], "-serialise" ) )
			{
				if ( store != stdout )
					i ++;
			}
			else
			{
				if ( store != NULL )
					fprintf( store, "%s\n", argv[ i ] );

				i ++;

				while ( argv[ i ] != NULL && argv[ i ][ 0 ] != '-' )
				{
					if ( store != NULL )
						fprintf( store, "%s\n", argv[ i ] );
					i += 1;
				}

				i --;
			}
		}

		if ( consumer != NULL && store == NULL )
		{
			// Get melt's properties
			mlt_properties melt_props = MLT_PRODUCER_PROPERTIES( melt );
	
			// Get the last group
			mlt_properties group = mlt_properties_get_data( melt_props, "group", 0 );
	
			// Apply group settings
			mlt_properties properties = MLT_CONSUMER_PROPERTIES( consumer );
			mlt_properties_inherit( properties, group );

			// Connect consumer to melt
			mlt_consumer_connect( consumer, MLT_PRODUCER_SERVICE( melt ) );

			// Start the consumer
			mlt_consumer_start( consumer );

			// Transport functionality
			transport( melt, consumer );

			// Stop the consumer
			mlt_consumer_stop( consumer );
		}
		else if ( store != NULL && store != stdout && name != NULL )
		{
			fprintf( stderr, "Project saved as %s.\n", name );
			fclose( store );
		}
	}
	else
	{
		fprintf( stderr,
"Usage: %s [options] [producer [name=value]* ]+\n"
"Options:\n"
"  -attach filter[:arg] [name=value]*       Attach a filter to the output\n"
"  -attach-cut filter[:arg] [name=value]*   Attach a filter to a cut\n"
"  -attach-track filter[:arg] [name=value]* Attach a filter to a track\n"
"  -attach-clip filter[:arg] [name=value]*  Attach a filter to a producer\n"
"  -audio-track | -hide-video               Add an audio-only track\n"
"  -blank frames                            Add blank silence to a track\n"
"  -consumer id[:arg] [name=value]*         Set the consumer (sink)\n"
"  -debug                                   Set the logging level to debug\n"
"  -filter filter[:arg] [name=value]*       Add a filter to the current track\n"
"  -group [name=value]*                     Apply properties repeatedly\n"
"  -help                                    Show this message\n"
"  -join clips                              Join multiple clips into one cut\n"
"  -mix length                              Add a mix between the last two cuts\n"
"  -mixer transition                        Add a transition to the mix\n"
"  -null-track | -hide-track                Add a hidden track\n"
"  -profile name                            Set the processing settings\n"
"  -progress                                Display progress along with position\n"
"  -remove                                  Remove the most recent cut\n"
"  -repeat times                            Repeat the last cut\n"
"  -query                                   List all of the registered services\n"
"  -query \"consumers\" | \"consumer\"=id       List consumers or show info about one\n"
"  -query \"filters\" | \"filter\"=id           List filters or show info about one\n"
"  -query \"producers\" | \"producer\"=id       List producers or show info about one\n"
"  -query \"transitions\" | \"transition\"=id   List transitions, show info about one\n"
"  -serialise [filename]                    Write the commands to a text file\n"
"  -silent                                  Do not display position/transport\n"
"  -split relative-frame                    Split the last cut into two cuts\n"
"  -swap                                    Rearrange the last two cuts\n"
"  -track                                   Add a track\n"
"  -transition id[:arg] [name=value]*       Add a transition\n"
"  -verbose                                 Set the logging level to verbose\n"
"  -version                                 Show the version and copyright\n"
"  -video-track | -hide-audio               Add a video-only track\n"
"For more help: <http://www.mltframework.org/>\n",
		basename( argv[0] ) );
	}

	// Close the producer
	if ( melt != NULL )
		mlt_producer_close( melt );

	// Close the consumer
	if ( consumer != NULL )
		mlt_consumer_close( consumer );

	// Close the factory
	mlt_profile_close( profile );

exit_factory:
		
	mlt_factory_close( );

	return 0;
}
Beispiel #13
0
static void on_fatal_error( mlt_properties owner, mlt_consumer consumer )
{
	mlt_consumer_stop( consumer );
	exit( EXIT_FAILURE );
}