[FFmpeg-devel] [PATCH 14/25] avformat/matroskaenc: Redo reformatting AV1

Andreas Rheinhardt andreas.rheinhardt at outlook.com
Mon Jan 17 01:03:54 EET 2022


This avoids allocations+copies in all cases, not only those
in which the desired OBUs are contiguous in the input buffer.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt at outlook.com>
---
ff_av1_filter_obus_buf() now has only one user left: movenc.c
Maybe movenc.c should be modified accordingly to remove it?

 libavformat/matroskaenc.c | 17 ++++++++++++++---
 1 file changed, 14 insertions(+), 3 deletions(-)

diff --git a/libavformat/matroskaenc.c b/libavformat/matroskaenc.c
index 08d2d338a6..d275d6cd6c 100644
--- a/libavformat/matroskaenc.c
+++ b/libavformat/matroskaenc.c
@@ -2389,6 +2389,16 @@ static int mkv_reformat_wavpack(MatroskaMuxContext *mkv, AVIOContext *pb,
 }
 #endif
 
+static int mkv_reformat_av1(MatroskaMuxContext *mkv, AVIOContext *pb,
+                            const AVPacket *pkt, int *size)
+{
+    int ret = ff_av1_filter_obus(pb, pkt->data, pkt->size);
+    if (ret < 0)
+        return ret;
+    *size = ret;
+    return 0;
+}
+
 static int mkv_write_block(AVFormatContext *s, AVIOContext *pb,
                            uint32_t blockid, const AVPacket *pkt, int keyframe)
 {
@@ -2426,9 +2436,7 @@ static int mkv_write_block(AVFormatContext *s, AVIOContext *pb,
         err = ff_hevc_annexb2mp4_buf(pkt->data, &data, &size, 0, NULL);
     } else
 #endif
-           if (par->codec_id == AV_CODEC_ID_AV1) {
-        err = ff_av1_filter_obus_buf(pkt->data, &data, &size, &offset);
-    } else if (track->reformat) {
+    if (track->reformat) {
         err = track->reformat(mkv, NULL, pkt, &size);
     } else
         data = pkt->data;
@@ -3106,6 +3114,9 @@ static int mkv_init(struct AVFormatContext *s)
             track->reformat = mkv_reformat_wavpack;
             break;
 #endif
+        case AV_CODEC_ID_AV1:
+            track->reformat = mkv_reformat_av1;
+            break;
         }
 
         if (s->flags & AVFMT_FLAG_BITEXACT) {
-- 
2.32.0



More information about the ffmpeg-devel mailing list