From: lilo_booter Date: Thu, 10 Nov 2005 12:26:32 +0000 (+0000) Subject: Allows aac output, corrects ntsc sample collection, and picks up known info streams X-Git-Url: http://research.m1stereo.tv/gitweb?a=commitdiff_plain;h=35bfd1603d15f70354524f4d59eab2f7b4eb4946;p=melted Allows aac output, corrects ntsc sample collection, and picks up known info streams git-svn-id: https://mlt.svn.sourceforge.net/svnroot/mlt/trunk/mlt@861 d19143bc-622f-0410-bfdd-b5b2a6649095 --- diff --git a/src/modules/avformat/consumer_avformat.c b/src/modules/avformat/consumer_avformat.c index dfa1c6b..612e88b 100644 --- a/src/modules/avformat/consumer_avformat.c +++ b/src/modules/avformat/consumer_avformat.c @@ -331,6 +331,9 @@ static AVStream *add_audio_stream( mlt_consumer this, AVFormatContext *oc, int c c->sample_rate = mlt_properties_get_int( properties, "frequency" ); c->channels = mlt_properties_get_int( properties, "channels" ); + if (oc->oformat->flags & AVFMT_GLOBALHEADER) + c->flags |= CODEC_FLAG_GLOBAL_HEADER; + // Allow the user to override the audio fourcc if ( mlt_properties_get( properties, "afourcc" ) ) { @@ -802,7 +805,7 @@ static void *consumer_thread( void *arg ) // Get audio and append to the fifo if ( !terminated && audio_st ) { - samples = mlt_sample_calculator( fps, frequency, count ); + samples = mlt_sample_calculator( fps, frequency, count ++ ); mlt_frame_get_audio( frame, &pcm, &aud_fmt, &frequency, &channels, &samples ); // Create the fifo if we don't have one @@ -855,14 +858,15 @@ static void *consumer_thread( void *arg ) pkt.size = avcodec_encode_audio( c, audio_outbuf, audio_outbuf_size, buffer ); // Write the compressed frame in the media file - if ( c->coded_frame ) + if ( c->coded_frame && c->coded_frame->pts != AV_NOPTS_VALUE ) pkt.pts = av_rescale_q( c->coded_frame->pts, c->time_base, audio_st->time_base ); pkt.flags |= PKT_FLAG_KEY; pkt.stream_index= audio_st->index; pkt.data= audio_outbuf; - if ( av_interleaved_write_frame( oc, &pkt ) != 0) - fprintf(stderr, "Error while writing audio frame\n"); + if ( pkt.size ) + if ( av_interleaved_write_frame( oc, &pkt ) != 0) + fprintf(stderr, "Error while writing audio frame\n"); audio_pts += c->frame_size; } @@ -966,12 +970,12 @@ static void *consumer_thread( void *arg ) 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 (out_size > 0) { AVPacket pkt; av_init_packet( &pkt ); - if ( c->coded_frame ) + if ( c->coded_frame && c->coded_frame->pts != AV_NOPTS_VALUE ) pkt.pts= av_rescale_q( c->coded_frame->pts, c->time_base, video_st->time_base ); if( c->coded_frame && c->coded_frame->key_frame ) pkt.flags |= PKT_FLAG_KEY; @@ -983,6 +987,10 @@ static void *consumer_thread( void *arg ) ret = av_interleaved_write_frame(oc, &pkt); video_pts += c->frame_size; } + else + { + fprintf( stderr, "Error with video encode\n" ); + } } frame_count++; mlt_frame_close( frame ); diff --git a/src/modules/avformat/producer_avformat.c b/src/modules/avformat/producer_avformat.c index 8cbdad4..c6c0135 100644 --- a/src/modules/avformat/producer_avformat.c +++ b/src/modules/avformat/producer_avformat.c @@ -287,6 +287,15 @@ static int producer_open( mlt_producer this, char *file ) // Store selected audio and video indexes on properties mlt_properties_set_int( properties, "audio_index", audio_index ); mlt_properties_set_int( properties, "video_index", video_index ); + + // Fetch the width, height and aspect ratio + if ( video_index != -1 ) + { + AVCodecContext *codec_context = context->streams[ video_index ]->codec; + mlt_properties_set_int( properties, "width", codec_context->width ); + mlt_properties_set_int( properties, "height", codec_context->height ); + mlt_properties_set_double( properties, "aspect_ratio", av_q2d( codec_context->sample_aspect_ratio ) ); + } // We're going to cheat here - for a/v files, we will have two contexts (reasoning will be clear later) if ( av == 0 && !av_bypass && audio_index != -1 && video_index != -1 )