[FFmpeg-devel] [PATCH 12/17] avformat/avc: Discard empty NAL units during annex B->mp4 conversion

Andreas Rheinhardt andreas.rheinhardt at gmail.com
Thu Jul 9 22:20:17 EEST 2020


When an empty annex B NAL unit (i.e. 0x000001 immediately followed by a
three or four-byte start code) is encountered during annex B->mp4
conversion, a NAL unit of size zero is created; this is invalid.
Furthermore, several functions simply presumed all NAL units to be
nonempty and treated the first byte as the NAL unit type.

Ticket #7200 contains a sample with such NAL units.

This commit skips empty NAL units during annex B->mp4 conversion,
ensuring that the callers don't need to check for themselves.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt at gmail.com>
---
 libavformat/avc.c | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/libavformat/avc.c b/libavformat/avc.c
index 98462940ad..17fcd1e73f 100644
--- a/libavformat/avc.c
+++ b/libavformat/avc.c
@@ -104,6 +104,7 @@ const uint8_t *ff_avc_parse_nalu(const uint8_t **start, const uint8_t **nal_end,
         p += 3;
     }
 
+search_again:
     next = avc_find_startcode_internal(p, end);
 
     if (next) {
@@ -112,6 +113,12 @@ const uint8_t *ff_avc_parse_nalu(const uint8_t **start, const uint8_t **nal_end,
     } else {
         *nal_end = end;
     }
+    if (*nal_end == p) {
+        if (!next)
+            return NULL;
+        p = next;
+        goto search_again;
+    }
     *start = next;
     return p;
 }
-- 
2.20.1



More information about the ffmpeg-devel mailing list