[FFmpeg-devel] Create and populate AVStream side data packet with contents of ISOBMFF edit list entries

Matthew Szatmary matt at szatmary.org
Thu Jul 30 19:03:23 EEST 2020


>From 91ae719dd69cba5153e4ce1aad2eb3ce819668b1 Mon Sep 17 00:00:00 2001
From: Matthew Szatmary <matt at szatmary.org>
Date: Thu, 23 Jul 2020 16:36:49 -0700
Subject: [PATCH] Create and populate AVStream side data packet with contents
 of ISOBMFF edit list entries

Signed-off-by: Matthew Szatmary <matt at szatmary.org>
---
 Changelog           |  1 +
 libavcodec/packet.h | 15 +++++++++++++++
 libavformat/mov.c   | 19 +++++++++++++++++++
 3 files changed, 35 insertions(+)

diff --git a/Changelog b/Changelog
index 6f648bff2b..d51e836301 100644
--- a/Changelog
+++ b/Changelog
@@ -10,6 +10,7 @@ version <next>:
 - ADPCM IMA Ubisoft APM encoder
 - Rayman 2 APM muxer
 - AV1 encoding support SVT-AV1
+- AV_PKT_DATA_EDIT_LIST added to AVStream side_data


 version 4.3:
diff --git a/libavcodec/packet.h b/libavcodec/packet.h
index 0a19a0eff3..f4a00ccf1e 100644
--- a/libavcodec/packet.h
+++ b/libavcodec/packet.h
@@ -290,6 +290,21 @@ enum AVPacketSideDataType {
      */
     AV_PKT_DATA_S12M_TIMECODE,

+    /**
+     * ISO media file edit list side data packet
+     * The structre is repeated for each entry in the edit list
+     * The number of entries can be calculated
+     * by dividing the total size by the entry size
+     * Each entry is 20 bytes and is laid out as follows:
+     * @code
+     * s64be segment duration in AV_TIME_BASE
+     * s64be media time in AV_TIME_BASE
+     * s16be media rate
+     * s16be media rate fraction
+     * @endcode
+     */
+    AV_PKT_DATA_EDIT_LIST,
+
     /**
      * The number of side data types.
      * This is not part of the public API/ABI in the sense that it may
diff --git a/libavformat/mov.c b/libavformat/mov.c
index d16840f3df..0d29588831 100644
--- a/libavformat/mov.c
+++ b/libavformat/mov.c
@@ -4311,6 +4311,25 @@ static int mov_read_trak(MOVContext *c,
AVIOContext *pb, MOVAtom atom)
         && sc->time_scale == st->codecpar->sample_rate) {
             st->need_parsing = AVSTREAM_PARSE_FULL;
     }
+
+    if (sc->elst_data) {
+        int i;
+        uint8_t *elst_data;
+        elst_data = av_stream_new_side_data(st,
AV_PKT_DATA_EDIT_LIST, sc->elst_count * 20);
+        if (elst_data) {
+            for (i = 0; i < sc->elst_count; i++) {
+                uint32_t media_rate;
+                int64_t duration, time;
+                media_rate = (uint32_t)(sc->elst_data[i].rate * 65536.0);
+                duration = av_rescale(sc->elst_data[i].duration,
c->time_scale, AV_TIME_BASE);
+                time = av_rescale(sc->elst_data[i].time,
c->time_scale, AV_TIME_BASE);
+                AV_WB64((elst_data+(i*20)), duration);
+                AV_WB64((elst_data+(i*20)+8), time);
+                AV_WB32((elst_data+(i*20)+16), media_rate);
+            }
+        }
+    }
+
     /* Do not need those anymore. */
     av_freep(&sc->chunk_offsets);
     av_freep(&sc->sample_sizes);
-- 
2.27.0


More information about the ffmpeg-devel mailing list