@@ -490,13 +490,44 @@ static mlt_properties find_default_streams(producer_avformat self)
490490 // Allow for multiple audio and video streams in the file and select first of each (if available)
491491 for (i = 0 ; i < context -> nb_streams ; i ++ ) {
492492 // Get the codec context
493+ AVFormatContext * vpxContext = NULL ;
493494 AVStream * stream = context -> streams [i ];
494495 if (!stream )
495496 continue ;
496497 AVCodecParameters * codec_params = stream -> codecpar ;
497498 const AVCodec * codec = avcodec_find_decoder (codec_params -> codec_id );
498499 if (!codec )
499500 continue ;
501+ int switchToVpxCodec = 0 ;
502+ if (codec_params -> codec_id == AV_CODEC_ID_VP9 ) {
503+ if (!(codec = avcodec_find_decoder_by_name ("libvpx-vp9" ))) {
504+ codec = avcodec_find_decoder (codec_params -> codec_id );
505+ } else {
506+ switchToVpxCodec = 1 ;
507+ }
508+ } else if (codec_params -> codec_id == AV_CODEC_ID_VP8 ) {
509+ if (!(codec = avcodec_find_decoder_by_name ("libvpx" ))) {
510+ codec = avcodec_find_decoder (codec_params -> codec_id );
511+ } else {
512+ switchToVpxCodec = 1 ;
513+ }
514+ }
515+ if (switchToVpxCodec ) {
516+ // Use a temporary format context to get the real pixel format with the libvpx decoder,
517+ // since the native decoder incorreclty detects yuva420p as yuv420p
518+ int error = avformat_open_input (& vpxContext ,
519+ mlt_properties_get (meta_media , "resource" ),
520+ NULL ,
521+ NULL );
522+ if (!error ) {
523+ vpxContext -> video_codec = codec ;
524+ avformat_find_stream_info (vpxContext , NULL );
525+ AVStream * vpxStream = vpxContext -> streams [i ];
526+ if (vpxStream ) {
527+ codec_params = vpxStream -> codecpar ;
528+ }
529+ }
530+ }
500531
501532 snprintf (key , sizeof (key ), "meta.media.%u.stream.type" , i );
502533
@@ -634,6 +665,10 @@ static mlt_properties find_default_streams(producer_avformat self)
634665 free (value );
635666 }
636667 }
668+ if (vpxContext ) {
669+ avformat_close_input (& vpxContext );
670+ vpxContext = NULL ;
671+ }
637672 }
638673
639674 // Use the album art if that is all we have
0 commit comments