X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=src%2Fmodules%2Favformat%2Fproducer_avformat.c;h=c0b226ef433880db0f34385ad98bfbd7425ed1c3;hb=02a0ab41399ce94753e94d1a2229e43d09370463;hp=4fc105230ef2969e00cf842880054757d245a57c;hpb=6834acd8779dbf5224a294c22a6d5f69f1903d3e;p=mlt diff --git a/src/modules/avformat/producer_avformat.c b/src/modules/avformat/producer_avformat.c index 4fc10523..c0b226ef 100644 --- a/src/modules/avformat/producer_avformat.c +++ b/src/modules/avformat/producer_avformat.c @@ -1,6 +1,6 @@ /* * producer_avformat.c -- avformat producer - * Copyright (C) 2003-2012 Ushodaya Enterprises Limited + * Copyright (C) 2003-2014 Ushodaya Enterprises Limited * Author: Charles Yates * Author: Dan Dennedy * Much code borrowed from ffmpeg.c: Copyright (c) 2000-2003 Fabrice Bellard @@ -1189,7 +1189,8 @@ static int convert_image( producer_avformat self, AVFrame *frame, uint8_t *buffe width, height, PIX_FMT_RGB24, flags | SWS_FULL_CHR_H_INT, NULL, NULL, NULL); AVPicture output; avpicture_fill( &output, buffer, PIX_FMT_RGB24, width, height ); - set_luma_transfer( context, self->yuv_colorspace, profile->colorspace, self->full_luma ); + // libswscale wants the RGB colorspace to be SWS_CS_DEFAULT, which is = SWS_CS_ITU601. + set_luma_transfer( context, self->yuv_colorspace, 601, self->full_luma ); sws_scale( context, (const uint8_t* const*) frame->data, frame->linesize, 0, height, output.data, output.linesize); sws_freeContext( context ); @@ -1200,7 +1201,8 @@ static int convert_image( producer_avformat self, AVFrame *frame, uint8_t *buffe width, height, PIX_FMT_RGBA, flags | SWS_FULL_CHR_H_INT, NULL, NULL, NULL); AVPicture output; avpicture_fill( &output, buffer, PIX_FMT_RGBA, width, height ); - set_luma_transfer( context, self->yuv_colorspace, profile->colorspace, self->full_luma ); + // libswscale wants the RGB colorspace to be SWS_CS_DEFAULT, which is = SWS_CS_ITU601. + set_luma_transfer( context, self->yuv_colorspace, 601, self->full_luma ); sws_scale( context, (const uint8_t* const*) frame->data, frame->linesize, 0, height, output.data, output.linesize); sws_freeContext( context ); @@ -1377,6 +1379,7 @@ static int producer_get_image( mlt_frame frame, uint8_t **buffer, mlt_image_form // Duplicate it if ( ( image_size = allocate_buffer( frame, codec_context, buffer, format, width, height ) ) ) { + int yuv_colorspace; // Workaround 1088 encodings missing cropping info. if ( *height == 1088 && mlt_profile_dar( mlt_service_profile( MLT_PRODUCER_SERVICE( producer ) ) ) == 16.0/9.0 ) *height = 1080; @@ -1390,13 +1393,12 @@ static int producer_get_image( mlt_frame frame, uint8_t **buffer, mlt_image_form picture.linesize[0] = codec_context->width; picture.linesize[1] = codec_context->width / 2; picture.linesize[2] = codec_context->width / 2; - int yuv_colorspace = convert_image( self, (AVFrame*) &picture, *buffer, + yuv_colorspace = convert_image( self, (AVFrame*) &picture, *buffer, PIX_FMT_YUV420P, format, *width, *height, &alpha ); - mlt_properties_set_int( frame_properties, "colorspace", yuv_colorspace ); } else #endif - int yuv_colorspace = convert_image( self, self->video_frame, *buffer, codec_context->pix_fmt, + yuv_colorspace = convert_image( self, self->video_frame, *buffer, codec_context->pix_fmt, format, *width, *height, &alpha ); mlt_properties_set_int( frame_properties, "colorspace", yuv_colorspace ); got_picture = 1; @@ -1549,6 +1551,7 @@ static int producer_get_image( mlt_frame frame, uint8_t **buffer, mlt_image_form { if ( ( image_size = allocate_buffer( frame, codec_context, buffer, format, width, height ) ) ) { + int yuv_colorspace; // Workaround 1088 encodings missing cropping info. if ( *height == 1088 && mlt_profile_dar( mlt_service_profile( MLT_PRODUCER_SERVICE( producer ) ) ) == 16.0/9.0 ) *height = 1080; @@ -1574,7 +1577,7 @@ static int producer_get_image( mlt_frame frame, uint8_t **buffer, mlt_image_form VdpStatus status = vdp_surface_get_bits( render->surface, dest_format, planes, pitches ); if ( status == VDP_STATUS_OK ) { - int yuv_colorspace = convert_image( self, self->video_frame, *buffer, PIX_FMT_YUV420P, + yuv_colorspace = convert_image( self, self->video_frame, *buffer, PIX_FMT_YUV420P, format, *width, *height, &alpha ); mlt_properties_set_int( frame_properties, "colorspace", yuv_colorspace ); } @@ -1592,7 +1595,7 @@ static int producer_get_image( mlt_frame frame, uint8_t **buffer, mlt_image_form } else #endif - int yuv_colorspace = convert_image( self, self->video_frame, *buffer, codec_context->pix_fmt, + yuv_colorspace = convert_image( self, self->video_frame, *buffer, codec_context->pix_fmt, format, *width, *height, &alpha ); mlt_properties_set_int( frame_properties, "colorspace", yuv_colorspace ); self->top_field_first |= self->video_frame->top_field_first; @@ -1629,6 +1632,7 @@ static int producer_get_image( mlt_frame frame, uint8_t **buffer, mlt_image_form // Duplicate it if ( ( image_size = allocate_buffer( frame, codec_context, buffer, format, width, height ) ) ) { + int yuv_colorspace; // Workaround 1088 encodings missing cropping info. if ( *height == 1088 && mlt_profile_dar( mlt_service_profile( MLT_PRODUCER_SERVICE( producer ) ) ) == 16.0/9.0 ) *height = 1080; @@ -1642,13 +1646,13 @@ static int producer_get_image( mlt_frame frame, uint8_t **buffer, mlt_image_form picture.linesize[0] = codec_context->width; picture.linesize[1] = codec_context->width / 2; picture.linesize[2] = codec_context->width / 2; - int yuv_colorspace = convert_image( self, (AVFrame*) &picture, *buffer, + yuv_colorspace = convert_image( self, (AVFrame*) &picture, *buffer, PIX_FMT_YUV420P, format, *width, *height, &alpha ); mlt_properties_set_int( frame_properties, "colorspace", yuv_colorspace ); } else #endif - int yuv_colorspace = convert_image( self, self->video_frame, *buffer, codec_context->pix_fmt, + yuv_colorspace = convert_image( self, self->video_frame, *buffer, codec_context->pix_fmt, format, *width, *height, &alpha ); mlt_properties_set_int( frame_properties, "colorspace", yuv_colorspace ); got_picture = 1; @@ -1802,7 +1806,7 @@ static int video_codec_init( producer_avformat self, int index, mlt_properties p #endif double fps = av_q2d( frame_rate ); -#if LIBAVFORMAT_VERSION_MAJOR < 55 +#if LIBAVFORMAT_VERSION_MAJOR < 55 || defined(FFUDIV) // Verify and sanitize the muxer frame rate. if ( isnan( fps ) || isinf( fps ) || fps == 0 ) { @@ -1810,7 +1814,7 @@ static int video_codec_init( producer_avformat self, int index, mlt_properties p fps = av_q2d( frame_rate ); } #endif -#if LIBAVFORMAT_VERSION_INT >= ((52<<16)+(42<<8)+0) && LIBAVFORMAT_VERSION_MAJOR < 55 +#if LIBAVFORMAT_VERSION_INT >= ((52<<16)+(42<<8)+0) && ( LIBAVFORMAT_VERSION_MAJOR < 55 || defined(FFUDIV) ) // With my samples when r_frame_rate != 1000 but avg_frame_rate is valid, // avg_frame_rate gives some approximate value that does not well match the media. // Also, on my sample where r_frame_rate = 1000, using avg_frame_rate directly @@ -1949,7 +1953,7 @@ static void producer_set_up_video( producer_avformat self, mlt_frame frame ) } // Update the video properties if the index changed - if ( index != self->video_index ) + if ( context && index > -1 && index != self->video_index ) { // Reset the video properties if the index changed self->video_index = index;