[FFmpeg-cvslog] avcodec/cbs_av1: add support for standard MP4/Matroska extradata

Jan Ekström git at videolan.org
Tue Nov 24 10:27:30 EET 2020


ffmpeg | branch: master | Jan Ekström <jeebjp at gmail.com> | Mon Nov 23 19:37:38 2020 +0200| [a66d1779bb1b33cc54b359b142dcbcd2827fa282] | committer: Jan Ekström

avcodec/cbs_av1: add support for standard MP4/Matroska extradata

This way API clients can just pass the AV1CodecConfigurationRecord
as extradata as-is without further filtering.

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

 libavcodec/cbs_av1.c | 34 ++++++++++++++++++++++++++++++++++
 1 file changed, 34 insertions(+)

diff --git a/libavcodec/cbs_av1.c b/libavcodec/cbs_av1.c
index 9badfe31e4..9ae2f59872 100644
--- a/libavcodec/cbs_av1.c
+++ b/libavcodec/cbs_av1.c
@@ -758,6 +758,39 @@ static int cbs_av1_split_fragment(CodedBitstreamContext *ctx,
         goto fail;
     }
 
+    if (header && size && data[0] & 0x80) {
+        // first bit is nonzero, the extradata does not consist purely of
+        // OBUs. Expect MP4/Matroska AV1CodecConfigurationRecord
+        int config_record_version = data[0] & 0x7f;
+
+        if (config_record_version != 1) {
+            av_log(ctx->log_ctx, AV_LOG_ERROR,
+                   "Unknown version %d of AV1CodecConfigurationRecord "
+                   "found!\n",
+                   config_record_version);
+            err = AVERROR_INVALIDDATA;
+            goto fail;
+        }
+
+        if (size <= 4) {
+            if (size < 4) {
+                av_log(ctx->log_ctx, AV_LOG_WARNING,
+                       "Undersized AV1CodecConfigurationRecord v%d found!\n",
+                       config_record_version);
+                err = AVERROR_INVALIDDATA;
+                goto fail;
+            }
+
+            goto success;
+        }
+
+        // In AV1CodecConfigurationRecord v1, actual OBUs start after
+        // four bytes. Thus set the offset as required for properly
+        // parsing them.
+        data += 4;
+        size -= 4;
+    }
+
     while (size > 0) {
         AV1RawOBUHeader header;
         uint64_t obu_size;
@@ -803,6 +836,7 @@ static int cbs_av1_split_fragment(CodedBitstreamContext *ctx,
         size -= obu_length;
     }
 
+success:
     err = 0;
 fail:
     ctx->trace_enable = trace;



More information about the ffmpeg-cvslog mailing list