[Libav-user] What is correct method to identify streams containing alpha?

Mark Schafer mschafer at wireframe.biz
Fri Jun 15 00:03:05 EEST 2018


We're trying to integrate ffmpeg 4 with Pyglet.
Its all going very well but we have one issue:

- If a VP9 (or VP8) file is created using ffmpeg4 from png files with 
alphas, we get a video file (webm) with alpha internally. (Excellent)
- ffmpeg -i image_seq%03d.png -qmin 0 -qmax 50 -crf 5 -b:v 1M output.webm
     - The report from this CLI indicates that an alpha has been generated.

- Sample webm videos with alpha can be found on this page: 
https://simpl.info/videoalpha/
- However on playing back we only get the RGB and do not get the alpha 
unless we override the codec to be 'libvpx'. (same behaviour can be 
demonstrated in CLI version of ffplay).

Question:
What is the correct way to identify (in code) that a VP8 or VP9 stream 
has an alpha component ?
(So we can load it and access it via AVFrame() for use as an RGBA 
texture.)  We are wrapping avutil, avcodec, etc.


More specifically:
We get the FormatContext from the file using AVFormatContext and the 
stream AVStream from that.
Then from the AVStream we get the 'codecpar' param (AVCodecParameters).
 From the AVCodecParameters we can examine the codec_id (167 is VP9) and 
other useful params like 'bits_per_coded_sample'.

Interestingly these values seem correct for streams like H264 
(codec_id=27) at 24 bits but are marked as 0 for the VP9 codec.
Leading me to think this is not the correct place to find the proper values.



More information about the Libav-user mailing list