Fix H.264 HW decode for AVC3 in-band streams (V4L2/m2m)#2034
Conversation
On platforms using V4L2 mem2mem H.264 decoding (e.g. Raspberry Pi with OSMC's custom FFmpeg), the decoder's h264_xd_copy() function rejects avcC extradata with 0 SPS/0 PPS entries, causing a fallback to software decode. This format is used by AVC3 in-band streams (e.g. BBC iPlayer DASH) where SPS/PPS are carried in-band rather than in the codec private data. Fix by: - Detecting avcC with 0 SPS in Session::UpdateStream() and FragmentedSampleReader::UpdateSampleDescription(), and clearing extradata so the V4L2 decoder skips h264_xd_copy() - Adding AVCCodecHandler::Transform() to convert NALU length-prefixed packets (avcC framing) to Annex B start-code framing at decode time - Setting the AnnexB transform flag for all H.264 AVC1-4 formats (with and without SPS), ensuring consistent packet-level conversion
|
Decision: APPROVE kodiai responseDecision: APPROVE Evidence:
Review Details
|
|
Development work should be done first on the main branch, and then, if accepted, in the older branches the way you explain it seems more like an issue that needs to be addressed at the higher level rather than here Also, what happens with same stream on FFmpeg direct add-on? should have same problem? |
|
sorry if i ping you @samnazarko but i dont know exactly who ping |
|
Honestly, I’d advise getting access to a stream. |
|
Talking to some LE devs, if this is not working also with last firmware/OS build (more likely best on v22) Using workarounds like this that must be applied to every binary add-on is not the most appropriate way Given the nature of the issue, i don't think it's appropriate to accept this PR, especially from a code maintenance perspective, since this is focused to a third-party Kodi OS and not the official Kodi platforms |
|
Agreed.
On 15 Jun 2026, at 07:48, Stefano Gottardo ***@***.***> wrote:
[https://avatars.githubusercontent.com/u/3257156?s=20&v=4]CastagnaIT left a comment (xbmc/inputstream.adaptive#2034)<#2034 (comment)>
Talking to some LE devs, if this is not working also with last firmware/OS build (more likely best on v22)
the fix should be proposed on ffmpeg side, and probably add a temporary patch in your case for the OSMC build
Using workarounds like this that must be applied to every binary add-on is not the most appropriate way
especially since the problem is focused on a specific platform
Given the nature of the issue, i don't think it's appropriate to accept this PR, especially from a code maintenance perspective, since this is focused to a third-party Kodi OS and not the official Kodi platforms
—
Reply to this email directly, view it on GitHub<#2034?email_source=notifications&email_token=AAHDWLHI6E3XY2KEW4Q32VD476L33A5CNFSNUABFM5UWIORPF5TWS5BNNB2WEL2JONZXKZKDN5WW2ZLOOQXTINZQGUZDONBXGMZKM4TFMFZW63VHNVSW45DJN5XKKZLWMVXHJLDGN5XXIZLSL5RWY2LDNM#issuecomment-4705274732>, or unsubscribe<https://github.com/notifications/unsubscribe-auth/AAHDWLDDWRAJ45LS52VSDW3476L33AVCNFSNUABEKJSXA33TNF2G64TZHM3TGMBSGE2TKMZ3JFZXG5LFHM2DIOBRG43DAOJQGGQXMAQ>.
Triage notifications, keep track of coding agent tasks and review pull requests on the go with GitHub Mobile for iOS<https://github.com/notifications/mobile/ios/AAHDWLE36Z7FSJ4OPSOEGDT476L33A5CNFSNUABFM5UWIORPF5TWS5BNNB2WEL2JONZXKZKDN5WW2ZLOOQXTINZQGUZDONBXGMZKM4TFMFZW63VHNVSW45DJN5XKKZLWMVXHJKTGN5XXIZLSL5UW64Y> and Android<https://github.com/notifications/mobile/android/AAHDWLD47ZFXASNLFLZANMT476L33A5CNFSNUABFM5UWIORPF5TWS5BNNB2WEL2JONZXKZKDN5WW2ZLOOQXTINZQGUZDONBXGMZKM4TFMFZW63VHNVSW45DJN5XKKZLWMVXHJLTGN5XXIZLSL5QW4ZDSN5UWI>. Download it today!
You are receiving this because you were mentioned.Message ID: ***@***.***>
|
Summary
On platforms using V4L2 mem2mem H.264 decoding (e.g. Raspberry Pi with OSMC's custom FFmpeg), the decoder's
h264_xd_copy()function rejects avcC extradata with 0 SPS/0 PPS entries, causing a fallback to software decode. This format is used by AVC3 in-band streams (e.g. BBC iPlayer DASH) where SPS/PPS are carried in-band rather than in the codec private data.Problem
AVC3 streams provide an avcC record like
01 64 00 1f ff e0 00— 7 bytes with 0 SPS and 0 PPS. The V4L2 mem2mem decoder's init function (h264_xd_copy) tries to parse SPS/PPS from this record and fails withAVERROR(EINVAL), causing the decoder to fall back to software decode.Fix
Three-part approach:
Clear extradata for 0-SPS avcC — In both
Session::UpdateStream()andFragmentedSampleReader::UpdateSampleDescription(), detect avcC records with 0 SPS and set extradata to null. This preventsh264_xd_copyfrom being called, allowing the V4L2 decoder to open successfully (it receives SPS/PPS from in-band NALUs instead).Convert avcC extradata to Annex B — For avcC records that do contain SPS, convert to Annex B format. This is already done for DRM streams (
SSD_ANNEXB_REQUIRED), but non-DRM AVC1-4 streams now also get this treatment, which is required for V4L2/m2mem compatibility.Packet-level Annex B transform — Add
AVCCodecHandler::Transform()override that replaces NALU length prefixes (1/2/4 byte avcC framing) with Annex B start codes (00 00 00 01). This is needed because when extradata is cleared or converted, the downstream decoder expects Annex B framed packets. TheTransform()virtual already exists inCodecHandlerand is called byFragmentedSampleReader::ReadSample().Changes
src/Session.cpp— RestructureUpdateStream()H.264 extradata handling: DRM+SPS → Annex B conversion; avcC with 0 SPS → clear extradata; avcC with SPS → Annex B conversion; non-avcC → pass through. Added error handling for failedAvcToAnnexb()calls.src/codechandler/AVCCodecHandler.h— AddTransform()override andSetAnnexBTransformNeeded()/m_needAnnexBTransformmembers.src/codechandler/AVCCodecHandler.cpp— ImplementTransform(): iterates buffer replacing NALU length prefixes with00 00 00 01start codes.src/samplereader/FragmentedSampleReader.cpp— Add AVC1-4 handling inUpdateSampleDescription(): 0-SPS → clear extradata + enable transform; with SPS →ExtraDataToAnnexB()+ enable transform; failed conversion → clear extradata + enable transform.Testing
Tested on Raspberry Pi 4 (OSMC 2026.05-1, kernel 5.15.92, Kodi 21.3 Omega) with BBC iPlayer DASH streams: