LAVFilters
LAVFilters copied to clipboard
Workaround to improve support of AVIF with alpha
Example file: example_with_alpha.zip
AVIF image with alpha data is currently being demuxed by FFmpeg as two separate streams. Unfortunately, the first stream may be the alpha layer, with default disposition. Selecting the non-alpha stream by default should give better output.
So as a workaround, I propose a small addition in CLAVFDemuxer::SelectVideoStream():
// workaround for AVIF images where alpha layer is a separate stream
if (m_avFormat->streams[best->pid]->codecpar->codec_id == AV_CODEC_ID_AV1 && m_avFormat->streams[check->pid]->codecpar->codec_id == AV_CODEC_ID_AV1)
{
if (m_avFormat->streams[best->pid]->codecpar->format == AV_PIX_FMT_GRAY8 && m_avFormat->streams[check->pid]->codecpar->format != AV_PIX_FMT_GRAY8)
{
best = check;
continue;
}
}
// prefer default streams