X-Git-Url: http://research.m1stereo.tv/gitweb?a=blobdiff_plain;f=src%2Fmodules%2Favformat%2Fconsumer_avformat.c;h=e5a4dddfef98ed2d9a4521d05bbdfaa28caa6435;hb=2a2669b620e293e8963205c86606618789951eed;hp=a7fd977a499980ce6849fe08cf1c60d56a764c85;hpb=f44c1d4653f43c8e7a63e6c3895f6f1f0ee0103b;p=melted diff --git a/src/modules/avformat/consumer_avformat.c b/src/modules/avformat/consumer_avformat.c index a7fd977..e5a4ddd 100644 --- a/src/modules/avformat/consumer_avformat.c +++ b/src/modules/avformat/consumer_avformat.c @@ -141,7 +141,7 @@ mlt_consumer consumer_avformat_init( char *arg ) if ( this != NULL ) { // Get properties from the consumer - mlt_properties properties = mlt_consumer_properties( this ); + mlt_properties properties = MLT_CONSUMER_PROPERTIES( this ); // Assign close callback this->close = consumer_close; @@ -228,7 +228,7 @@ mlt_consumer consumer_avformat_init( char *arg ) static int consumer_start( mlt_consumer this ) { // Get the properties - mlt_properties properties = mlt_consumer_properties( this ); + mlt_properties properties = MLT_CONSUMER_PROPERTIES( this ); // Check that we're not already running if ( !mlt_properties_get_int( properties, "running" ) ) @@ -285,7 +285,7 @@ static int consumer_start( mlt_consumer this ) static int consumer_stop( mlt_consumer this ) { // Get the properties - mlt_properties properties = mlt_consumer_properties( this ); + mlt_properties properties = MLT_CONSUMER_PROPERTIES( this ); // Check that we're running if ( mlt_properties_get_int( properties, "running" ) ) @@ -309,7 +309,7 @@ static int consumer_stop( mlt_consumer this ) static int consumer_is_stopped( mlt_consumer this ) { // Get the properties - mlt_properties properties = mlt_consumer_properties( this ); + mlt_properties properties = MLT_CONSUMER_PROPERTIES( this ); return !mlt_properties_get_int( properties, "running" ); } @@ -319,7 +319,7 @@ static int consumer_is_stopped( mlt_consumer this ) static AVStream *add_audio_stream( mlt_consumer this, AVFormatContext *oc, int codec_id ) { // Get the properties - mlt_properties properties = mlt_consumer_properties( this ); + mlt_properties properties = MLT_CONSUMER_PROPERTIES( this ); // Create a new stream AVStream *st = av_new_stream( oc, 1 ); @@ -405,7 +405,7 @@ static void close_audio( AVFormatContext *oc, AVStream *st ) static AVStream *add_video_stream( mlt_consumer this, AVFormatContext *oc, int codec_id ) { // Get the properties - mlt_properties properties = mlt_consumer_properties( this ); + mlt_properties properties = MLT_CONSUMER_PROPERTIES( this ); // Create a new stream AVStream *st = av_new_stream( oc, 0 ); @@ -564,7 +564,7 @@ static void *consumer_thread( void *arg ) mlt_consumer this = arg; // Get the properties - mlt_properties properties = mlt_consumer_properties( this ); + mlt_properties properties = MLT_CONSUMER_PROPERTIES( this ); // Get the terminate on pause property int terminate_on_pause = mlt_properties_get_int( properties, "terminate_on_pause" ); @@ -760,7 +760,7 @@ static void *consumer_thread( void *arg ) frames ++; // Default audio args - frame_properties = mlt_frame_properties( frame ); + frame_properties = MLT_FRAME_PROPERTIES( frame ); // Check for the terminated condition terminated = terminate_on_pause && mlt_properties_get_double( frame_properties, "_speed" ) == 0.0; @@ -778,6 +778,9 @@ static void *consumer_thread( void *arg ) mlt_properties_set_data( properties, "sample_fifo", fifo, 0, ( mlt_destructor )sample_fifo_close, NULL ); } + if ( mlt_properties_get_double( frame_properties, "_speed" ) != 1.0 ) + memset( pcm, 0, samples * channels * 2 ); + // Append the samples sample_fifo_append( fifo, pcm, samples * channels ); total_time += ( samples * 1000000 ) / frequency; @@ -819,12 +822,13 @@ 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 - pkt.pts= c->coded_frame->pts; + if ( c->coded_frame ) + pkt.pts= c->coded_frame->pts; pkt.flags |= PKT_FLAG_KEY; pkt.stream_index= audio_st->index; pkt.data= audio_outbuf; - if ( av_write_frame( oc, &pkt ) != 0) + if ( av_interleaved_write_frame( oc, &pkt ) != 0) fprintf(stderr, "Error while writing audio frame\n"); } else @@ -840,7 +844,7 @@ static void *consumer_thread( void *arg ) AVCodecContext *c; frame = mlt_deque_pop_front( queue ); - frame_properties = mlt_frame_properties( frame ); + frame_properties = MLT_FRAME_PROPERTIES( frame ); c = &video_st->codec; @@ -851,6 +855,15 @@ static void *consumer_thread( void *arg ) uint8_t *p; uint8_t *q; + mlt_events_fire( properties, "consumer-frame-show", frame, NULL ); + + // This will cause some fx to go awry.... + if ( mlt_properties_get_int( properties, "transcode" ) ) + { + mlt_properties_set_int( MLT_FRAME_PROPERTIES( frame ), "normalised_width", img_height * 4.0 / 3.0 ); + mlt_properties_set_int( MLT_FRAME_PROPERTIES( frame ), "normalised_height", img_height ); + } + mlt_frame_get_image( frame, &image, &img_fmt, &img_width, &img_height, 0 ); q = image; @@ -896,7 +909,8 @@ static void *consumer_thread( void *arg ) AVPacket pkt; av_init_packet( &pkt ); - pkt.pts= c->coded_frame->pts; + if ( c->coded_frame ) + pkt.pts= c->coded_frame->pts; if(c->coded_frame->key_frame) pkt.flags |= PKT_FLAG_KEY; pkt.stream_index= video_st->index; @@ -904,7 +918,7 @@ static void *consumer_thread( void *arg ) pkt.size= out_size; // write the compressed frame in the media file - ret = av_write_frame(oc, &pkt); + ret = av_interleaved_write_frame(oc, &pkt); } } frame_count++; @@ -917,7 +931,7 @@ static void *consumer_thread( void *arg ) } } - if ( real_time_output && frames % 25 == 0 ) + if ( real_time_output && frames % 12 == 0 ) { long passed = time_difference( &ante ); if ( fifo != NULL )