2 * producer_avformat.c -- avformat producer
3 * Copyright (C) 2003-2004 Ushodaya Enterprises Limited
4 * Author: Charles Yates <charles.yates@pandora.be>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software Foundation,
18 * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22 #include "producer_avformat.h"
25 #include <framework/mlt_frame.h>
27 // ffmpeg Header files
30 // System header files
36 void avformat_lock( );
37 void avformat_unlock( );
39 // Forward references.
40 static int producer_open( mlt_producer this, char *file );
41 static int producer_get_frame( mlt_producer this, mlt_frame_ptr frame, int index );
43 /** Constructor for libavformat.
46 mlt_producer producer_avformat_init( char *file )
48 mlt_producer this = NULL;
50 // Check that we have a non-NULL argument
53 // Construct the producer
54 this = calloc( 1, sizeof( struct mlt_producer_s ) );
57 if ( mlt_producer_init( this, NULL ) == 0 )
60 mlt_properties properties = mlt_producer_properties( this );
62 // Set the resource property (required for all producers)
63 mlt_properties_set( properties, "resource", file );
65 // Register our get_frame implementation
66 this->get_frame = producer_get_frame;
69 if ( producer_open( this, file ) != 0 )
72 mlt_producer_close( this );
81 /** Find the default streams.
84 static void find_default_streams( AVFormatContext *context, int *audio_index, int *video_index )
88 // Allow for multiple audio and video streams in the file and select first of each (if available)
89 for( i = 0; i < context->nb_streams; i++ )
91 // Get the codec context
92 AVCodecContext *codec_context = &context->streams[ i ]->codec;
94 // Determine the type and obtain the first index of each type
95 switch( codec_context->codec_type )
97 case CODEC_TYPE_VIDEO:
98 if ( *video_index < 0 )
101 case CODEC_TYPE_AUDIO:
102 if ( *audio_index < 0 )
111 /** Producer file destructor.
114 static void producer_file_close( void *context )
116 if ( context != NULL )
118 // Lock the mutex now
122 av_close_input_file( context );
124 // Unlock the mutex now
129 /** Producer file destructor.
132 static void producer_codec_close( void *codec )
136 // Lock the mutex now
140 avcodec_close( codec );
142 // Unlock the mutex now
150 static int producer_open( mlt_producer this, char *file )
152 // Return an error code (0 == no error)
155 // Context for avformat
156 AVFormatContext *context = NULL;
158 // Get the properties
159 mlt_properties properties = mlt_producer_properties( this );
161 // We will treat everything with the producer fps
162 double fps = mlt_properties_get_double( properties, "fps" );
164 // Lock the mutex now
167 // If "MRL", then create AVInputFormat
168 AVInputFormat *format = NULL;
169 AVFormatParameters *params = NULL;
170 char *standard = NULL;
171 char *mrl = strchr( file, ':' );
173 // AV option (0 = both, 1 = video, 2 = audio)
176 // Only if there is not a protocol specification that avformat can handle
177 if ( mrl && !url_exist( file ) )
179 // 'file' becomes format abbreviation
183 format = av_find_input_format( file );
185 // Eat the format designator
191 params = calloc( sizeof( AVFormatParameters ), 1 );
193 // These are required by video4linux (defaults)
195 params->height = 480;
196 params->frame_rate = 25;
197 params->frame_rate_base = 1;
198 params->device = file;
199 params->channels = 2;
200 params->sample_rate = 48000;
204 mrl = strchr( file, '?' );
208 char *name = strdup( ++mrl );
209 char *value = strchr( name, ':' );
214 char *t = strchr( value, '&' );
217 if ( !strcmp( name, "frame_rate" ) )
218 params->frame_rate = atoi( value );
219 else if ( !strcmp( name, "frame_rate_base" ) )
220 params->frame_rate_base = atoi( value );
221 else if ( !strcmp( name, "sample_rate" ) )
222 params->sample_rate = atoi( value );
223 else if ( !strcmp( name, "channels" ) )
224 params->channels = atoi( value );
225 else if ( !strcmp( name, "width" ) )
226 params->width = atoi( value );
227 else if ( !strcmp( name, "height" ) )
228 params->height = atoi( value );
229 else if ( !strcmp( name, "standard" ) )
231 standard = strdup( value );
232 params->standard = standard;
234 else if ( !strcmp( name, "av" ) )
238 mrl = strchr( mrl, '&' );
242 // Now attempt to open the file
243 error = av_open_input_file( &context, file, format, 0, params );
246 // Cleanup AVFormatParameters
250 // If successful, then try to get additional info
253 // Get the stream info
254 error = av_find_stream_info( context ) < 0;
256 // Continue if no error
259 // We will default to the first audio and video streams found
260 int audio_index = -1;
261 int video_index = -1;
263 // Now set properties where we can (use default unknowns if required)
264 if ( context->duration != AV_NOPTS_VALUE )
266 // This isn't going to be accurate for all formats
267 mlt_position frames = ( mlt_position )( ( ( double )context->duration / ( double )AV_TIME_BASE ) * fps );
268 mlt_properties_set_position( properties, "out", frames - 2 );
269 mlt_properties_set_position( properties, "length", frames - 1 );
272 // Find default audio and video streams
273 find_default_streams( context, &audio_index, &video_index );
275 if ( context->start_time != AV_NOPTS_VALUE )
276 mlt_properties_set_double( properties, "start_time", context->start_time );
278 // Check if we're seekable (something funny about mpeg here :-/)
279 if ( strcmp( file, "pipe:" ) )
280 mlt_properties_set_int( properties, "seekable", av_seek_frame( context, -1, mlt_properties_get_double( properties, "start_time" ) ) >= 0 );
282 // Store selected audio and video indexes on properties
283 mlt_properties_set_int( properties, "audio_index", audio_index );
284 mlt_properties_set_int( properties, "video_index", video_index );
286 // We're going to cheat here - for a/v files, we will have two contexts (reasoning will be clear later)
287 if ( av == 0 && strcmp( file, "pipe:" ) && audio_index != -1 && video_index != -1 )
289 // We'll use the open one as our video_context
290 mlt_properties_set_data( properties, "video_context", context, 0, producer_file_close, NULL );
292 // And open again for our audio context
293 av_open_input_file( &context, file, NULL, 0, NULL );
294 av_find_stream_info( context );
297 mlt_properties_set_data( properties, "audio_context", context, 0, producer_file_close, NULL );
299 else if ( av != 2 && video_index != -1 )
301 // We only have a video context
302 mlt_properties_set_data( properties, "video_context", context, 0, producer_file_close, NULL );
304 else if ( audio_index != -1 )
306 // We only have an audio context
307 mlt_properties_set_data( properties, "audio_context", context, 0, producer_file_close, NULL );
311 // Something has gone wrong
317 // Unlock the mutex now
323 /** Convert a frame position to a time code.
326 static double producer_time_of_frame( mlt_producer this, mlt_position position )
328 // Get the properties
329 mlt_properties properties = mlt_producer_properties( this );
332 double fps = mlt_properties_get_double( properties, "fps" );
335 return ( double )position / fps;
338 static inline void convert_image( AVFrame *frame, uint8_t *buffer, int pix_fmt, mlt_image_format format, int width, int height )
340 // EXPERIMENTAL IMAGE NORMALISATIONS
341 if ( pix_fmt == PIX_FMT_YUV420P && format == mlt_image_yuv422 )
344 register int half = width >> 1;
345 register uint8_t *Y = ( ( AVPicture * )frame )->data[ 0 ];
346 register uint8_t *U = ( ( AVPicture * )frame )->data[ 1 ];
347 register uint8_t *V = ( ( AVPicture * )frame )->data[ 2 ];
348 register uint8_t *d = buffer;
349 register uint8_t *y, *u, *v;
366 Y += ( ( AVPicture * )frame )->linesize[ 0 ];
379 Y += ( ( AVPicture * )frame )->linesize[ 0 ];
380 U += ( ( AVPicture * )frame )->linesize[ 1 ];
381 V += ( ( AVPicture * )frame )->linesize[ 2 ];
384 else if ( format == mlt_image_yuv420p )
387 pict.data[0] = buffer;
388 pict.data[1] = buffer + width * height;
389 pict.data[2] = buffer + ( 3 * width * height ) / 2;
390 pict.linesize[0] = width;
391 pict.linesize[1] = width >> 1;
392 pict.linesize[2] = width >> 1;
393 img_convert( &pict, PIX_FMT_YUV420P, (AVPicture *)frame, pix_fmt, width, height );
398 avpicture_fill( &output, buffer, PIX_FMT_YUV422, width, height );
399 img_convert( &output, PIX_FMT_YUV422, (AVPicture *)frame, pix_fmt, width, height );
403 /** Get an image from a frame.
406 static int producer_get_image( mlt_frame frame, uint8_t **buffer, mlt_image_format *format, int *width, int *height, int writable )
408 // Get the properties from the frame
409 mlt_properties frame_properties = mlt_frame_properties( frame );
411 // Obtain the frame number of this frame
412 mlt_position position = mlt_properties_get_position( frame_properties, "avformat_position" );
415 mlt_producer this = mlt_properties_get_data( frame_properties, "avformat_producer", NULL );
417 // Get the producer properties
418 mlt_properties properties = mlt_producer_properties( this );
420 // Fetch the video_context
421 AVFormatContext *context = mlt_properties_get_data( properties, "video_context", NULL );
423 // Get the video_index
424 int index = mlt_properties_get_int( properties, "video_index" );
426 // Obtain the expected frame numer
427 mlt_position expected = mlt_properties_get_position( properties, "video_expected" );
429 // Calculate the real time code
430 double real_timecode = producer_time_of_frame( this, position );
432 // Get the video stream
433 AVStream *stream = context->streams[ index ];
436 AVCodecContext *codec_context = &stream->codec;
441 // Get the conversion frame
442 AVFrame *av_frame = mlt_properties_get_data( properties, "av_frame", NULL );
444 // Special case pause handling flag
447 // Special case ffwd handling
450 // Current time calcs
451 double current_time = mlt_properties_get_double( properties, "current_time" );
453 // We may want to use the source fps if available
454 double source_fps = mlt_properties_get_double( properties, "source_fps" );
456 // Get the seekable status
457 int seekable = mlt_properties_get_int( properties, "seekable" );
459 // Generate the size in bytes
462 // Set the result arguments that we know here (only *buffer is now required)
463 if ( *format != mlt_image_yuv422 && *format != mlt_image_yuv420p )
464 *format = mlt_image_yuv422;
465 *width = codec_context->width;
466 *height = codec_context->height;
468 size = *width * ( *height + 1 ) * 2;
470 // Set this on the frame properties
471 mlt_properties_set_int( frame_properties, "width", *width );
472 mlt_properties_set_int( frame_properties, "height", *height );
474 // Construct the output image
475 *buffer = mlt_pool_alloc( size );
478 if ( position != expected )
480 if ( position + 1 == expected )
482 // We're paused - use last image
485 else if ( !seekable && position > expected && ( position - expected ) < 250 )
487 // Fast forward - seeking is inefficient for small distances - just ignore following frames
488 ignore = position - expected;
490 else if ( codec_context->gop_size == 0 || ( position < expected || position - expected >= 12 ) )
492 // Set to the real timecode
493 av_seek_frame( context, -1, mlt_properties_get_double( properties, "start_time" ) + real_timecode * 1000000.0 );
495 // Remove the cached info relating to the previous position
496 mlt_properties_set_double( properties, "current_time", real_timecode );
498 mlt_properties_set_data( properties, "av_frame", NULL, 0, NULL, NULL );
503 // Duplicate the last image if necessary
504 if ( av_frame != NULL && ( paused || mlt_properties_get_double( properties, "current_time" ) >= real_timecode ) &&
505 strcmp( mlt_properties_get( properties, "resource" ), "pipe:" ) )
508 convert_image( av_frame, *buffer, codec_context->pix_fmt, *format, *width, *height );
510 // Set this on the frame properties
511 mlt_properties_set_data( frame_properties, "image", *buffer, size, ( mlt_destructor )mlt_pool_release, NULL );
518 memset( &pkt, 0, sizeof( pkt ) );
520 // Construct an AVFrame for YUV422 conversion
521 if ( av_frame == NULL )
523 av_frame = calloc( 1, sizeof( AVFrame ) );
524 mlt_properties_set_data( properties, "av_frame", av_frame, 0, free, NULL );
528 while( ret >= 0 && !got_picture )
531 ret = av_read_frame( context, &pkt );
533 // We only deal with video from the selected video_index
534 if ( ret >= 0 && pkt.stream_index == index && pkt.size > 0 )
537 ret = avcodec_decode_video( codec_context, av_frame, &got_picture, pkt.data, pkt.size );
541 if ( pkt.pts != AV_NOPTS_VALUE )
542 current_time = ( double )pkt.pts / 1000000.0;
544 current_time = real_timecode;
547 if ( ( int )( current_time * 100 ) < ( int )( real_timecode * 100 ) - 7 )
552 else if ( current_time >= real_timecode )
554 //current_time = real_timecode;
557 else if ( ignore -- )
561 mlt_properties_set_int( properties, "top_field_first", av_frame->top_field_first );
565 // We're finished with this packet regardless
566 av_free_packet( &pkt );
569 // Now handle the picture if we have one
572 convert_image( av_frame, *buffer, codec_context->pix_fmt, *format, *width, *height );
574 mlt_properties_set_data( frame_properties, "image", *buffer, size, (mlt_destructor)mlt_pool_release, NULL );
576 if ( current_time == 0 && source_fps != 0 )
578 double fps = mlt_properties_get_double( properties, "fps" );
579 current_time = ceil( source_fps * ( double )position / fps ) * ( 1 / source_fps );
580 mlt_properties_set_double( properties, "current_time", current_time );
584 mlt_properties_set_double( properties, "current_time", current_time );
589 // Set the field order property for this frame
590 mlt_properties_set_int( frame_properties, "top_field_first",
591 mlt_properties_get_int( properties, "top_field_first" ) );
593 // Regardless of speed, we expect to get the next frame (cos we ain't too bright)
594 mlt_properties_set_position( properties, "video_expected", position + 1 );
599 /** Set up video handling.
602 static void producer_set_up_video( mlt_producer this, mlt_frame frame )
604 // Get the properties
605 mlt_properties properties = mlt_producer_properties( this );
607 // Fetch the video_context
608 AVFormatContext *context = mlt_properties_get_data( properties, "video_context", NULL );
610 // Get the video_index
611 int index = mlt_properties_get_int( properties, "video_index" );
613 // Get the frame properties
614 mlt_properties frame_properties = mlt_frame_properties( frame );
616 if ( context != NULL && index != -1 )
618 // Get the video stream
619 AVStream *stream = context->streams[ index ];
622 AVCodecContext *codec_context = &stream->codec;
625 AVCodec *codec = mlt_properties_get_data( properties, "video_codec", NULL );
627 // Initialise the codec if necessary
631 codec = avcodec_find_decoder( codec_context->codec_id );
633 // If we don't have a codec and we can't initialise it, we can't do much more...
634 if ( codec != NULL && avcodec_open( codec_context, codec ) >= 0 )
636 // Now store the codec with its destructor
637 mlt_properties_set_data( properties, "video_codec", codec_context, 0, producer_codec_close, NULL );
641 // Remember that we can't use this later
642 mlt_properties_set_int( properties, "video_index", -1 );
646 // No codec, no show...
649 double source_fps = 0;
651 // XXX: We won't know the real aspect ratio until an image is decoded
652 // but we do need it now (to satisfy filter_resize) - take a guess based
654 if ( codec_context->sample_aspect_ratio.num > 0 )
656 mlt_properties_set_double( properties, "aspect_ratio", av_q2d( codec_context->sample_aspect_ratio ) );
660 int is_pal = mlt_properties_get_double( properties, "fps" ) == 25.0;
661 mlt_properties_set_double( properties, "aspect_ratio", is_pal ? 128.0/117.0 : 72.0/79.0 );
664 //fprintf( stderr, "AVFORMAT: sample aspect %f %dx%d\n", av_q2d( codec_context->sample_aspect_ratio ), codec_context->width, codec_context->height );
667 source_fps = ( double )codec_context->frame_rate / ( codec_context->frame_rate_base == 0 ? 1 : codec_context->frame_rate_base );
669 // We'll use fps if it's available
670 if ( source_fps > 0 && source_fps < 30 )
671 mlt_properties_set_double( properties, "source_fps", source_fps );
673 // Set the width and height
674 mlt_properties_set_int( frame_properties, "width", codec_context->width );
675 mlt_properties_set_int( frame_properties, "height", codec_context->height );
677 mlt_frame_push_get_image( frame, producer_get_image );
678 mlt_properties_set_data( frame_properties, "avformat_producer", this, 0, NULL, NULL );
682 mlt_properties_set_int( frame_properties, "test_image", 1 );
687 mlt_properties_set_int( frame_properties, "test_image", 1 );
691 /** Get the audio from a frame.
694 static int producer_get_audio( mlt_frame frame, int16_t **buffer, mlt_audio_format *format, int *frequency, int *channels, int *samples )
696 // Get the properties from the frame
697 mlt_properties frame_properties = mlt_frame_properties( frame );
699 // Obtain the frame number of this frame
700 mlt_position position = mlt_properties_get_position( frame_properties, "avformat_position" );
703 mlt_producer this = mlt_properties_get_data( frame_properties, "avformat_producer", NULL );
705 // Get the producer properties
706 mlt_properties properties = mlt_producer_properties( this );
708 // Fetch the audio_context
709 AVFormatContext *context = mlt_properties_get_data( properties, "audio_context", NULL );
711 // Get the audio_index
712 int index = mlt_properties_get_int( properties, "audio_index" );
714 // Get the seekable status
715 int seekable = mlt_properties_get_int( properties, "seekable" );
717 // Obtain the expected frame numer
718 mlt_position expected = mlt_properties_get_position( properties, "audio_expected" );
720 // Obtain the resample context if it exists (not always needed)
721 ReSampleContext *resample = mlt_properties_get_data( properties, "audio_resample", NULL );
723 // Obtain the audio buffer
724 int16_t *audio_buffer = mlt_properties_get_data( properties, "audio_buffer", NULL );
726 // Get amount of audio used
727 int audio_used = mlt_properties_get_int( properties, "audio_used" );
729 // Calculate the real time code
730 double real_timecode = producer_time_of_frame( this, position );
732 // Get the audio stream
733 AVStream *stream = context->streams[ index ];
736 AVCodecContext *codec_context = &stream->codec;
741 // Number of frames to ignore (for ffwd)
744 // Flag for paused (silence)
747 // Check for resample and create if necessary
748 if ( resample == NULL && codec_context->channels <= 2 )
750 // Create the resampler
751 resample = audio_resample_init( *channels, codec_context->channels, *frequency, codec_context->sample_rate );
753 // And store it on properties
754 mlt_properties_set_data( properties, "audio_resample", resample, 0, ( mlt_destructor )audio_resample_close, NULL );
756 else if ( resample == NULL )
758 *channels = codec_context->channels;
759 *frequency = codec_context->sample_rate;
762 // Check for audio buffer and create if necessary
763 if ( audio_buffer == NULL )
765 // Allocate the audio buffer
766 audio_buffer = mlt_pool_alloc( AVCODEC_MAX_AUDIO_FRAME_SIZE * sizeof( int16_t ) );
768 // And store it on properties for reuse
769 mlt_properties_set_data( properties, "audio_buffer", audio_buffer, 0, ( mlt_destructor )mlt_pool_release, NULL );
773 if ( position != expected )
775 if ( position + 1 == expected )
777 // We're paused - silence required
780 else if ( !seekable && position > expected && ( position - expected ) < 250 )
782 // Fast forward - seeking is inefficient for small distances - just ignore following frames
783 ignore = position - expected;
785 else if ( position < expected || position - expected >= 12 )
787 // Set to the real timecode
788 if ( av_seek_frame( context, -1, mlt_properties_get_double( properties, "start_time" ) + real_timecode * 1000000.0 ) != 0 )
791 // Clear the usage in the audio buffer
796 // Get the audio if required
801 int16_t *temp = mlt_pool_alloc( sizeof( int16_t ) * AVCODEC_MAX_AUDIO_FRAME_SIZE );
803 memset( &pkt, 0, sizeof( pkt ) );
805 while( ret >= 0 && !got_audio )
807 // Check if the buffer already contains the samples required
808 if ( audio_used >= *samples && ignore == 0 )
815 ret = av_read_frame( context, &pkt );
818 uint8_t *ptr = pkt.data;
821 // We only deal with audio from the selected audio_index
822 while ( ptr != NULL && ret >= 0 && pkt.stream_index == index && len > 0 )
825 ret = avcodec_decode_audio( codec_context, temp, &data_size, ptr, len );
838 if ( resample != NULL )
840 audio_used += audio_resample( resample, &audio_buffer[ audio_used * *channels ], temp, data_size / ( codec_context->channels * sizeof( int16_t ) ) );
844 memcpy( &audio_buffer[ audio_used * *channels ], temp, data_size );
845 audio_used += data_size / ( codec_context->channels * sizeof( int16_t ) );
849 while ( ignore && audio_used > *samples )
852 audio_used -= *samples;
853 memmove( audio_buffer, &audio_buffer[ *samples * *channels ], audio_used * sizeof( int16_t ) );
857 // If we're behind, ignore this packet
858 float current_pts = (float)pkt.pts / 1000000.0;
859 if ( seekable && ( !ignore && current_pts <= ( real_timecode - 0.02 ) ) )
863 // We're finished with this packet regardless
864 av_free_packet( &pkt );
867 *buffer = mlt_pool_alloc( *samples * *channels * sizeof( int16_t ) );
868 mlt_properties_set_data( frame_properties, "audio", *buffer, 0, ( mlt_destructor )mlt_pool_release, NULL );
870 // Now handle the audio if we have enough
871 if ( audio_used >= *samples )
873 memcpy( *buffer, audio_buffer, *samples * *channels * sizeof( int16_t ) );
874 audio_used -= *samples;
875 memmove( audio_buffer, &audio_buffer[ *samples * *channels ], audio_used * *channels * sizeof( int16_t ) );
879 memset( *buffer, 0, *samples * *channels * sizeof( int16_t ) );
882 // Store the number of audio samples still available
883 mlt_properties_set_int( properties, "audio_used", audio_used );
885 // Release the temporary audio
886 mlt_pool_release( temp );
890 // Get silence and don't touch the context
891 frame->get_audio = NULL;
892 mlt_frame_get_audio( frame, buffer, format, frequency, channels, samples );
895 // Regardless of speed (other than paused), we expect to get the next frame
897 mlt_properties_set_position( properties, "audio_expected", position + 1 );
902 /** Set up audio handling.
905 static void producer_set_up_audio( mlt_producer this, mlt_frame frame )
907 // Get the properties
908 mlt_properties properties = mlt_producer_properties( this );
910 // Fetch the audio_context
911 AVFormatContext *context = mlt_properties_get_data( properties, "audio_context", NULL );
913 // Get the audio_index
914 int index = mlt_properties_get_int( properties, "audio_index" );
916 // Deal with audio context
917 if ( context != NULL && index != -1 )
919 // Get the frame properties
920 mlt_properties frame_properties = mlt_frame_properties( frame );
922 // Get the audio stream
923 AVStream *stream = context->streams[ index ];
926 AVCodecContext *codec_context = &stream->codec;
929 AVCodec *codec = mlt_properties_get_data( properties, "audio_codec", NULL );
931 // Initialise the codec if necessary
935 codec = avcodec_find_decoder( codec_context->codec_id );
937 // If we don't have a codec and we can't initialise it, we can't do much more...
938 if ( codec != NULL && avcodec_open( codec_context, codec ) >= 0 )
940 // Now store the codec with its destructor
941 mlt_properties_set_data( properties, "audio_codec", codec_context, 0, producer_codec_close, NULL );
946 // Remember that we can't use this later
947 mlt_properties_set_int( properties, "audio_index", -1 );
951 // No codec, no show...
954 frame->get_audio = producer_get_audio;
955 mlt_properties_set_data( frame_properties, "avformat_producer", this, 0, NULL, NULL );
960 /** Our get frame implementation.
963 static int producer_get_frame( mlt_producer this, mlt_frame_ptr frame, int index )
965 // Create an empty frame
966 *frame = mlt_frame_init( );
968 // Update timecode on the frame we're creating
969 mlt_frame_set_position( *frame, mlt_producer_position( this ) );
971 // Set the position of this producer
972 mlt_properties_set_position( mlt_frame_properties( *frame ), "avformat_position", mlt_producer_position( this ) );
975 producer_set_up_video( this, *frame );
978 producer_set_up_audio( this, *frame );
980 // Set the aspect_ratio
981 mlt_properties_set_double( mlt_frame_properties( *frame ), "aspect_ratio", mlt_properties_get_double( mlt_producer_properties( this ), "aspect_ratio" ) );
983 // Calculate the next timecode
984 mlt_producer_prepare_next( this );