[FFmpeg-cvslog] avcodec/h2645_parse: Don't treat 0x000002 as a start code and truncate

Mattias Wadman git at videolan.org
Sun Feb 18 08:37:32 EET 2024


ffmpeg | branch: master | Mattias Wadman <mattias.wadman at gmail.com> | Tue Feb 13 11:17:46 2024 +0100| [78812cd147fa2ab1f0aa3019886c0abe00b7c63a] | committer: Anton Khirnov

avcodec/h2645_parse: Don't treat 0x000002 as a start code and truncate

According to ITU-T H.265 7.4.2.1 this byte sequence should not appear in a
NAL unit but in practice in rare cases it seems it does, possibly due to buggy
encoders. Other players like VLC and Quicktime seem to be fine with it.

Currently when this sequence is found it is treated as if the next start code
has been found and the NAL unit gets truncated.

This change limits the code to only look for first start code 0x0000001 or
first escape 0x000003.

Sadly i can't share the original source file with the issue but the first
80 bytes of the NAL unit looks like this:

       │00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f│0123456789abcdef│
0x00000│00 00 00 01 02 01 d0 bc 57 a1 b8 44 70 01 00 0b│........W..Dp...│
0x00010│80 2e 00 c2 6c ec 3e b9 e3 03 fb 91 2e d2 43 cb│....l.>.......C.│
0x00020│1d 2c 00 00 02 00 02 00 5c 93 72 6f 31 76 18 00│.,......\.ro1v..│
0x00030│08 38 aa b1 4c 33 3f fd 08 cb 77 9b d4 3c db 02│.8..L3?...w..<..│
0x00040│a2 04 73 15 75 de 3b c4 67 c0 8f ca ad 31 f1 99│..s.u.;.g....1..│

Signed-off-by: Anton Khirnov <anton at khirnov.net>

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=78812cd147fa2ab1f0aa3019886c0abe00b7c63a
---

 libavcodec/h2645_parse.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/libavcodec/h2645_parse.c b/libavcodec/h2645_parse.c
index 28db465059..9f66f079c2 100644
--- a/libavcodec/h2645_parse.c
+++ b/libavcodec/h2645_parse.c
@@ -40,8 +40,9 @@ int ff_h2645_extract_rbsp(const uint8_t *src, int length,
 
     nal->skipped_bytes = 0;
 #define STARTCODE_TEST                                                  \
-        if (i + 2 < length && src[i + 1] == 0 && src[i + 2] <= 3) {     \
-            if (src[i + 2] != 3 && src[i + 2] != 0) {                   \
+        if (i + 2 < length && src[i + 1] == 0 &&                        \
+           (src[i + 2] == 3 || src[i + 2] == 1)) {                      \
+            if (src[i + 2] == 1) {                                      \
                 /* startcode, so we must be past the end */             \
                 length = i;                                             \
             }                                                           \



More information about the ffmpeg-cvslog mailing list