@@ -490,13 +490,44 @@ static mlt_properties find_default_streams(producer_avformat self)
490
490
// Allow for multiple audio and video streams in the file and select first of each (if available)
491
491
for (i = 0 ; i < context -> nb_streams ; i ++ ) {
492
492
// Get the codec context
493
+ AVFormatContext * vpx_context = NULL ;
493
494
AVStream * stream = context -> streams [i ];
494
495
if (!stream )
495
496
continue ;
496
497
AVCodecParameters * codec_params = stream -> codecpar ;
497
498
const AVCodec * codec = avcodec_find_decoder (codec_params -> codec_id );
498
499
if (!codec )
499
500
continue ;
501
+ int switch_to_vpx = 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
+ switch_to_vpx = 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
+ switch_to_vpx = 1 ;
513
+ }
514
+ }
515
+ if (switch_to_vpx ) {
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 (& vpx_context ,
519
+ mlt_properties_get (meta_media , "resource" ),
520
+ NULL ,
521
+ NULL );
522
+ if (!error ) {
523
+ vpx_context -> video_codec = codec ;
524
+ avformat_find_stream_info (vpx_context , NULL );
525
+ AVStream * vpx_stream = vpx_context -> streams [i ];
526
+ if (vpx_stream ) {
527
+ codec_params = vpx_stream -> codecpar ;
528
+ }
529
+ }
530
+ }
500
531
501
532
snprintf (key , sizeof (key ), "meta.media.%u.stream.type" , i );
502
533
@@ -634,6 +665,10 @@ static mlt_properties find_default_streams(producer_avformat self)
634
665
free (value );
635
666
}
636
667
}
668
+ if (vpx_context ) {
669
+ avformat_close_input (& vpx_context );
670
+ vpx_context = NULL ;
671
+ }
637
672
}
638
673
639
674
// Use the album art if that is all we have
0 commit comments