From: lilo_booter Date: Tue, 30 Mar 2004 19:45:13 +0000 (+0000) Subject: Minor optimisations, consumer avformat experimentation X-Git-Url: https://git.sesse.net/?a=commitdiff_plain;h=f2dda0fcd1c242afcd07f2c2ef98f8f6b3fb0e13;p=mlt Minor optimisations, consumer avformat experimentation git-svn-id: https://mlt.svn.sourceforge.net/svnroot/mlt/trunk/mlt@262 d19143bc-622f-0410-bfdd-b5b2a6649095 --- diff --git a/docs/services.txt b/docs/services.txt index e9321477..7e6fcae3 100644 --- a/docs/services.txt +++ b/docs/services.txt @@ -1278,6 +1278,35 @@ Transitions Consumers --------- + avformat + + Description + + Multiformat transcoding consumer. + + Constructor Argument + + string target - the filename to write to, e.g. test.mpeg. + + Initialisation Properties + + int buffer - the number of frames to buffer, minimum 1, default 25. + string rescale - a rescale method, see the Filters/rescale. + int progressive - indicates whether to use progressive or field- + based rendering, default 0 (off). + + Read Only Properties + + none + + Dependencies + + libavformat + + Known Bugs + + Plenty. + bluefish (Proprietary) Description diff --git a/src/albino/Makefile b/src/albino/Makefile index d30c7626..4ad38e48 100644 --- a/src/albino/Makefile +++ b/src/albino/Makefile @@ -4,15 +4,10 @@ TARGET = albino OBJS = albino.o -CFLAGS = -O3 -I .. -Wall -g -D_FILE_OFFSET_BITS=64 -pthread -rdynamic +CFLAGS = -O4 -pipe -ffast-math -fomit-frame-pointer -I .. -Wall -g -D_FILE_OFFSET_BITS=64 -pthread -rdynamic LDFLAGS = -L ../valerie -L ../miracle -L ../framework -lmiracle -lmlt -lvalerie -ifeq ($(MLT_GPROF),true) -CFLAGS+=-p -LDFLAGS+=-p -endif - SRCS := $(OBJS:.o=.c) all: $(TARGET) diff --git a/src/framework/Makefile b/src/framework/Makefile index b9f2c708..00cc6050 100644 --- a/src/framework/Makefile +++ b/src/framework/Makefile @@ -21,7 +21,7 @@ OBJS = mlt_frame.o \ SRCS := $(OBJS:.o=.c) -CFLAGS = -g -O3 -Wall -D_FILE_OFFSET_BITS=64 -pthread -DPREFIX="\"$(prefix)\"" +CFLAGS = -g -O4 -pipe -ffast-math -fomit-frame-pointer -Wall -D_FILE_OFFSET_BITS=64 -pthread -DPREFIX="\"$(prefix)\"" LDFLAGS = -lm -ldl -lpthread diff --git a/src/framework/mlt_consumer.c b/src/framework/mlt_consumer.c index 2fb7dd33..829c3e83 100644 --- a/src/framework/mlt_consumer.c +++ b/src/framework/mlt_consumer.c @@ -165,6 +165,9 @@ int mlt_consumer_start( mlt_consumer this ) mlt_properties_set_data( properties, "test_card_producer", NULL, 0, NULL, NULL ); } + // Set the real_time preference + this->real_time = mlt_properties_get_int( properties, "real_time" ); + // Start the service if ( this->start != NULL ) return this->start( this ); @@ -172,7 +175,7 @@ int mlt_consumer_start( mlt_consumer this ) return 0; } -/** Protected method :-/ for consumer to get frames from connected service +/** Protected method for consumer to get frames from connected service */ mlt_frame mlt_consumer_get_frame( mlt_consumer this ) @@ -375,7 +378,7 @@ mlt_frame mlt_consumer_rt_frame( mlt_consumer this ) mlt_properties properties = mlt_consumer_properties( this ); // Check if the user has requested real time or not - if ( mlt_properties_get_int( properties, "real_time" ) ) + if ( this->real_time ) { int size = 1; diff --git a/src/framework/mlt_consumer.h b/src/framework/mlt_consumer.h index 53767562..e718912c 100644 --- a/src/framework/mlt_consumer.h +++ b/src/framework/mlt_consumer.h @@ -42,6 +42,7 @@ struct mlt_consumer_s void *private; void *child; + int real_time; int ahead; mlt_image_format format; mlt_deque queue; diff --git a/src/framework/mlt_frame.c b/src/framework/mlt_frame.c index ce820b9a..0924cbbc 100644 --- a/src/framework/mlt_frame.c +++ b/src/framework/mlt_frame.c @@ -494,6 +494,8 @@ void mlt_resize_yuv422( uint8_t *output, int owidth, int oheight, uint8_t *input int active_width = 2 * iwidth; int inactive_width = out_x_range - in_x_range; + uint8_t *p = NULL; + uint8_t *end = NULL; // Loop for the entirety of our output height. while ( iheight -- ) @@ -510,8 +512,13 @@ void mlt_resize_yuv422( uint8_t *output, int owidth, int oheight, uint8_t *input } // We're in the input range for this row. - memcpy( out_ptr, in_middle + in_line, active_width ); - out_ptr += active_width; + p = in_middle + in_line; + end = out_ptr + active_width; + while ( out_ptr != end ) + { + *out_ptr ++ = *p ++; + *out_ptr ++ = *p ++; + } // Fill the outer part with black elements = inactive_width; diff --git a/src/humperdink/Makefile b/src/humperdink/Makefile index 7003d633..f974b0db 100644 --- a/src/humperdink/Makefile +++ b/src/humperdink/Makefile @@ -6,7 +6,7 @@ OBJS = client.o \ io.o \ remote.o -CFLAGS = -O3 -I .. -Wall -g -D_FILE_OFFSET_BITS=64 -pthread -rdynamic +CFLAGS = -O4 -pipe -ffast-math -fomit-frame-pointer -I .. -Wall -g -D_FILE_OFFSET_BITS=64 -pthread -rdynamic LDFLAGS = -L ../valerie -lvalerie diff --git a/src/inigo/Makefile b/src/inigo/Makefile index 0b67a319..46f21f8b 100644 --- a/src/inigo/Makefile +++ b/src/inigo/Makefile @@ -5,7 +5,7 @@ TARGET = inigo OBJS = inigo.o \ io.o -CFLAGS = -O3 -I .. -Wall -g -D_FILE_OFFSET_BITS=64 -pthread -rdynamic +CFLAGS = -O4 -pipe -ffast-math -fomit-frame-pointer -I .. -Wall -g -D_FILE_OFFSET_BITS=64 -pthread -rdynamic LDFLAGS = -L ../framework -lmlt diff --git a/src/miracle/Makefile b/src/miracle/Makefile index f8f4340f..8cba00af 100644 --- a/src/miracle/Makefile +++ b/src/miracle/Makefile @@ -14,7 +14,7 @@ LIB_OBJS = miracle_log.o \ OBJS = $(APP_OBJS) $(LIB_OBJS) -CFLAGS = -O3 -I .. -Wall -g -D_FILE_OFFSET_BITS=64 -pthread -rdynamic +CFLAGS = -O4 -pipe -ffast-math -fomit-frame-pointer -I .. -Wall -g -D_FILE_OFFSET_BITS=64 -pthread -rdynamic LDFLAGS = -L ../valerie -lvalerie -L ../framework -lmlt diff --git a/src/miracle/miracle_unit.c b/src/miracle/miracle_unit.c index ff607231..ce9dac81 100644 --- a/src/miracle/miracle_unit.c +++ b/src/miracle/miracle_unit.c @@ -697,6 +697,7 @@ void miracle_unit_close( miracle_unit unit ) if ( unit != NULL ) { miracle_log( LOG_DEBUG, "closing unit..." ); + miracle_unit_terminate( unit ); if ( unit->old_producers != NULL ) mlt_properties_close( unit->old_producers ); mlt_properties_close( unit->properties ); diff --git a/src/modules/avformat/Makefile b/src/modules/avformat/Makefile index 3d1e1cc0..390cef48 100644 --- a/src/modules/avformat/Makefile +++ b/src/modules/avformat/Makefile @@ -6,7 +6,7 @@ OBJS = factory.o \ producer_avformat.o \ consumer_avformat.o -CFLAGS = -O3 -I../../ -Wall -g -D_FILE_OFFSET_BITS=64 +CFLAGS = -O4 -pipe -ffast-math -fomit-frame-pointer -I../../ -Wall -g -D_FILE_OFFSET_BITS=64 LDFLAGS = -lavformat -lavcodec diff --git a/src/modules/avformat/consumer_avformat.c b/src/modules/avformat/consumer_avformat.c index ce13c884..a841339e 100644 --- a/src/modules/avformat/consumer_avformat.c +++ b/src/modules/avformat/consumer_avformat.c @@ -10,7 +10,7 @@ * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License @@ -117,10 +117,14 @@ mlt_consumer consumer_avformat_init( char *arg ) // Set avformat defaults mlt_properties_set_int( properties, "audio_bit_rate", 128000 ); - mlt_properties_set_int( properties, "video_bit_rate", 400000 ); + mlt_properties_set_int( properties, "video_bit_rate", 200 * 1000 ); + mlt_properties_set_int( properties, "video_bit_rate_tolerance", 4000 * 1000 ); + mlt_properties_set_int( properties, "frame_rate_base", 1 ); mlt_properties_set_int( properties, "gop_size", 12 ); mlt_properties_set_int( properties, "max_b_frames", 0 ); mlt_properties_set_int( properties, "mb_decision", 0 ); + mlt_properties_set_double( properties, "qscale", 0 ); + mlt_properties_set_int( properties, "me_method", ME_EPZS ); // Ensure termination at end of the stream mlt_properties_set_int( properties, "terminate_on_pause", 1 ); @@ -161,7 +165,7 @@ static int consumer_start( mlt_consumer this ) int height = mlt_properties_get_int( properties, "height" ); // Obtain the size property - char *size = mlt_properties_get( properties, "size" ); + char *size = mlt_properties_get( properties, "size" ); // Interpret it if ( size != NULL ) @@ -241,26 +245,26 @@ static AVStream *add_audio_stream( mlt_consumer this, AVFormatContext *oc, int c mlt_properties properties = mlt_consumer_properties( this ); // Create a new stream - AVStream *st = av_new_stream( oc, 1 ); + AVStream *st = av_new_stream( oc, 1 ); // If created, then initialise from properties - if ( st != NULL ) + if ( st != NULL ) { - AVCodecContext *c = &st->codec; - c->codec_id = codec_id; - c->codec_type = CODEC_TYPE_AUDIO; - - // Put sample parameters - c->bit_rate = mlt_properties_get_int( properties, "audio_bit_rate" ); - c->sample_rate = mlt_properties_get_int( properties, "frequency" ); - c->channels = mlt_properties_get_int( properties, "channels" ); + AVCodecContext *c = &st->codec; + c->codec_id = codec_id; + c->codec_type = CODEC_TYPE_AUDIO; + + // Put sample parameters + c->bit_rate = mlt_properties_get_int( properties, "audio_bit_rate" ); + c->sample_rate = mlt_properties_get_int( properties, "frequency" ); + c->channels = mlt_properties_get_int( properties, "channels" ); } else { - fprintf( stderr, "Could not allocate a stream for audio\n" ); - } + fprintf( stderr, "Could not allocate a stream for audio\n" ); + } - return st; + return st; } static int open_audio( AVFormatContext *oc, AVStream *st, int audio_outbuf_size ) @@ -269,35 +273,41 @@ static int open_audio( AVFormatContext *oc, AVStream *st, int audio_outbuf_size int audio_input_frame_size = 0; // Get the context - AVCodecContext *c = &st->codec; + AVCodecContext *c = &st->codec; // Find the encoder - AVCodec *codec = avcodec_find_encoder( c->codec_id ); + AVCodec *codec = avcodec_find_encoder( c->codec_id ); // Continue if codec found and we can open it if ( codec != NULL && avcodec_open(c, codec) >= 0 ) { - // ugly hack for PCM codecs (will be removed ASAP with new PCM - // support to compute the input frame size in samples - if ( c->frame_size <= 1 ) + // ugly hack for PCM codecs (will be removed ASAP with new PCM + // support to compute the input frame size in samples + if ( c->frame_size <= 1 ) { - audio_input_frame_size = audio_outbuf_size / c->channels; - switch(st->codec.codec_id) + audio_input_frame_size = audio_outbuf_size / c->channels; + switch(st->codec.codec_id) { - case CODEC_ID_PCM_S16LE: - case CODEC_ID_PCM_S16BE: - case CODEC_ID_PCM_U16LE: - case CODEC_ID_PCM_U16BE: - audio_input_frame_size >>= 1; - break; - default: - break; - } - } + case CODEC_ID_PCM_S16LE: + case CODEC_ID_PCM_S16BE: + case CODEC_ID_PCM_U16LE: + case CODEC_ID_PCM_U16BE: + audio_input_frame_size >>= 1; + break; + default: + break; + } + } else { - audio_input_frame_size = c->frame_size; - } + audio_input_frame_size = c->frame_size; + } + + // Some formats want stream headers to be seperate (hmm) + if( !strcmp( oc->oformat->name, "mp4" ) || + !strcmp( oc->oformat->name, "mov" ) || + !strcmp( oc->oformat->name, "3gp" ) ) + c->flags |= CODEC_FLAG_GLOBAL_HEADER; } else { @@ -309,7 +319,7 @@ static int open_audio( AVFormatContext *oc, AVStream *st, int audio_outbuf_size static void close_audio( AVFormatContext *oc, AVStream *st ) { - avcodec_close( &st->codec ); + avcodec_close( &st->codec ); } /** Add a video output stream @@ -317,77 +327,95 @@ static void close_audio( AVFormatContext *oc, AVStream *st ) static AVStream *add_video_stream( mlt_consumer this, AVFormatContext *oc, int codec_id ) { - // Get the properties + // Get the properties mlt_properties properties = mlt_consumer_properties( this ); // Create a new stream - AVStream *st = av_new_stream( oc, 0 ); + AVStream *st = av_new_stream( oc, 0 ); - if ( st != NULL ) + if ( st != NULL ) { AVCodecContext *c = &st->codec; - c->codec_id = codec_id; - c->codec_type = CODEC_TYPE_VIDEO; - - // put sample parameters - c->bit_rate = mlt_properties_get_int( properties, "video_bit_rate" ); - c->width = mlt_properties_get_int( properties, "width" ); - c->height = mlt_properties_get_int( properties, "height" ); - c->frame_rate = mlt_properties_get_double( properties, "fps" ); - c->frame_rate_base = 1; - c->gop_size = mlt_properties_get_int( properties, "gop_size" ); - c->max_b_frames = mlt_properties_get_int( properties, "max_b_frames" ); - c->mb_decision = mlt_properties_get_int( properties, "mb_decision" ); - - // Some formats want stream headers to be seperate (hmm) - if( !strcmp( oc->oformat->name, "mp4" ) || + c->codec_id = codec_id; + c->codec_type = CODEC_TYPE_VIDEO; + + // put sample parameters + c->bit_rate = mlt_properties_get_int( properties, "video_bit_rate" ); + c->bit_rate_tolerance = mlt_properties_get_int( properties, "video_bit_rate_tolerance" ); + c->width = mlt_properties_get_int( properties, "width" ); + c->height = mlt_properties_get_int( properties, "height" ); + c->frame_rate = mlt_properties_get_double( properties, "fps" ); + c->frame_rate_base = mlt_properties_get_double( properties, "frame_rate_base" ); + c->frame_rate_base = 1; + c->gop_size = mlt_properties_get_int( properties, "gop_size" ); + c->max_b_frames = mlt_properties_get_int( properties, "max_b_frames" ); + if ( c->max_b_frames ) + { + c->b_frame_strategy = 0; + c->b_quant_factor = 2.0; + } + + c->mb_decision = mlt_properties_get_int( properties, "mb_decision" ); + c->sample_aspect_ratio = av_d2q( mlt_properties_get_double( properties, "aspect_ratio" ), 255 ); + + + if ( mlt_properties_get_double( properties, "qscale" ) > 0 ) + { + c->flags |= CODEC_FLAG_QSCALE; + st->quality = FF_QP2LAMBDA * mlt_properties_get_double( properties, "qscale" ); + } + + // Some formats want stream headers to be seperate (hmm) + if( !strcmp( oc->oformat->name, "mp4" ) || !strcmp( oc->oformat->name, "mov" ) || !strcmp( oc->oformat->name, "3gp" ) ) - c->flags |= CODEC_FLAG_GLOBAL_HEADER; + c->flags |= CODEC_FLAG_GLOBAL_HEADER; + + c->me_method = mlt_properties_get_int( properties, "me_method" ); } else { - fprintf( stderr, "Could not allocate a stream for video\n" ); - } - - return st; + fprintf( stderr, "Could not allocate a stream for video\n" ); + } + + return st; } static AVFrame *alloc_picture( int pix_fmt, int width, int height ) { // Allocate a frame - AVFrame *picture = avcodec_alloc_frame(); + AVFrame *picture = avcodec_alloc_frame(); // Determine size of the - int size = avpicture_get_size(pix_fmt, width, height); + int size = avpicture_get_size(pix_fmt, width, height); // Allocate the picture buf - uint8_t *picture_buf = av_malloc(size); + uint8_t *picture_buf = av_malloc(size); // If we have both, then fill the image if ( picture != NULL && picture_buf != NULL ) { // Fill the frame with the allocated buffer - avpicture_fill((AVPicture *)picture, picture_buf, pix_fmt, width, height); + avpicture_fill( (AVPicture *)picture, picture_buf, pix_fmt, width, height); } else { // Something failed - clean up what we can - av_free(picture); - av_free(picture_buf); - picture = NULL; + av_free( picture ); + av_free( picture_buf ); + picture = NULL; } - return picture; + return picture; } - + static int open_video(AVFormatContext *oc, AVStream *st) { // Get the codec - AVCodecContext *c = &st->codec; + AVCodecContext *c = &st->codec; - // find the video encoder - AVCodec *codec = avcodec_find_encoder(c->codec_id); + // find the video encoder + AVCodec *codec = avcodec_find_encoder(c->codec_id); // Open the codec safely return codec != NULL && avcodec_open(c, codec) >= 0; @@ -395,7 +423,7 @@ static int open_video(AVFormatContext *oc, AVStream *st) void close_video(AVFormatContext *oc, AVStream *st) { - avcodec_close(&st->codec); + avcodec_close(&st->codec); } /** The main thread - the argument is simply the consumer. @@ -429,14 +457,14 @@ static void *consumer_thread( void *arg ) int samples = 0; // AVFormat audio buffer and frame size - int audio_outbuf_size = 10000; - uint8_t *audio_outbuf = av_malloc( audio_outbuf_size ); + int audio_outbuf_size = 2 * 128 * 1024; + uint8_t *audio_outbuf = av_malloc( audio_outbuf_size ); int audio_input_frame_size = 0; // AVFormat video buffer and frame count int frame_count = 0; - int video_outbuf_size = 200000; - uint8_t *video_outbuf = av_malloc(video_outbuf_size); + int video_outbuf_size = ( 1024 * 1024 ); + uint8_t *video_outbuf = av_malloc( video_outbuf_size ); // Used for the frame properties mlt_frame frame = NULL; @@ -459,24 +487,28 @@ static void *consumer_thread( void *arg ) int count = 0; // Allocate the context - AVFormatContext *oc = av_alloc_format_context(); + AVFormatContext *oc = av_alloc_format_context( ); // Streams - AVStream *audio_st = NULL; + AVStream *audio_st = NULL; AVStream *video_st = NULL; // Time stamps - double audio_pts, video_pts; + double audio_pts, video_pts; // Loop variable int i; // Determine the format - AVOutputFormat *fmt = NULL; + AVOutputFormat *fmt = NULL; char *filename = mlt_properties_get( properties, "target" ); char *format = mlt_properties_get( properties, "format" ); - //char *vcodec = mlt_properties_get( properties, "vcodec" ); - //char *acodec = mlt_properties_get( properties, "acodec" ); + char *vcodec = mlt_properties_get( properties, "vcodec" ); + char *acodec = mlt_properties_get( properties, "acodec" ); + + // Used to store and override codec ids + int audio_codec_id; + int video_codec_id; // Check for user selected format first if ( format != NULL ) @@ -494,43 +526,82 @@ static void *consumer_thread( void *arg ) if ( filename == NULL ) filename = "pipe:"; + // Get the codec ids selected + audio_codec_id = fmt->audio_codec; + video_codec_id = fmt->video_codec; + + // Check for audio codec overides + if ( acodec != NULL ) + { + AVCodec *p = first_avcodec; + while( p != NULL ) + { + if ( !strcmp( p->name, acodec ) && p->type == CODEC_TYPE_AUDIO ) + break; + p = p->next; + } + if ( p != NULL ) + audio_codec_id = p->id; + else + fprintf( stderr, "consumer_avcodec: audio codec %s unrecognised - ignoring\n", acodec ); + } + + // Check for video codec overides + if ( vcodec != NULL ) + { + AVCodec *p = first_avcodec; + while( p != NULL ) + { + if ( !strcmp( p->name, vcodec ) && p->type == CODEC_TYPE_VIDEO ) + break; + p = p->next; + } + if ( p != NULL ) + video_codec_id = p->id; + else + fprintf( stderr, "consumer_avcodec: video codec %s unrecognised - ignoring\n", vcodec ); + } + // Update the output context oc->oformat = fmt; - snprintf( oc->filename, sizeof(oc->filename), "%s", filename ); + snprintf( oc->filename, sizeof(oc->filename), "%s", filename ); // Add audio and video streams - if ( fmt->video_codec != CODEC_ID_NONE ) - video_st = add_video_stream( this, oc, fmt->video_codec ); - if ( fmt->audio_codec != CODEC_ID_NONE ) - audio_st = add_audio_stream( this, oc, fmt->audio_codec ); + if ( fmt->video_codec != CODEC_ID_NONE ) + video_st = add_video_stream( this, oc, video_codec_id ); + if ( fmt->audio_codec != CODEC_ID_NONE ) + audio_st = add_audio_stream( this, oc, audio_codec_id ); // Set the parameters (even though we have none...) - if ( av_set_parameters(oc, NULL) >= 0 ) + if ( av_set_parameters(oc, NULL) >= 0 ) { - if ( video_st && !open_video( oc, video_st ) ) + if ( video_st && !open_video( oc, video_st ) ) video_st = NULL; - if ( audio_st ) - audio_input_frame_size = open_audio( oc, audio_st, audio_outbuf_size ); + if ( audio_st ) + audio_input_frame_size = open_audio( oc, audio_st, audio_outbuf_size ); - // Open the output file, if needed - if ( !( fmt->flags & AVFMT_NOFILE ) ) + // Open the output file, if needed + if ( !( fmt->flags & AVFMT_NOFILE ) ) { - if (url_fopen(&oc->pb, filename, URL_WRONLY) < 0) + if (url_fopen(&oc->pb, filename, URL_RDWR) < 0) { - fprintf(stderr, "Could not open '%s'\n", filename); + fprintf(stderr, "Could not open '%s'\n", filename); mlt_properties_set_int( properties, "running", 0 ); - } - } - - // Write the stream header, if any + } + } + + if ( url_is_streamed( &oc->pb ) ) + fprintf( stderr, "FUCK!\n" ); + + // Write the stream header, if any if ( mlt_properties_get_int( properties, "running" ) ) - av_write_header( oc ); + av_write_header( oc ); } else { - fprintf(stderr, "Invalid output format parameters\n"); + fprintf(stderr, "Invalid output format parameters\n"); mlt_properties_set_int( properties, "running", 0 ); - } + } // Last check - need at least one stream if ( audio_st == NULL && video_st == NULL ) @@ -565,47 +636,47 @@ static void *consumer_thread( void *arg ) // While we have stuff to process, process... while ( 1 ) { - // Compute current audio and video time - if (audio_st) - audio_pts = (double)audio_st->pts.val * oc->pts_num / oc->pts_den; - else - audio_pts = 0.0; - - if (video_st) - video_pts = (double)video_st->pts.val * oc->pts_num / oc->pts_den; - else - video_pts = 0.0; - - // Write interleaved audio and video frames - if ( !video_st || ( video_st && audio_st && audio_pts < video_pts ) ) + // Compute current audio and video time + if (audio_st) + audio_pts = (double)audio_st->pts.val * oc->pts_num / oc->pts_den; + else + audio_pts = 0.0; + + if (video_st) + video_pts = (double)video_st->pts.val * oc->pts_num / oc->pts_den; + else + video_pts = 0.0; + + // Write interleaved audio and video frames + if ( !video_st || ( video_st && audio_st && audio_pts < video_pts ) ) { if ( channels * audio_input_frame_size < sample_fifo_used( fifo ) ) { - int out_size; - AVCodecContext *c; + int out_size; + AVCodecContext *c; - c = &audio_st->codec; + c = &audio_st->codec; sample_fifo_fetch( fifo, buffer, channels * audio_input_frame_size ); - out_size = avcodec_encode_audio( c, audio_outbuf, audio_outbuf_size, buffer ); + out_size = avcodec_encode_audio( c, audio_outbuf, audio_outbuf_size, buffer ); - // Write the compressed frame in the media file - if (av_write_frame(oc, audio_st->index, audio_outbuf, out_size) != 0) - fprintf(stderr, "Error while writing audio frame\n"); + // Write the compressed frame in the media file + if (av_write_frame(oc, audio_st->index, audio_outbuf, out_size) != 0) + fprintf(stderr, "Error while writing audio frame\n"); } else { break; } } - else if ( video_st ) + else if ( video_st ) { if ( mlt_deque_count( queue ) ) { - int out_size, ret; - AVCodecContext *c; - + int out_size, ret; + AVCodecContext *c; + frame = mlt_deque_pop_front( queue ); frame_properties = mlt_frame_properties( frame ); @@ -615,8 +686,8 @@ static void *consumer_thread( void *arg ) break; } - c = &video_st->codec; - + c = &video_st->codec; + if ( mlt_properties_get_int( frame_properties, "rendered" ) ) { int i = 0; @@ -641,26 +712,26 @@ static void *consumer_thread( void *arg ) img_convert( ( AVPicture * )output, PIX_FMT_YUV420P, ( AVPicture * )input, PIX_FMT_YUV422, width, height ); } - - if (oc->oformat->flags & AVFMT_RAWPICTURE) + + if (oc->oformat->flags & AVFMT_RAWPICTURE) { - // raw video case. The API will change slightly in the near future for that - ret = av_write_frame(oc, video_st->index, (uint8_t *)output, sizeof(AVPicture)); - } + // raw video case. The API will change slightly in the near future for that + ret = av_write_frame(oc, video_st->index, (uint8_t *)output, sizeof(AVPicture)); + } else { - // Encode the image - out_size = avcodec_encode_video(c, video_outbuf, video_outbuf_size, output ); + // Encode the image + out_size = avcodec_encode_video(c, video_outbuf, video_outbuf_size, output ); - // If zero size, it means the image was buffered - if (out_size != 0) + // If zero size, it means the image was buffered + if (out_size != 0) { - // write the compressed frame in the media file - // XXX: in case of B frames, the pts is not yet valid - ret = av_write_frame( oc, video_st->index, video_outbuf, out_size ); - } - } - frame_count++; + // write the compressed frame in the media file + // XXX: in case of B frames, the pts is not yet valid + ret = av_write_frame( oc, video_st->index, video_outbuf, out_size ); + } + } + frame_count++; mlt_frame_close( frame ); } else @@ -672,32 +743,32 @@ static void *consumer_thread( void *arg ) } } - // close each codec - if (video_st) - close_video(oc, video_st); - if (audio_st) - close_audio(oc, audio_st); + // close each codec + if (video_st) + close_video(oc, video_st); + if (audio_st) + close_audio(oc, audio_st); + + // Write the trailer, if any + av_write_trailer(oc); - // Write the trailer, if any - av_write_trailer(oc); - - // Free the streams - for(i = 0; i < oc->nb_streams; i++) - av_freep(&oc->streams[i]); + // Free the streams + for(i = 0; i < oc->nb_streams; i++) + av_freep(&oc->streams[i]); // Close the output file - if (!(fmt->flags & AVFMT_NOFILE)) - url_fclose(&oc->pb); + if (!(fmt->flags & AVFMT_NOFILE)) + url_fclose(&oc->pb); // Clean up input and output frames - av_free( output->data[0] ); - av_free( output ); - av_free( input->data[0] ); - av_free( input ); - av_free( video_outbuf ); - - // Free the stream - av_free(oc); + av_free( output->data[0] ); + av_free( output ); + av_free( input->data[0] ); + av_free( input ); + av_free( video_outbuf ); + + // Free the stream + av_free(oc); return NULL; } diff --git a/src/modules/avformat/producer_avformat.c b/src/modules/avformat/producer_avformat.c index 582171ea..f4cb38b6 100644 --- a/src/modules/avformat/producer_avformat.c +++ b/src/modules/avformat/producer_avformat.c @@ -469,7 +469,7 @@ static int producer_get_image( mlt_frame frame, uint8_t **buffer, mlt_image_form current_time = real_timecode; // Handle ignore - if ( current_time < real_timecode ) + if ( ( int )( current_time * 100 ) < ( int )( real_timecode * 100 ) - 7 ) { ignore = 0; got_picture = 0; diff --git a/src/modules/core/Makefile b/src/modules/core/Makefile index 12e2d618..a906252b 100644 --- a/src/modules/core/Makefile +++ b/src/modules/core/Makefile @@ -24,7 +24,7 @@ OBJS = factory.o \ ASM_OBJS = composite_line_yuv_mmx.o -CFLAGS = -O3 -DUSE_MMX -I../../ -Wall -g -D_FILE_OFFSET_BITS=64 -pthread +CFLAGS = -O4 -pipe -ffast-math -fomit-frame-pointer -DUSE_MMX -I../../ -Wall -g -D_FILE_OFFSET_BITS=64 -pthread SRCS := $(OBJS:.o=.c) diff --git a/src/modules/dv/Makefile b/src/modules/dv/Makefile index 493d2ac4..576d4f47 100644 --- a/src/modules/dv/Makefile +++ b/src/modules/dv/Makefile @@ -6,7 +6,7 @@ OBJS = factory.o \ producer_libdv.o \ consumer_libdv.o -CFLAGS = -O3 -I../../ -Wall -g -D_FILE_OFFSET_BITS=64 -pthread +CFLAGS = -O4 -pipe -ffast-math -fomit-frame-pointer -I../../ -Wall -g -D_FILE_OFFSET_BITS=64 -pthread LDFLAGS=-ldv -lpthread diff --git a/src/modules/fezzik/Makefile b/src/modules/fezzik/Makefile index 1cb292e1..137c9c2b 100644 --- a/src/modules/fezzik/Makefile +++ b/src/modules/fezzik/Makefile @@ -6,7 +6,7 @@ OBJS = factory.o \ producer_fezzik.o \ producer_hold.o -CFLAGS = -O3 -I../../ -Wall -g -D_FILE_OFFSET_BITS=64 -pthread +CFLAGS = -O4 -pipe -ffast-math -fomit-frame-pointer -I../../ -Wall -g -D_FILE_OFFSET_BITS=64 -pthread SRCS := $(OBJS:.o=.c) diff --git a/src/modules/ffmpeg/Makefile b/src/modules/ffmpeg/Makefile index 8e0e3ad3..05855711 100644 --- a/src/modules/ffmpeg/Makefile +++ b/src/modules/ffmpeg/Makefile @@ -7,7 +7,7 @@ OBJS = factory.o \ filter_ffmpeg_dub.o \ consumer_ffmpeg.o -CFLAGS = -O3 -I../../ -Wall -g -D_FILE_OFFSET_BITS=64 -pthread +CFLAGS = -O4 -pipe -ffast-math -fomit-frame-pointer -I../../ -Wall -g -D_FILE_OFFSET_BITS=64 -pthread SRCS := $(OBJS:.o=.c) diff --git a/src/modules/gtk2/Makefile b/src/modules/gtk2/Makefile index 77c47658..a37c1842 100644 --- a/src/modules/gtk2/Makefile +++ b/src/modules/gtk2/Makefile @@ -11,7 +11,7 @@ OBJS = factory.o \ ASM_OBJS = have_mmx.o \ scale_line_22_yuv_mmx.o -CFLAGS = -O3 -DUSE_MMX `pkg-config gdk-pixbuf-2.0 --cflags` `pkg-config pangoft2 --cflags` -I../../ -Wall -g -D_FILE_OFFSET_BITS=64 -pthread +CFLAGS = -O4 -pipe -ffast-math -fomit-frame-pointer -DUSE_MMX `pkg-config gdk-pixbuf-2.0 --cflags` `pkg-config pangoft2 --cflags` -I../../ -Wall -g -D_FILE_OFFSET_BITS=64 -pthread LDFLAGS = `pkg-config gdk-pixbuf-2.0 --libs` `pkg-config pangoft2 --libs` diff --git a/src/modules/inigo/Makefile b/src/modules/inigo/Makefile index 31c4955e..8ea9c243 100644 --- a/src/modules/inigo/Makefile +++ b/src/modules/inigo/Makefile @@ -5,7 +5,7 @@ TARGET = ../libmltinigo.so OBJS = factory.o \ producer_inigo.o -CFLAGS = -O3 -I../../ -Wall -g -D_FILE_OFFSET_BITS=64 -pthread +CFLAGS = -O4 -pipe -ffast-math -fomit-frame-pointer -I../../ -Wall -g -D_FILE_OFFSET_BITS=64 -pthread SRCS := $(OBJS:.o=.c) diff --git a/src/modules/resample/Makefile b/src/modules/resample/Makefile index 83ffb3d9..78110506 100644 --- a/src/modules/resample/Makefile +++ b/src/modules/resample/Makefile @@ -5,7 +5,7 @@ TARGET = ../libmltresample.so OBJS = factory.o \ filter_resample.o -CFLAGS = -O3 -I../../ -Wall -g +CFLAGS = -O4 -pipe -ffast-math -fomit-frame-pointer -I../../ -Wall -g LDFLAGS= -lsamplerate diff --git a/src/modules/sdl/Makefile b/src/modules/sdl/Makefile index 1571a297..19ef216c 100644 --- a/src/modules/sdl/Makefile +++ b/src/modules/sdl/Makefile @@ -5,7 +5,7 @@ TARGET = ../libmltsdl.so OBJS = factory.o \ consumer_sdl.o -CFLAGS = -O3 -I../../ `sdl-config --cflags` -Wall -g -D_FILE_OFFSET_BITS=64 -pthread +CFLAGS = -O4 -pipe -ffast-math -fomit-frame-pointer -I../../ `sdl-config --cflags` -Wall -g -D_FILE_OFFSET_BITS=64 -pthread LDFLAGS= `sdl-config --libs` diff --git a/src/modules/vorbis/Makefile b/src/modules/vorbis/Makefile index fabf4d7b..3d190241 100644 --- a/src/modules/vorbis/Makefile +++ b/src/modules/vorbis/Makefile @@ -5,7 +5,7 @@ TARGET = ../libmltvorbis.so OBJS = factory.o \ producer_vorbis.o -CFLAGS = -O3 -I../../ -Wall -g -D_FILE_OFFSET_BITS=64 +CFLAGS = -O4 -pipe -ffast-math -fomit-frame-pointer -I../../ -Wall -g -D_FILE_OFFSET_BITS=64 LDFLAGS = -lvorbisfile -lvorbis diff --git a/src/modules/westley/Makefile b/src/modules/westley/Makefile index a5d5d184..160181b6 100644 --- a/src/modules/westley/Makefile +++ b/src/modules/westley/Makefile @@ -6,7 +6,7 @@ OBJS = factory.o \ consumer_westley.o \ producer_westley.o -CFLAGS = -O3 -I../../ -Wall -g -D_FILE_OFFSET_BITS=64 -pthread `xml2-config --cflags` +CFLAGS = -O4 -pipe -ffast-math -fomit-frame-pointer -I../../ -Wall -g -D_FILE_OFFSET_BITS=64 -pthread `xml2-config --cflags` LDFLAGS = `xml2-config --libs` diff --git a/src/modules/xine/Makefile b/src/modules/xine/Makefile index 9a965929..2f82a13f 100644 --- a/src/modules/xine/Makefile +++ b/src/modules/xine/Makefile @@ -7,7 +7,7 @@ OBJS = factory.o \ cpu_accel.o \ filter_deinterlace.o -CFLAGS = -O3 -I../../ -Wall -g -D_FILE_OFFSET_BITS=64 -pthread -DARCH_X86 +CFLAGS = -O4 -pipe -ffast-math -fomit-frame-pointer -I../../ -Wall -g -D_FILE_OFFSET_BITS=64 -pthread -DARCH_X86 SRCS := $(OBJS:.o=.c) diff --git a/src/tests/Makefile b/src/tests/Makefile index 92ef0eb9..0dd5bb8e 100644 --- a/src/tests/Makefile +++ b/src/tests/Makefile @@ -2,7 +2,7 @@ include ../../config.mak TARGET = dan charlie pango pixbuf dissolve luma -CFLAGS = -O3 -I .. -Wall -rdynamic -pthread +CFLAGS = -O4 -pipe -ffast-math -fomit-frame-pointer -I .. -Wall -rdynamic -pthread LDFLAGS = -L ../framework -L ../modules -lmlt -lmltdv -lmltsdl diff --git a/src/valerie/Makefile b/src/valerie/Makefile index d7ff25cc..12b835fb 100644 --- a/src/valerie/Makefile +++ b/src/valerie/Makefile @@ -14,7 +14,7 @@ OBJS = valerie.o \ SRCS := $(OBJS:.o=.c) -CFLAGS=-O3 -Wall -g -D_FILE_OFFSET_BITS=64 -pthread +CFLAGS=-O4 -pipe -ffast-math -fomit-frame-pointer -Wall -g -D_FILE_OFFSET_BITS=64 -pthread LDFLAGS=-ldv -lpthread