X-Git-Url: http://research.m1stereo.tv/gitweb?a=blobdiff_plain;f=src%2Fmodules%2Favformat%2Fconsumer_avformat.c;h=f5a7cc2b902d829b6c5e0f162375d036b13b041f;hb=f00476101550ec7d8e863f6516aa83bc1b524570;hp=b21ba272962ca676db1cdd981d4945cef2f051a1;hpb=f68e93d2fc602f49044169ad4fcc6f91294375ee;p=melted diff --git a/src/modules/avformat/consumer_avformat.c b/src/modules/avformat/consumer_avformat.c index b21ba27..f5a7cc2 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" ); @@ -663,7 +663,7 @@ static void *consumer_thread( void *arg ) fmt = guess_format( "mpeg", NULL, NULL ); // We need a filename - default to stdout? - if ( filename == NULL ) + if ( filename == NULL || !strcmp( filename, "" ) ) filename = "pipe:"; // Get the codec ids selected @@ -723,7 +723,7 @@ static void *consumer_thread( void *arg ) // Open the output file, if needed if ( !( fmt->flags & AVFMT_NOFILE ) ) { - if (url_fopen(&oc->pb, filename, URL_RDWR) < 0) + if (url_fopen(&oc->pb, filename, URL_WRONLY) < 0) { fprintf(stderr, "Could not open '%s'\n", filename); mlt_properties_set_int( properties, "running", 0 ); @@ -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; @@ -819,12 +819,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 +841,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 +852,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 +906,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 +915,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++; @@ -920,8 +931,11 @@ static void *consumer_thread( void *arg ) if ( real_time_output && frames % 25 == 0 ) { long passed = time_difference( &ante ); - long pending = ( ( ( long )sample_fifo_used( fifo ) * 1000 ) / frequency ) * 1000; - passed -= pending; + if ( fifo != NULL ) + { + long pending = ( ( ( long )sample_fifo_used( fifo ) * 1000 ) / frequency ) * 1000; + passed -= pending; + } if ( passed < total_time ) { long total = ( total_time - passed ); @@ -962,6 +976,8 @@ static void *consumer_thread( void *arg ) // Just in case we terminated on pause mlt_properties_set_int( properties, "running", 0 ); + mlt_consumer_stopped( this ); + return NULL; }