return consumer;
}
-static void load_consumer( mlt_consumer &consumer, int argc, const char **argv )
+static void load_consumer( mlt_consumer *consumer, mlt_profile profile, int argc, char **argv )
{
int i;
for ( i = 1; i < argc; i ++ )
}
else
{
- fprintf( stderr, "Current Position: %10d\r", (int)mlt_producer_position( producer ) );
+ fprintf( stderr, "Current Position: %10d\r", (int)mlt_consumer_position( consumer ) );
}
}
}
}
+static void show_usage( char *program_name )
+{
+ 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( program_name ) );
+}
+
static void guess_profile( mlt_producer melt, mlt_profile profile )
{
mlt_frame fr = NULL;
mlt_frame_close( fr );
mlt_service_get_frame( MLT_PRODUCER_SERVICE(melt), &fr, 0 );
p = MLT_FRAME_PROPERTIES( fr );
- if ( mlt_properties_get_int( p, "meta.media.width" ) )
+// 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;
}
}
}
FILE *store = NULL;
char *name = NULL;
mlt_profile profile = NULL;
- mlt_profile backup_profile = NULL;
int is_progress = 0;
int is_silent = 0;
- int is_profile_explicit = 0;
+ mlt_profile backup_profile;
// Construct the factory
mlt_repository repo = mlt_factory_init( NULL );
if ( profile == NULL )
profile = mlt_profile_init( NULL );
else
- is_profile_explicit = 1;
+ profile->is_explicit = 1;
// Look for the consumer option to load profile settings from consumer properties
- load_consumer( &consumer, argc, argv );
-
- // Make backup of profile for determining if we need to use 'consumer' producer.
- backup_profile = mlt_profile_init( NULL );
- memcpy( backup_profile, profile, sizeof( struct mlt_profile_s ) );
- backup_profile->description = strdup( "" );
+ 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 )
if ( melt )
{
- // If the producer changed the profile then do not try to guess it.
- if ( 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 )
- {
- if ( is_profile_explicit )
- {
- // We need to use the 'consumer' producer.
- mlt_producer_close( melt );
- mlt_profile_close( profile );
- profile = backup_profile;
- backup_profile = NULL;
- if ( profile->description )
- free( profile->description );
- // This is a hack to signal create_producer() in producer_melt.c.
- profile->description = strdup( "consumer:" );
- melt = mlt_factory_producer( profile, "melt", &argv[ 1 ] );
- }
- }
- else if ( ! is_profile_explicit )
+ // Generate an automatic profile if needed.
+ if ( ! profile->is_explicit )
{
guess_profile( melt, profile );
+ mlt_producer_close( melt );
+ melt = mlt_factory_producer( profile, "melt", &argv[ 1 ] );
}
-
- // Reload the consumer with the fully qualified profile
- load_consumer( consumer, argc, argv );
+
+ // Reload the consumer with the fully qualified profile.
+ // The producer or guess_profile could have changed the profile.
+ load_consumer( &consumer, profile, argc, argv );
// If we have no consumer, default to sdl
if ( store == NULL && consumer == NULL )
}
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] ) );
+ show_usage( argv[0] );
}
// Close the producer
// Close the factory
mlt_profile_close( profile );
- mlt_profile_close( backup_profile );
exit_factory: