LAVFilters icon indicating copy to clipboard operation
LAVFilters copied to clipboard

Workaround to improve support of AVIF with alpha

Open clsid2 opened this issue 11 months ago • 0 comments

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

clsid2 avatar Jan 31 '25 01:01 clsid2