FFMPEG revisions to match current CVS (part 1)
authorlilo_booter <lilo_booter@d19143bc-622f-0410-bfdd-b5b2a6649095>
Wed, 4 May 2005 11:28:12 +0000 (11:28 +0000)
committerlilo_booter <lilo_booter@d19143bc-622f-0410-bfdd-b5b2a6649095>
Wed, 4 May 2005 11:28:12 +0000 (11:28 +0000)
git-svn-id: https://mlt.svn.sourceforge.net/svnroot/mlt/trunk/mlt@718 d19143bc-622f-0410-bfdd-b5b2a6649095

src/modules/avformat/Makefile
src/modules/avformat/configure
src/modules/avformat/consumer_avformat.c
src/modules/avformat/factory.c
src/modules/avformat/producer_avformat.c

index d307bc2..9354339 100644 (file)
@@ -1,7 +1,7 @@
 include ../../../config.mak
 include config.mak
 
-TARGET = ../libmltavformat$(LIBSUF)
+TARGET = ../libmltffmpeg$(LIBSUF)
 
 OBJS = factory.o \
           producer_avformat.o \
@@ -50,8 +50,8 @@ clean:
 install: all
                install -m 755 $(TARGET) "$(prefix)/share/mlt/modules"
                if [ $(LOCAL_FFMPEG) ] ; then \
-                       install -m 755 ../../framework/libmltavcodec.$(LIBSUF) "$(prefix)/share/mlt/modules" ; \
-                       install -m 755 ../../framework/libmltavformat.$(LIBSUF) "$(prefix)/share/mlt/modules" ; \
+                       install -m 755 ../../framework/libmltavcodec$(LIBSUF) "$(prefix)/share/mlt/modules" ; \
+                       install -m 755 ../../framework/libmltavformat$(LIBSUF) "$(prefix)/share/mlt/modules" ; \
                fi
 
 ifneq ($(wildcard .depend),)
index b6a94e3..53276db 100755 (executable)
@@ -88,17 +88,17 @@ else
        echo "EXTRA_LIBS=$extra_libs" >> config.mak
 
 cat << EOF >> ../producers.dat
-avformat               libmltavformat$LIBSUF
+avformat               libmltffmpeg$LIBSUF
 EOF
 
 cat << EOF >> ../filters.dat
-avdeinterlace  libmltavformat$LIBSUF
-avresample             libmltavformat$LIBSUF
-avcolour_space libmltavformat$LIBSUF
+avdeinterlace  libmltffmpeg$LIBSUF
+avresample             libmltffmpeg$LIBSUF
+avcolour_space libmltffmpeg$LIBSUF
 EOF
 
 cat << EOF >> ../consumers.dat
-avformat               libmltavformat$LIBSUF
+avformat               libmltffmpeg$LIBSUF
 EOF
 
 fi
index 021c501..d1d8106 100644 (file)
@@ -416,10 +416,11 @@ static AVStream *add_video_stream( mlt_consumer this, AVFormatContext *oc, int c
                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->time_base.den = mlt_properties_get_double( properties, "fps" );
+               c->time_base.num = mlt_properties_get_double( properties, "frame_rate_base" );
+               c->time_base.num = 1;
                c->gop_size = mlt_properties_get_int( properties, "gop_size" );
+               c->pix_fmt = PIX_FMT_YUV420P;
 
                if ( mlt_properties_get_int( properties, "b_frames" ) )
                {
@@ -625,7 +626,8 @@ static void *consumer_thread( void *arg )
        AVStream *video_st = NULL;
 
        // Time stamps
-       double audio_pts, video_pts;
+       double audio_pts = 0;
+       double video_pts = 0;
 
        // Loop variable
        int i;
@@ -791,16 +793,15 @@ 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 * audio_st->time_base.num / audio_st->time_base.den;
+                       if (audio_st)
+                               audio_pts = (double)audio_st->pts.val * audio_st->time_base.num / audio_st->time_base.den;
                        else
-                               audio_pts = 0.0;
-       
+                               audio_pts = 0.0;
+        
                        if (video_st)
-                               video_pts = (double)video_st->pts.val * video_st->time_base.num / video_st->time_base.den;
-                       else
-                               video_pts = 0.0;
+                               video_pts = (double)video_st->pts.val * video_st->time_base.num / video_st->time_base.den;
+                       else
+                               video_pts = 0.0;
 
                        // Write interleaved audio and video frames
                        if ( !video_st || ( video_st && audio_st && audio_pts < video_pts ) )
@@ -818,13 +819,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 )
-                                               pkt.pts= c->coded_frame->pts;
+                                               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");
+
+                                       audio_pts += c->frame_size;
                                }
                                else
                                {
@@ -889,6 +892,7 @@ static void *consumer_thread( void *arg )
                                                pkt.size= sizeof(AVPicture);
 
                                                ret = av_write_frame(oc, &pkt);
+                                               video_pts += c->frame_size;
                                        } 
                                        else 
                                        {
@@ -905,7 +909,7 @@ static void *consumer_thread( void *arg )
                                                        av_init_packet( &pkt );
 
                                                        if ( c->coded_frame )
-                                                               pkt.pts= c->coded_frame->pts;
+                                                               pkt.pts= av_rescale_q( c->coded_frame->pts, c->time_base, video_st->time_base );
                                                        if(c->coded_frame->key_frame)
                                                                pkt.flags |= PKT_FLAG_KEY;
                                                        pkt.stream_index= video_st->index;
@@ -914,6 +918,7 @@ static void *consumer_thread( void *arg )
 
                                        // write the compressed frame in the media file
                                                        ret = av_interleaved_write_frame(oc, &pkt);
+                                                       video_pts += c->frame_size;
                                                } 
                                        }
                                        frame_count++;
index 49d6b93..9c413ae 100644 (file)
@@ -87,7 +87,7 @@ static void avformat_init( )
                pthread_mutex_init( &avformat_mutex, NULL );
                av_register_all( );
                mlt_factory_register_for_clean_up( NULL, avformat_destroy );
-               av_log_set_level( -1 );
+               //av_log_set_level( -1 );
        }
 }
 
index a9979c1..f4ccb01 100644 (file)
@@ -196,8 +196,7 @@ static int producer_open( mlt_producer this, char *file )
                        // These are required by video4linux (defaults)
                        params->width = 640;
                        params->height = 480;
-                       params->frame_rate = 25;
-                       params->frame_rate_base = 1;
+                       params->time_base= (AVRational){1,25};
                        params->device = file;
                        params->channels = 2;
                        params->sample_rate = 48000;
@@ -218,9 +217,9 @@ static int producer_open( mlt_producer this, char *file )
                                if ( t )
                                        t[0] = 0;
                                if ( !strcmp( name, "frame_rate" ) )
-                                       params->frame_rate = atoi( value );
+                                       params->time_base.den = atoi( value );
                                else if ( !strcmp( name, "frame_rate_base" ) )
-                                       params->frame_rate_base = atoi( value );
+                                       params->time_base.num = atoi( value );
                                else if ( !strcmp( name, "sample_rate" ) )
                                        params->sample_rate = atoi( value );
                                else if ( !strcmp( name, "channels" ) )
@@ -565,8 +564,8 @@ static int producer_get_image( mlt_frame frame, uint8_t **buffer, mlt_image_form
                        if ( ret >= 0 && pkt.stream_index == index && pkt.size > 0 )
                        {
                                // Determine time code of the packet
-                               if ( pkt.pts != AV_NOPTS_VALUE )
-                                       current_time = ( double )pkt.pts / 1000000.0;
+                               if ( pkt.dts != AV_NOPTS_VALUE )
+                                       current_time = av_q2d( stream->time_base ) * pkt.dts;
                                else
                                        current_time = real_timecode;
 
@@ -694,10 +693,8 @@ static void producer_set_up_video( mlt_producer this, mlt_frame frame )
                                mlt_properties_set_double( properties, "aspect_ratio", is_pal ? 59.0/54.0 : 10.0/11.0 );
                        }
 
-                       //fprintf( stderr, "AVFORMAT: sample aspect %f %dx%d\n", av_q2d( codec_context->sample_aspect_ratio ), codec_context->width, codec_context->height );
-
                        // Determine the fps
-                       source_fps = ( double )codec_context->frame_rate / ( codec_context->frame_rate_base == 0 ? 1 : codec_context->frame_rate_base );
+                       source_fps = ( double )codec_context->time_base.den / ( codec_context->time_base.num == 0 ? 1 : codec_context->time_base.num );
 
                        // We'll use fps if it's available
                        if ( source_fps > 0 && source_fps < 30 )
@@ -888,7 +885,7 @@ static int producer_get_audio( mlt_frame frame, int16_t **buffer, mlt_audio_form
                                }
 
                                // If we're behind, ignore this packet
-                               float current_pts = (float)pkt.pts / 1000000.0;
+                               float current_pts = av_q2d( stream->time_base ) * pkt.pts;
                                if ( seekable && ( !ignore && current_pts <= ( real_timecode - 0.02 ) ) )
                                        ignore = 1;
                        }