From 6994e494f8a8bbd500d7fbcc5bd5f9fa79d90fa9 Mon Sep 17 00:00:00 2001 From: Nicolas Noury Date: Mon, 11 Dec 2023 21:35:07 +0100 Subject: [PATCH] Adapt codec PrivateData following libavformat behavior change for AV1 FFmpeg pre 5.0 used to skip the first 4 bytes, hw codecs does not know how to manage without this. FFmpeg sw codecs (via dav1d) is supposed to handle this, but it does not either with our libavcodec implementation. Fix AV1 decoding for ffmpeg 5+ --- Source/stream_parser_ffmpeg.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/Source/stream_parser_ffmpeg.c b/Source/stream_parser_ffmpeg.c index 94b207d..e27fe15 100644 --- a/Source/stream_parser_ffmpeg.c +++ b/Source/stream_parser_ffmpeg.c @@ -381,8 +381,11 @@ serprintf("untouched (!?) vrate=%d; vscale=%d\n", video->rate, video->scale); if( codecpar->extradata_size ) { if( codecpar->extradata_size <= sizeof( video->extraData ) ) { - video->extraDataSize = codecpar->extradata_size; - memcpy( video->extraData, codecpar->extradata, video->extraDataSize ); + // libavformat used to skip the first 4 bytes in av1 private data + // hw codecs and our implementation using libavcodec still want this + int offset = ( video->format == VIDEO_FORMAT_AV1 ) ? 4 : 0 ; + video->extraDataSize = codecpar->extradata_size - offset ; + memcpy( video->extraData, codecpar->extradata + offset , video->extraDataSize ); if( video->format == VIDEO_FORMAT_H264 && video->extraData[0] == 0x00 ) { serprintf("FF: parse H264 SPS\n"); // for non-AVCC H264, parse the SPS/PPS here