]> git.sesse.net Git - mlt/blobdiff - src/modules/avformat/consumer_avformat.c
Expand colorspace support to explicit 601.
[mlt] / src / modules / avformat / consumer_avformat.c
index c0167eae119586be5c4084482053383454e0767d..f26c3740da3e98436e7bb6547952e95dea13f6fb 100644 (file)
@@ -545,7 +545,10 @@ static AVStream *add_video_stream( mlt_consumer this, AVFormatContext *oc, int c
                        apply_properties( c, p, AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM, 1 );
                        mlt_properties_close( p );
                }
+               int colorspace = mlt_properties_get_int( properties, "colorspace" );
+               mlt_properties_set( properties, "colorspace", NULL );
                apply_properties( c, properties, AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM, 0 );
+               mlt_properties_set_int( properties, "colorspace", colorspace );
 
                // Set options controlled by MLT
                c->width = mlt_properties_get_int( properties, "width" );
@@ -559,6 +562,25 @@ static AVStream *add_video_stream( mlt_consumer this, AVFormatContext *oc, int c
 #else
                c->pix_fmt = pix_fmt ? avcodec_get_pix_fmt( pix_fmt ) : PIX_FMT_YUV420P;
 #endif
+               
+               switch ( colorspace )
+               {
+               case 170:
+                       c->colorspace = AVCOL_SPC_SMPTE170M;
+                       break;
+               case 240:
+                       c->colorspace = AVCOL_SPC_SMPTE240M;
+                       break;
+               case 470:
+                       c->colorspace = AVCOL_SPC_BT470BG;
+                       break;
+               case 601:
+                       c->colorspace = ( 576 % c->height ) ? AVCOL_SPC_SMPTE170M : AVCOL_SPC_BT470BG;
+                       break;
+               case 709:
+                       c->colorspace = AVCOL_SPC_BT709;
+                       break;
+               }
 
                if ( mlt_properties_get( properties, "aspect" ) )
                {
@@ -1235,10 +1257,7 @@ static void *consumer_thread( void *arg )
                                                mlt_log_debug( MLT_CONSUMER_SERVICE( this ), " frame_size %d\n", codec->frame_size );
                                                if ( i == 0 )
                                                {
-                                                       if ( audio_codec_id == CODEC_ID_VORBIS )
-                                                               audio_pts = (double)codec->coded_frame->pts * av_q2d( stream->time_base );
-                                                       else
-                                                               audio_pts = (double)stream->pts.val * av_q2d( stream->time_base );
+                                                       audio_pts = (double)stream->pts.val * av_q2d( stream->time_base );
                                                }
                                        }
                                }
@@ -1267,8 +1286,6 @@ static void *consumer_thread( void *arg )
                                                uint8_t *p;
                                                uint8_t *q;
 
-                                               mlt_events_fire( properties, "consumer-frame-show", frame, NULL );
-
                                                mlt_frame_get_image( frame, &image, &img_fmt, &img_width, &img_height, 0 );
 
                                                q = image;
@@ -1287,8 +1304,15 @@ static void *consumer_thread( void *arg )
 
                                                // Do the colour space conversion
 #ifdef SWSCALE
+                                               int flags = SWS_BILINEAR;
+#ifdef USE_MMX
+                                               flags |= SWS_CPU_CAPS_MMX;
+#endif
+#ifdef USE_SSE
+                                               flags |= SWS_CPU_CAPS_MMX2;
+#endif
                                                struct SwsContext *context = sws_getContext( width, height, PIX_FMT_YUYV422,
-                                                       width, height, video_st->codec->pix_fmt, SWS_FAST_BILINEAR, NULL, NULL, NULL);
+                                                       width, height, video_st->codec->pix_fmt, flags, NULL, NULL, NULL);
                                                sws_scale( context, input->data, input->linesize, 0, height,
                                                        output->data, output->linesize);
                                                sws_freeContext( context );
@@ -1296,6 +1320,8 @@ static void *consumer_thread( void *arg )
                                                img_convert( ( AVPicture * )output, video_st->codec->pix_fmt, ( AVPicture * )input, PIX_FMT_YUYV422, width, height );
 #endif
 
+                                               mlt_events_fire( properties, "consumer-frame-show", frame, NULL );
+
                                                // Apply the alpha if applicable
                                                if ( video_st->codec->pix_fmt == PIX_FMT_RGB32 )
                                                {