[FFmpeg-devel] [PATCH 09/17] avformat/avc, movenccenc: Simplify annex B->mp4 transformation

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


by using the new ff_avc_parse_nalu function.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt at gmail.com>
---
 libavformat/avc.c        | 11 ++---------
 libavformat/movenccenc.c | 12 ++----------
 2 files changed, 4 insertions(+), 19 deletions(-)

diff --git a/libavformat/avc.c b/libavformat/avc.c
index 39078aa5be..d089051034 100644
--- a/libavformat/avc.c
+++ b/libavformat/avc.c
@@ -120,20 +120,13 @@ int ff_avc_parse_nal_units(AVIOContext *pb, const uint8_t *buf_in, int size)
 {
     const uint8_t *p = buf_in;
     const uint8_t *end = p + size;
-    const uint8_t *nal_start, *nal_end;
+    const uint8_t *nal_start, *nal_end = NULL;
 
     size = 0;
-    nal_start = ff_avc_find_startcode(p, end);
-    for (;;) {
-        while (nal_start < end && !*(nal_start++));
-        if (nal_start == end)
-            break;
-
-        nal_end = ff_avc_find_startcode(nal_start, end);
+    while (nal_start = ff_avc_parse_nalu(&p, &nal_end, end)) {
         avio_wb32(pb, nal_end - nal_start);
         avio_write(pb, nal_start, nal_end - nal_start);
         size += 4 + nal_end - nal_start;
-        nal_start = nal_end;
     }
     return size;
 }
diff --git a/libavformat/movenccenc.c b/libavformat/movenccenc.c
index b91294f706..75244ab70b 100644
--- a/libavformat/movenccenc.c
+++ b/libavformat/movenccenc.c
@@ -194,7 +194,7 @@ int ff_mov_cenc_avc_parse_nal_units(MOVMuxCencContext* ctx, AVIOContext *pb,
 {
     const uint8_t *p = buf_in;
     const uint8_t *end = p + size;
-    const uint8_t *nal_start, *nal_end;
+    const uint8_t *nal_start, *nal_end = NULL;
     int ret;
 
     ret = mov_cenc_start_packet(ctx);
@@ -203,14 +203,7 @@ int ff_mov_cenc_avc_parse_nal_units(MOVMuxCencContext* ctx, AVIOContext *pb,
     }
 
     size = 0;
-    nal_start = ff_avc_find_startcode(p, end);
-    for (;;) {
-        while (nal_start < end && !*(nal_start++));
-        if (nal_start == end)
-            break;
-
-        nal_end = ff_avc_find_startcode(nal_start, end);
-
+    while (nal_start = ff_avc_parse_nalu(&p, &nal_end, end)) {
         avio_wb32(pb, nal_end - nal_start);
         avio_w8(pb, *nal_start);
         mov_cenc_write_encrypted(ctx, pb, nal_start + 1, nal_end - nal_start - 1);
@@ -218,7 +211,6 @@ int ff_mov_cenc_avc_parse_nal_units(MOVMuxCencContext* ctx, AVIOContext *pb,
         auxiliary_info_add_subsample(ctx, 5, nal_end - nal_start - 1);
 
         size += 4 + nal_end - nal_start;
-        nal_start = nal_end;
     }
 
     ret = mov_cenc_end_packet(ctx);
-- 
2.20.1



More information about the ffmpeg-devel mailing list