--- /dev/null
+Producers
+---------
+
+ ffmpeg
+
+ Description:
+
+ Test case pipe based producer for video and audio.
+
+ Constructor argument:
+
+ 'file' - produce a/v from file
+ v4l - produce a/v from video4linux and dsp device
+
+ Initialisation Properties
+
+ string video_type - "file" or "v4l"
+ string video_file - file or v4l device
+ string video_size - WxH of video to produce (default: "")
+ int video_loop - loop video until audio exhausted (default: 0)
+ string audio_type - "file" or "dsp"
+ string audio_file - file or dsp device
+ int audio_rate - audio frequency (default: 48000)
+ int audio_channels - audio channels (default: 2)
+ int audio_track - audio track to use (default: 0)
+ int audio_loop - loop audio until video exhausted (default: 0)
+ timecode in - in point
+ timecode out - out point
+ double fps - output frames per second (default: 25)
+
+ Read Only Properties
+
+ end_of_clip - holds 1 when input is exhausted
+
+ Dependencies
+
+ ffmpeg executable.
+
+ Known Bugs
+
+ in/out point setting is broken.
+
+ Implementation does not allow fast random access.
+
+ libdv
+
+ Description:
+
+ libdv based decoder for video and audio.
+
+ Constructor argument:
+
+ 'file' - produce a/v from file
+
+ Initialisation Properties
+
+ string file - file location
+ timecode in - in point
+ timecode out - out point
+
+ Read Only Properties
+
+ double fps - output frames per second
+
+ Dependencies
+
+ libdv.
+
+ Known Bugs
+
+ 'file' is not populated on properties?
+
+ mcdv
+ mcmpeg
+ pango
+ pixbuf
+ ppm
+
+
+Filters
+-------
+
+ deinterlace
+ ffmpeg_dub
+ gamma
+ greyscale
+ resize
+
+Transitions
+-----------
+
+ composite
+
+Consumers
+---------
+
+ bluefish
+ sdl
+
--- /dev/null
+Producers
+---------
+
+ ffmpeg
+
+ Description:
+
+ Test case pipe based producer for video and audio.
+
+ Constructor argument:
+
+ 'file' - produce a/v from file
+ v4l - produce a/v from video4linux and dsp device
+
+ Initialisation Properties
+
+ string video_type - "file" or "v4l"
+ string video_file - file or v4l device
+ string video_size - WxH of video to produce (default: "")
+ int video_loop - loop video until audio exhausted (default: 0)
+ string audio_type - "file" or "dsp"
+ string audio_file - file or dsp device
+ int audio_rate - audio frequency (default: 48000)
+ int audio_channels - audio channels (default: 2)
+ int audio_track - audio track to use (default: 0)
+ int audio_loop - loop audio until video exhausted (default: 0)
+ timecode in - in point
+ timecode out - out point
+ double fps - output frames per second (default: 25)
+
+ Read Only Properties
+
+ end_of_clip - holds 1 when input is exhausted
+
+ Dependencies
+
+ ffmpeg executable.
+
+ Known Bugs
+
+ in/out point setting is broken.
+
+ Implementation does not allow fast random access.
+
+ libdv
+
+ Description:
+
+ libdv based decoder for video and audio.
+
+ Constructor argument:
+
+ 'file' - produce a/v from file
+
+ Initialisation Properties
+
+ string file - file location
+ timecode in - in point
+ timecode out - out point
+
+ Read Only Properties
+
+ double fps - output frames per second
+
+ Dependencies
+
+ libdv.
+
+ Known Bugs
+
+ 'file' is not populated on properties?
+
+ mcdv
+ mcmpeg
+ pango
+ pixbuf
+ ppm
+
+
+Filters
+-------
+
+ deinterlace
+ ffmpeg_dub
+ gamma
+ greyscale
+ resize
+
+Transitions
+-----------
+
+ composite
+
+Consumers
+---------
+
+ bluefish
+ sdl
+
#include "mlt_properties.h"
#include <stdlib.h>
+#include <string.h>
/** Singleton repositories
*/
+static char *mlt_prefix = NULL;
static mlt_properties object_list = NULL;
static mlt_repository producers = NULL;
static mlt_repository filters = NULL;
if ( prefix == NULL )
prefix = PREFIX_DATA;
+ // Store the prefix for later retrieval
+ mlt_prefix = strdup( prefix );
+
// Create the object list.
object_list = calloc( sizeof( struct mlt_properties_s ), 1 );
mlt_properties_init( object_list, NULL );
return 0;
}
+/** Fetch the prefix used in this instance.
+*/
+
+const char *mlt_factory_prefix( )
+{
+ return mlt_prefix;
+}
+
/** Fetch a producer from the repository.
*/
mlt_repository_close( transitions );
mlt_repository_close( consumers );
mlt_properties_close( object_list );
+ free( mlt_prefix );
free( object_list );
}
#include "mlt_types.h"
extern int mlt_factory_init( char *prefix );
+extern const char *mlt_factory_prefix( );
extern mlt_producer mlt_factory_producer( char *name, void *input );
extern mlt_filter mlt_factory_filter( char *name, void *input );
extern mlt_transition mlt_factory_transition( char *name, void *input );
mlt_properties_set_timecode( properties, "length", length );
mlt_properties_set_timecode( properties, "out", length );
mlt_properties_set_timecode( properties, "playtime", length - mlt_properties_get_timecode( properties, "in" ) );
+ mlt_properties_set_double( properties, "fps", fps );
}
/** Connect a producer to a given track.
mlt_producer_prepare_next( this );
}
+ // Copy the fps of the producer onto the frame
+ mlt_properties properties = mlt_frame_properties( *frame );
+ mlt_properties_set_double( properties, "fps", mlt_producer_get_fps( this ) );
+
return 0;
}
--- /dev/null
+#!/bin/bash
+
+audio_type="$1"
+audio_file="$2"
+audio_position=$3
+audio_frequency=$4
+audio_channels=$5
+audio_track=$5
+
+if [ "$audio_type" == "dsp" ]
+then ffmpeg -ad "$audio_file" -f s16le -ar $audio_frequency -ac $audio_channels -
+else ffmpeg -i "$audio_file" -ss $audio_position -f s16le -ar $audio_frequency -ac $audio_channels -
+fi
+
mlt_properties producer_properties = mlt_producer_properties( producer );
// Get the original get_audio
- int ( *get_audio )( mlt_frame, int16_t **, mlt_audio_format *, int *, int *, int * ) = mlt_properties_get_data( frame_properties, "get_audio", NULL );
+ frame->get_audio = mlt_properties_get_data( frame_properties, "get_audio", NULL );
// Call the original get_audio
- get_audio( frame, buffer, format, frequency, channels, samples );
+ mlt_frame_get_audio( frame, buffer, format, frequency, channels, samples );
// Now if our producer is still producing, override the audio
if ( !mlt_properties_get_int( producer_properties, "end_of_clip" ) )
// We need a frame from the producer
mlt_frame producer_frame;
+ // Set the FPS
+ mlt_properties_set_double( producer_properties, "fps", mlt_properties_get_double( frame_properties, "fps" ) );
+
// Seek to the position
mlt_producer_seek_frame( producer, ( int64_t )position );
// Obtain the frame properties
mlt_properties frame_properties = mlt_frame_properties( frame );
- // Backup the original get_audio (it's still needed)
- mlt_properties_set_data( frame_properties, "get_audio", frame->get_audio, 0, NULL, NULL );
+ // Get the producer properties
+ mlt_properties producer_properties = mlt_producer_properties( producer );
- // Pass the producer on the frame
- mlt_properties_set_data( frame_properties, "producer", producer, 0, NULL, NULL );
+ // Only do this if we have not reached end of clip and ffmpeg_dub has not already been done
+ if ( !mlt_properties_get_int( producer_properties, "end_of_clip" ) &&
+ mlt_properties_get_data( frame_properties, "get_audio", NULL ) == NULL )
+ {
+ // Backup the original get_audio (it's still needed)
+ mlt_properties_set_data( frame_properties, "get_audio", frame->get_audio, 0, NULL, NULL );
+
+ // Pass the producer on the frame
+ mlt_properties_set_data( frame_properties, "producer", producer, 0, NULL, NULL );
- // Override the get_audio method
- frame->get_audio = filter_get_audio;
+ // Override the get_audio method
+ frame->get_audio = filter_get_audio;
+ }
return frame;
}
*/
#include "producer_ffmpeg.h"
+
#include <framework/mlt_frame.h>
+#include <framework/mlt_factory.h>
+
+#include <stdio.h>
#include <stdlib.h>
#include <string.h>
// Set the properties
mlt_properties_set( properties, "mlt_type", "producer_ffmpeg" );
- mlt_properties_set_int( properties, "known_length", 0 );
- mlt_properties_set( properties, "video_type", file );
+
if ( file != NULL && !strcmp( file, "v4l" ) )
{
+ mlt_properties_set( properties, "video_type", "v4l" );
mlt_properties_set( properties, "video_file", "/dev/video0" );
+ mlt_properties_set( properties, "video_size", "640x480" );
+ mlt_properties_set( properties, "audio_type", "dsp" );
mlt_properties_set( properties, "audio_file", "/dev/dsp" );
}
else
{
+ mlt_properties_set( properties, "video_type", "file" );
mlt_properties_set( properties, "video_file", file );
+ mlt_properties_set( properties, "video_size", "" );
+ mlt_properties_set( properties, "audio_type", "file" );
mlt_properties_set( properties, "audio_file", file );
}
+ mlt_properties_set_int( properties, "audio_rate", 48000 );
+ mlt_properties_set_int( properties, "audio_channels", 2 );
+ mlt_properties_set_int( properties, "audio_track", 0 );
+
this->buffer = malloc( 1024 * 1024 * 2 );
return producer;
FILE *producer_ffmpeg_run_video( producer_ffmpeg this )
{
- // Get the producer
- mlt_producer producer = &this->parent;
+ if ( this->video == NULL )
+ {
+ // Get the producer
+ mlt_producer producer = &this->parent;
- // Get the properties of the producer
- mlt_properties properties = mlt_producer_properties( producer );
+ // Get the properties of the producer
+ mlt_properties properties = mlt_producer_properties( producer );
- char *video_type = mlt_properties_get( properties, "video_type" );
- char *video_file = mlt_properties_get( properties, "video_file" );
- int video_loop = mlt_properties_get_int( properties, "video_loop" );
+ // Get the video loop property
+ int video_loop = mlt_properties_get_int( properties, "video_loop" );
- if ( this->video == NULL )
- {
if ( !this->open || video_loop )
{
+ const char *mlt_prefix = mlt_factory_prefix( );
+ char *video_type = mlt_properties_get( properties, "video_type" );
+ char *video_file = mlt_properties_get( properties, "video_file" );
+ float video_rate = mlt_properties_get_double( properties, "fps" );
+ char *video_size = mlt_properties_get( properties, "video_size" );
char command[ 1024 ] = "";
- float fps = mlt_producer_get_fps( &this->parent );
float position = mlt_producer_position( &this->parent );
if ( video_loop ) position = 0;
- if ( video_type != NULL && !strcmp( video_type, "v4l" ) )
- sprintf( command, "ffmpeg -r %f -s 640x480 -vd \"%s\" -f imagepipe -f yuv4mpegpipe - 2>/dev/null", fps, video_file );
- else if ( video_file != NULL && strcmp( video_file, "" ) )
- sprintf( command, "ffmpeg -i \"%s\" -ss %f -f imagepipe -r %f -f yuv4mpegpipe - 2>/dev/null", video_file, position, fps );
+ sprintf( command, "%s/ffmpeg/video.sh \"%s\" \"%s\" \"%s\" %f %f 2>/dev/null",
+ mlt_prefix,
+ video_type,
+ video_file,
+ video_size,
+ video_rate,
+ position );
- if ( strcmp( command, "" ) )
- this->video = popen( command, "r" );
+ this->video = popen( command, "r" );
}
}
return this->video;
// Get the properties of the producer
mlt_properties properties = mlt_producer_properties( producer );
- char *video_type = mlt_properties_get( properties, "video_type" );
- char *audio_file = mlt_properties_get( properties, "audio_file" );
- int audio_loop = mlt_properties_get_int( properties, "audio_loop" );
-
if ( this->audio == NULL )
{
+ int audio_loop = mlt_properties_get_int( properties, "audio_loop" );
+
if ( !this->open || audio_loop )
{
+ const char *mlt_prefix = mlt_factory_prefix( );
+ char *audio_type = mlt_properties_get( properties, "audio_type" );
+ char *audio_file = mlt_properties_get( properties, "audio_file" );
+ int frequency = mlt_properties_get_int( properties, "audio_rate" );
+ int channels = mlt_properties_get_int( properties, "audio_channels" );
+ int track = mlt_properties_get_int( properties, "audio_track" );
char command[ 1024 ] = "";
float position = mlt_producer_position( &this->parent );
if ( audio_loop ) position = 0;
- if ( video_type != NULL && !strcmp( video_type, "v4l" ) )
- sprintf( command, "ffmpeg -ad \"%s\" -f s16le -ar 48000 -ac 2 - 2>/dev/null", audio_file );
- else if ( audio_file != NULL )
- sprintf( command, "ffmpeg -i \"%s\" -ss %f -f s16le -ar 48000 -ac 2 - 2>/dev/null", audio_file, position );
+ sprintf( command, "%s/ffmpeg/audio.sh \"%s\" \"%s\" %f %d %d %d 2>/dev/null",
+ mlt_prefix,
+ audio_type,
+ audio_file,
+ position,
+ frequency,
+ channels,
+ track );
- if ( strcmp( command, "" ) )
- this->audio = popen( command, "r" );
+ this->audio = popen( command, "r" );
}
}
return this->audio;
this->open = 1;
}
+static int sample_calculator( float fps, int frequency, int64_t position )
+{
+ int samples = 0;
+
+ if ( fps == 25 )
+ {
+ samples = frequency / 25;
+ }
+ else if ( fps >= 29.97 && fps < 29.98 )
+ {
+ samples = frequency / 30;
+
+ switch ( frequency )
+ {
+ case 48000:
+ if ( position % 5 != 0 )
+ samples += 2;
+ break;
+ case 44100:
+ if ( position % 300 == 0 )
+ samples = 1471;
+ else if ( position % 30 == 0 )
+ samples = 1470;
+ else if ( position % 2 == 0 )
+ samples = 1472;
+ else
+ samples = 1471;
+ break;
+ case 32000:
+ if ( position % 30 == 0 )
+ samples = 1068;
+ else if ( position % 29 == 0 )
+ samples = 1067;
+ else if ( position % 4 == 2 )
+ samples = 1067;
+ else
+ samples = 1068;
+ break;
+ default:
+ samples = 0;
+ }
+ }
+ else
+ {
+ if ( fps != 0 )
+ samples = frequency / fps;
+ }
+
+ return samples;
+}
+
static int producer_get_audio( mlt_frame this, int16_t **buffer, mlt_audio_format *format, int *frequency, int *channels, int *samples )
{
// Get the frames properties
producer_ffmpeg producer = mlt_properties_get_data( properties, "producer_ffmpeg", NULL );
mlt_properties producer_properties = mlt_producer_properties( &producer->parent );
+ int64_t target = mlt_properties_get_double( properties, "target" );
int skip = mlt_properties_get_int( properties, "skip" );
- *frequency = 48000;
- *channels = 2;
- *samples = 1920;
+ float fps = mlt_properties_get_double( producer_properties, "fps" );
+ *frequency = mlt_properties_get_int( producer_properties, "audio_rate" );
+ *channels = mlt_properties_get_int( producer_properties, "audio_channels" );
- // Size
- int size = *samples * *channels * 2;
+ // Maximum Size (?)
+ int size = ( *frequency / 25 ) * *channels * 2;
// Allocate an image
*buffer = malloc( size );
{
do
{
- if ( fread( *buffer, size, 1, producer->audio ) != 1 )
+ *samples = sample_calculator( fps, *frequency, target - skip );
+ if ( fread( *buffer, *samples * *channels * 2, 1, producer->audio ) != 1 )
{
pclose( producer->audio );
producer->audio = NULL;
}
else
{
+ *samples = sample_calculator( fps, *frequency, target );
memset( *buffer, 0, size );
}
// Are we at the position expected?
producer_ffmpeg_position( this, mlt_producer_frame( producer ), &skip );
+ // Get properties objects
+ mlt_properties producer_properties = mlt_producer_properties( &this->parent );
+
// Get the frames properties
mlt_properties properties = mlt_frame_properties( *frame );
FILE *video = this->video;
+ mlt_properties_set_double( properties, "target", mlt_producer_frame( producer ) );
mlt_properties_set_int( properties, "skip", skip );
// Read the video
// Clean up
if ( this->video != NULL )
{
+ int video_loop = mlt_properties_get_int( producer_properties, "video_loop" );
+
// Inform caller that end of clip is reached
- this->end_of_video = 1;
+ this->end_of_video = !video_loop;
pclose( this->video );
this->video = NULL;
}
// Hmm - register audio callback
( *frame )->get_audio = producer_get_audio;
- // Get properties objects
- mlt_properties producer_properties = mlt_producer_properties( &this->parent );
-
// Get the additional properties
double aspect_ratio = mlt_properties_get_double( producer_properties, "aspect_ratio" );
double speed = mlt_properties_get_double( producer_properties, "speed" );
* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
-#ifndef _PRODUCER_Y4M_H_
-#define _PRODUCER_Y4M_H_
+#ifndef _PRODUCER_FFMPEG_H_
+#define _PRODUCER_FFMPEG_H_
#include <framework/mlt_producer.h>
-#include <stdio.h>
extern mlt_producer producer_ffmpeg_init( char *file );
--- /dev/null
+#!/bin/bash
+
+video_type="$1"
+video_file="$2"
+video_size="$3"
+video_fps=$4
+video_position=$5
+
+[ "$video_size" != "" ] && video_size="-s "$video_size
+
+if [ "$video_type" == "v4l" ]
+then ffmpeg -vd "$video_file" -r $video_fps $video_size -f imagepipe -f yuv4mpegpipe -
+else ffmpeg -i "$video_file" -ss $video_position -f imagepipe -r $video_fps $video_size -f yuv4mpegpipe -
+fi
#include "mlt_properties.h"
#include <stdlib.h>
+#include <string.h>
/** Singleton repositories
*/
+static char *mlt_prefix = NULL;
static mlt_properties object_list = NULL;
static mlt_repository producers = NULL;
static mlt_repository filters = NULL;
if ( prefix == NULL )
prefix = PREFIX_DATA;
+ // Store the prefix for later retrieval
+ mlt_prefix = strdup( prefix );
+
// Create the object list.
object_list = calloc( sizeof( struct mlt_properties_s ), 1 );
mlt_properties_init( object_list, NULL );
return 0;
}
+/** Fetch the prefix used in this instance.
+*/
+
+const char *mlt_factory_prefix( )
+{
+ return mlt_prefix;
+}
+
/** Fetch a producer from the repository.
*/
mlt_repository_close( transitions );
mlt_repository_close( consumers );
mlt_properties_close( object_list );
+ free( mlt_prefix );
free( object_list );
}
#include "mlt_types.h"
extern int mlt_factory_init( char *prefix );
+extern const char *mlt_factory_prefix( );
extern mlt_producer mlt_factory_producer( char *name, void *input );
extern mlt_filter mlt_factory_filter( char *name, void *input );
extern mlt_transition mlt_factory_transition( char *name, void *input );
mlt_properties_set_timecode( properties, "length", length );
mlt_properties_set_timecode( properties, "out", length );
mlt_properties_set_timecode( properties, "playtime", length - mlt_properties_get_timecode( properties, "in" ) );
+ mlt_properties_set_double( properties, "fps", fps );
}
/** Connect a producer to a given track.
mlt_producer_prepare_next( this );
}
+ // Copy the fps of the producer onto the frame
+ mlt_properties properties = mlt_frame_properties( *frame );
+ mlt_properties_set_double( properties, "fps", mlt_producer_get_fps( this ) );
+
return 0;
}
--- /dev/null
+#!/bin/bash
+
+audio_type="$1"
+audio_file="$2"
+audio_position=$3
+audio_frequency=$4
+audio_channels=$5
+audio_track=$5
+
+if [ "$audio_type" == "dsp" ]
+then ffmpeg -ad "$audio_file" -f s16le -ar $audio_frequency -ac $audio_channels -
+else ffmpeg -i "$audio_file" -ss $audio_position -f s16le -ar $audio_frequency -ac $audio_channels -
+fi
+
mlt_properties producer_properties = mlt_producer_properties( producer );
// Get the original get_audio
- int ( *get_audio )( mlt_frame, int16_t **, mlt_audio_format *, int *, int *, int * ) = mlt_properties_get_data( frame_properties, "get_audio", NULL );
+ frame->get_audio = mlt_properties_get_data( frame_properties, "get_audio", NULL );
// Call the original get_audio
- get_audio( frame, buffer, format, frequency, channels, samples );
+ mlt_frame_get_audio( frame, buffer, format, frequency, channels, samples );
// Now if our producer is still producing, override the audio
if ( !mlt_properties_get_int( producer_properties, "end_of_clip" ) )
// We need a frame from the producer
mlt_frame producer_frame;
+ // Set the FPS
+ mlt_properties_set_double( producer_properties, "fps", mlt_properties_get_double( frame_properties, "fps" ) );
+
// Seek to the position
mlt_producer_seek_frame( producer, ( int64_t )position );
// Obtain the frame properties
mlt_properties frame_properties = mlt_frame_properties( frame );
- // Backup the original get_audio (it's still needed)
- mlt_properties_set_data( frame_properties, "get_audio", frame->get_audio, 0, NULL, NULL );
+ // Get the producer properties
+ mlt_properties producer_properties = mlt_producer_properties( producer );
- // Pass the producer on the frame
- mlt_properties_set_data( frame_properties, "producer", producer, 0, NULL, NULL );
+ // Only do this if we have not reached end of clip and ffmpeg_dub has not already been done
+ if ( !mlt_properties_get_int( producer_properties, "end_of_clip" ) &&
+ mlt_properties_get_data( frame_properties, "get_audio", NULL ) == NULL )
+ {
+ // Backup the original get_audio (it's still needed)
+ mlt_properties_set_data( frame_properties, "get_audio", frame->get_audio, 0, NULL, NULL );
+
+ // Pass the producer on the frame
+ mlt_properties_set_data( frame_properties, "producer", producer, 0, NULL, NULL );
- // Override the get_audio method
- frame->get_audio = filter_get_audio;
+ // Override the get_audio method
+ frame->get_audio = filter_get_audio;
+ }
return frame;
}
*/
#include "producer_ffmpeg.h"
+
#include <framework/mlt_frame.h>
+#include <framework/mlt_factory.h>
+
+#include <stdio.h>
#include <stdlib.h>
#include <string.h>
// Set the properties
mlt_properties_set( properties, "mlt_type", "producer_ffmpeg" );
- mlt_properties_set_int( properties, "known_length", 0 );
- mlt_properties_set( properties, "video_type", file );
+
if ( file != NULL && !strcmp( file, "v4l" ) )
{
+ mlt_properties_set( properties, "video_type", "v4l" );
mlt_properties_set( properties, "video_file", "/dev/video0" );
+ mlt_properties_set( properties, "video_size", "640x480" );
+ mlt_properties_set( properties, "audio_type", "dsp" );
mlt_properties_set( properties, "audio_file", "/dev/dsp" );
}
else
{
+ mlt_properties_set( properties, "video_type", "file" );
mlt_properties_set( properties, "video_file", file );
+ mlt_properties_set( properties, "video_size", "" );
+ mlt_properties_set( properties, "audio_type", "file" );
mlt_properties_set( properties, "audio_file", file );
}
+ mlt_properties_set_int( properties, "audio_rate", 48000 );
+ mlt_properties_set_int( properties, "audio_channels", 2 );
+ mlt_properties_set_int( properties, "audio_track", 0 );
+
this->buffer = malloc( 1024 * 1024 * 2 );
return producer;
FILE *producer_ffmpeg_run_video( producer_ffmpeg this )
{
- // Get the producer
- mlt_producer producer = &this->parent;
+ if ( this->video == NULL )
+ {
+ // Get the producer
+ mlt_producer producer = &this->parent;
- // Get the properties of the producer
- mlt_properties properties = mlt_producer_properties( producer );
+ // Get the properties of the producer
+ mlt_properties properties = mlt_producer_properties( producer );
- char *video_type = mlt_properties_get( properties, "video_type" );
- char *video_file = mlt_properties_get( properties, "video_file" );
- int video_loop = mlt_properties_get_int( properties, "video_loop" );
+ // Get the video loop property
+ int video_loop = mlt_properties_get_int( properties, "video_loop" );
- if ( this->video == NULL )
- {
if ( !this->open || video_loop )
{
+ const char *mlt_prefix = mlt_factory_prefix( );
+ char *video_type = mlt_properties_get( properties, "video_type" );
+ char *video_file = mlt_properties_get( properties, "video_file" );
+ float video_rate = mlt_properties_get_double( properties, "fps" );
+ char *video_size = mlt_properties_get( properties, "video_size" );
char command[ 1024 ] = "";
- float fps = mlt_producer_get_fps( &this->parent );
float position = mlt_producer_position( &this->parent );
if ( video_loop ) position = 0;
- if ( video_type != NULL && !strcmp( video_type, "v4l" ) )
- sprintf( command, "ffmpeg -r %f -s 640x480 -vd \"%s\" -f imagepipe -f yuv4mpegpipe - 2>/dev/null", fps, video_file );
- else if ( video_file != NULL && strcmp( video_file, "" ) )
- sprintf( command, "ffmpeg -i \"%s\" -ss %f -f imagepipe -r %f -f yuv4mpegpipe - 2>/dev/null", video_file, position, fps );
+ sprintf( command, "%s/ffmpeg/video.sh \"%s\" \"%s\" \"%s\" %f %f 2>/dev/null",
+ mlt_prefix,
+ video_type,
+ video_file,
+ video_size,
+ video_rate,
+ position );
- if ( strcmp( command, "" ) )
- this->video = popen( command, "r" );
+ this->video = popen( command, "r" );
}
}
return this->video;
// Get the properties of the producer
mlt_properties properties = mlt_producer_properties( producer );
- char *video_type = mlt_properties_get( properties, "video_type" );
- char *audio_file = mlt_properties_get( properties, "audio_file" );
- int audio_loop = mlt_properties_get_int( properties, "audio_loop" );
-
if ( this->audio == NULL )
{
+ int audio_loop = mlt_properties_get_int( properties, "audio_loop" );
+
if ( !this->open || audio_loop )
{
+ const char *mlt_prefix = mlt_factory_prefix( );
+ char *audio_type = mlt_properties_get( properties, "audio_type" );
+ char *audio_file = mlt_properties_get( properties, "audio_file" );
+ int frequency = mlt_properties_get_int( properties, "audio_rate" );
+ int channels = mlt_properties_get_int( properties, "audio_channels" );
+ int track = mlt_properties_get_int( properties, "audio_track" );
char command[ 1024 ] = "";
float position = mlt_producer_position( &this->parent );
if ( audio_loop ) position = 0;
- if ( video_type != NULL && !strcmp( video_type, "v4l" ) )
- sprintf( command, "ffmpeg -ad \"%s\" -f s16le -ar 48000 -ac 2 - 2>/dev/null", audio_file );
- else if ( audio_file != NULL )
- sprintf( command, "ffmpeg -i \"%s\" -ss %f -f s16le -ar 48000 -ac 2 - 2>/dev/null", audio_file, position );
+ sprintf( command, "%s/ffmpeg/audio.sh \"%s\" \"%s\" %f %d %d %d 2>/dev/null",
+ mlt_prefix,
+ audio_type,
+ audio_file,
+ position,
+ frequency,
+ channels,
+ track );
- if ( strcmp( command, "" ) )
- this->audio = popen( command, "r" );
+ this->audio = popen( command, "r" );
}
}
return this->audio;
this->open = 1;
}
+static int sample_calculator( float fps, int frequency, int64_t position )
+{
+ int samples = 0;
+
+ if ( fps == 25 )
+ {
+ samples = frequency / 25;
+ }
+ else if ( fps >= 29.97 && fps < 29.98 )
+ {
+ samples = frequency / 30;
+
+ switch ( frequency )
+ {
+ case 48000:
+ if ( position % 5 != 0 )
+ samples += 2;
+ break;
+ case 44100:
+ if ( position % 300 == 0 )
+ samples = 1471;
+ else if ( position % 30 == 0 )
+ samples = 1470;
+ else if ( position % 2 == 0 )
+ samples = 1472;
+ else
+ samples = 1471;
+ break;
+ case 32000:
+ if ( position % 30 == 0 )
+ samples = 1068;
+ else if ( position % 29 == 0 )
+ samples = 1067;
+ else if ( position % 4 == 2 )
+ samples = 1067;
+ else
+ samples = 1068;
+ break;
+ default:
+ samples = 0;
+ }
+ }
+ else
+ {
+ if ( fps != 0 )
+ samples = frequency / fps;
+ }
+
+ return samples;
+}
+
static int producer_get_audio( mlt_frame this, int16_t **buffer, mlt_audio_format *format, int *frequency, int *channels, int *samples )
{
// Get the frames properties
producer_ffmpeg producer = mlt_properties_get_data( properties, "producer_ffmpeg", NULL );
mlt_properties producer_properties = mlt_producer_properties( &producer->parent );
+ int64_t target = mlt_properties_get_double( properties, "target" );
int skip = mlt_properties_get_int( properties, "skip" );
- *frequency = 48000;
- *channels = 2;
- *samples = 1920;
+ float fps = mlt_properties_get_double( producer_properties, "fps" );
+ *frequency = mlt_properties_get_int( producer_properties, "audio_rate" );
+ *channels = mlt_properties_get_int( producer_properties, "audio_channels" );
- // Size
- int size = *samples * *channels * 2;
+ // Maximum Size (?)
+ int size = ( *frequency / 25 ) * *channels * 2;
// Allocate an image
*buffer = malloc( size );
{
do
{
- if ( fread( *buffer, size, 1, producer->audio ) != 1 )
+ *samples = sample_calculator( fps, *frequency, target - skip );
+ if ( fread( *buffer, *samples * *channels * 2, 1, producer->audio ) != 1 )
{
pclose( producer->audio );
producer->audio = NULL;
}
else
{
+ *samples = sample_calculator( fps, *frequency, target );
memset( *buffer, 0, size );
}
// Are we at the position expected?
producer_ffmpeg_position( this, mlt_producer_frame( producer ), &skip );
+ // Get properties objects
+ mlt_properties producer_properties = mlt_producer_properties( &this->parent );
+
// Get the frames properties
mlt_properties properties = mlt_frame_properties( *frame );
FILE *video = this->video;
+ mlt_properties_set_double( properties, "target", mlt_producer_frame( producer ) );
mlt_properties_set_int( properties, "skip", skip );
// Read the video
// Clean up
if ( this->video != NULL )
{
+ int video_loop = mlt_properties_get_int( producer_properties, "video_loop" );
+
// Inform caller that end of clip is reached
- this->end_of_video = 1;
+ this->end_of_video = !video_loop;
pclose( this->video );
this->video = NULL;
}
// Hmm - register audio callback
( *frame )->get_audio = producer_get_audio;
- // Get properties objects
- mlt_properties producer_properties = mlt_producer_properties( &this->parent );
-
// Get the additional properties
double aspect_ratio = mlt_properties_get_double( producer_properties, "aspect_ratio" );
double speed = mlt_properties_get_double( producer_properties, "speed" );
* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
-#ifndef _PRODUCER_Y4M_H_
-#define _PRODUCER_Y4M_H_
+#ifndef _PRODUCER_FFMPEG_H_
+#define _PRODUCER_FFMPEG_H_
#include <framework/mlt_producer.h>
-#include <stdio.h>
extern mlt_producer producer_ffmpeg_init( char *file );
--- /dev/null
+#!/bin/bash
+
+video_type="$1"
+video_file="$2"
+video_size="$3"
+video_fps=$4
+video_position=$5
+
+[ "$video_size" != "" ] && video_size="-s "$video_size
+
+if [ "$video_type" == "v4l" ]
+then ffmpeg -vd "$video_file" -r $video_fps $video_size -f imagepipe -f yuv4mpegpipe -
+else ffmpeg -i "$video_file" -ss $video_position -f imagepipe -r $video_fps $video_size -f yuv4mpegpipe -
+fi