]> git.sesse.net Git - mlt/commitdiff
Allows aac output, corrects ntsc sample collection, and picks up known info streams
authorlilo_booter <lilo_booter@d19143bc-622f-0410-bfdd-b5b2a6649095>
Thu, 10 Nov 2005 12:26:32 +0000 (12:26 +0000)
committerlilo_booter <lilo_booter@d19143bc-622f-0410-bfdd-b5b2a6649095>
Thu, 10 Nov 2005 12:26:32 +0000 (12:26 +0000)
git-svn-id: https://mlt.svn.sourceforge.net/svnroot/mlt/trunk/mlt@861 d19143bc-622f-0410-bfdd-b5b2a6649095

src/modules/avformat/consumer_avformat.c
src/modules/avformat/producer_avformat.c

index dfa1c6b5db54fd96a5458edea40ca94d62f20dcb..612e88b29b10a3988cba6ec39e7e5602149c7f60 100644 (file)
@@ -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 );
index 8cbdad442c20077ba6d62422e78cf2354e18b1f8..c6c013553409fe25da7347efc12e0733e0fcebe9 100644 (file)
@@ -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 )