X-Git-Url: http://research.m1stereo.tv/gitweb?a=blobdiff_plain;f=src%2Fmodules%2Favformat%2Fproducer_avformat.c;h=bd6927a923cf861dd7fcee99a634f469dd3beac8;hb=f44c1d4653f43c8e7a63e6c3895f6f1f0ee0103b;hp=f72d9fa7f4bbe99b7b01321ed38b8bf8d82047fa;hpb=21209debb562b399069257566d765c45ea7180b0;p=melted diff --git a/src/modules/avformat/producer_avformat.c b/src/modules/avformat/producer_avformat.c index f72d9fa..bd6927a 100644 --- a/src/modules/avformat/producer_avformat.c +++ b/src/modules/avformat/producer_avformat.c @@ -173,6 +173,9 @@ static int producer_open( mlt_producer this, char *file ) // AV option (0 = both, 1 = video, 2 = audio) int av = 0; + // Setting lowest log level + av_log_set_level( -1 ); + // Only if there is not a protocol specification that avformat can handle if ( mrl && !url_exist( file ) ) { @@ -259,6 +262,7 @@ static int producer_open( mlt_producer this, char *file ) // We will default to the first audio and video streams found int audio_index = -1; int video_index = -1; + int av_bypass = 0; // Now set properties where we can (use default unknowns if required) if ( context->duration != AV_NOPTS_VALUE ) @@ -276,15 +280,17 @@ static int producer_open( mlt_producer this, char *file ) mlt_properties_set_double( properties, "start_time", context->start_time ); // Check if we're seekable (something funny about mpeg here :-/) - if ( strcmp( file, "pipe:" ) ) + if ( strcmp( file, "pipe:" ) && strncmp( file, "http://", 6 ) ) mlt_properties_set_int( properties, "seekable", av_seek_frame( context, -1, mlt_properties_get_double( properties, "start_time" ) ) >= 0 ); + else + av_bypass = 1; // 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 ); // We're going to cheat here - for a/v files, we will have two contexts (reasoning will be clear later) - if ( av == 0 && strcmp( file, "pipe:" ) && audio_index != -1 && video_index != -1 ) + if ( av == 0 && !av_bypass && audio_index != -1 && video_index != -1 ) { // We'll use the open one as our video_context mlt_properties_set_data( properties, "video_context", context, 0, producer_file_close, NULL ); @@ -311,6 +317,8 @@ static int producer_open( mlt_producer this, char *file ) // Something has gone wrong error = -1; } + + mlt_properties_set_int( properties, "av_bypass", av_bypass ); } } @@ -392,6 +400,12 @@ static inline void convert_image( AVFrame *frame, uint8_t *buffer, int pix_fmt, pict.linesize[2] = width >> 1; img_convert( &pict, PIX_FMT_YUV420P, (AVPicture *)frame, pix_fmt, width, height ); } + else if ( format == mlt_image_rgb24 ) + { + AVPicture output; + avpicture_fill( &output, buffer, PIX_FMT_RGB24, width, height ); + img_convert( &output, PIX_FMT_RGB24, (AVPicture *)frame, pix_fmt, width, height ); + } else { AVPicture output; @@ -459,13 +473,26 @@ static int producer_get_image( mlt_frame frame, uint8_t **buffer, mlt_image_form // Generate the size in bytes int size = 0; + // Hopefully provide better support for streams... + int av_bypass = mlt_properties_get_int( properties, "av_bypass" ); + // Set the result arguments that we know here (only *buffer is now required) - if ( *format != mlt_image_yuv422 && *format != mlt_image_yuv420p ) - *format = mlt_image_yuv422; *width = codec_context->width; *height = codec_context->height; - size = *width * ( *height + 1 ) * 2; + switch ( *format ) + { + case mlt_image_yuv420p: + size = *width * 3 * ( *height + 1 ) / 2; + break; + case mlt_image_rgb24: + size = *width * ( *height + 1 ) * 3; + break; + default: + *format = mlt_image_yuv422; + size = *width * ( *height + 1 ) * 2; + break; + } // Set this on the frame properties mlt_properties_set_int( frame_properties, "width", *width ); @@ -487,7 +514,7 @@ static int producer_get_image( mlt_frame frame, uint8_t **buffer, mlt_image_form // Fast forward - seeking is inefficient for small distances - just ignore following frames ignore = position - expected; } - else if ( codec_context->gop_size == 0 || ( position < expected || position - expected >= 12 ) ) + else if ( seekable && ( position < expected || position - expected >= 12 ) ) { // Set to the real timecode av_seek_frame( context, -1, mlt_properties_get_double( properties, "start_time" ) + real_timecode * 1000000.0 ); @@ -502,7 +529,7 @@ static int producer_get_image( mlt_frame frame, uint8_t **buffer, mlt_image_form // Duplicate the last image if necessary if ( av_frame != NULL && ( paused || mlt_properties_get_double( properties, "current_time" ) >= real_timecode ) && - strcmp( mlt_properties_get( properties, "resource" ), "pipe:" ) ) + av_bypass == 0 ) { // Duplicate it convert_image( av_frame, *buffer, codec_context->pix_fmt, *format, *width, *height ); @@ -514,6 +541,11 @@ static int producer_get_image( mlt_frame frame, uint8_t **buffer, mlt_image_form { int ret = 0; int got_picture = 0; + int must_decode = 1; + + // Temporary hack to improve intra frame only + if ( !strcmp( codec_context->codec->name, "mjpeg" ) ) + must_decode = 0; memset( &pkt, 0, sizeof( pkt ) ); @@ -522,7 +554,6 @@ static int producer_get_image( mlt_frame frame, uint8_t **buffer, mlt_image_form { av_frame = calloc( 1, sizeof( AVFrame ) ); mlt_properties_set_data( properties, "av_frame", av_frame, 0, free, NULL ); - paused = 0; } while( ret >= 0 && !got_picture ) @@ -533,16 +564,18 @@ static int producer_get_image( mlt_frame frame, uint8_t **buffer, mlt_image_form // We only deal with video from the selected video_index 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; + else + current_time = real_timecode; + // Decode the image - ret = avcodec_decode_video( codec_context, av_frame, &got_picture, pkt.data, pkt.size ); + if ( must_decode || current_time >= real_timecode ) + ret = avcodec_decode_video( codec_context, av_frame, &got_picture, pkt.data, pkt.size ); if ( got_picture ) { - if ( pkt.pts != AV_NOPTS_VALUE ) - current_time = ( double )pkt.pts / 1000000.0; - else - current_time = real_timecode; - // Handle ignore if ( ( int )( current_time * 100 ) < ( int )( real_timecode * 100 ) - 7 ) { @@ -551,7 +584,6 @@ static int producer_get_image( mlt_frame frame, uint8_t **buffer, mlt_image_form } else if ( current_time >= real_timecode ) { - //current_time = real_timecode; ignore = 0; } else if ( ignore -- )