[FFmpeg-devel] [PATCH 5/7] avformat/dashenc: update stream extradata from packet side data

James Almer jamrial at gmail.com
Tue Jul 30 23:19:48 EEST 2019


codecpar->extradata is not going to change between packets. New extradata
is instead propagated using packet side data.

Signed-off-by: James Almer <jamrial at gmail.com>
---
 libavformat/dashenc.c | 26 +++++++++++++++-----------
 1 file changed, 15 insertions(+), 11 deletions(-)

diff --git a/libavformat/dashenc.c b/libavformat/dashenc.c
index 64e2dac77e..bded260806 100644
--- a/libavformat/dashenc.c
+++ b/libavformat/dashenc.c
@@ -1464,25 +1464,29 @@ static void find_index_range(AVFormatContext *s, const char *full_path,
 }
 
 static int update_stream_extradata(AVFormatContext *s, OutputStream *os,
-                                   AVCodecParameters *par,
-                                   AVRational *frame_rate)
+                                   AVPacket *pkt, AVRational *frame_rate)
 {
-    uint8_t *extradata;
+    uint8_t *extradata, *new_extradata;
+    int extradata_size;
 
-    if (os->ctx->streams[0]->codecpar->extradata_size || !par->extradata_size)
+    if (os->ctx->streams[0]->codecpar->extradata_size)
         return 0;
 
-    extradata = av_malloc(par->extradata_size);
+    extradata = av_packet_get_side_data(pkt, AV_PKT_DATA_NEW_EXTRADATA, &extradata_size);
+    if (!extradata_size)
+        return 0;
+
+    new_extradata = av_malloc(extradata_size);
 
-    if (!extradata)
+    if (!new_extradata)
         return AVERROR(ENOMEM);
 
-    memcpy(extradata, par->extradata, par->extradata_size);
+    memcpy(new_extradata, extradata, extradata_size);
 
-    os->ctx->streams[0]->codecpar->extradata = extradata;
-    os->ctx->streams[0]->codecpar->extradata_size = par->extradata_size;
+    os->ctx->streams[0]->codecpar->extradata = new_extradata;
+    os->ctx->streams[0]->codecpar->extradata_size = extradata_size;
 
-    set_codec_str(s, par, frame_rate, os->codec_str, sizeof(os->codec_str));
+    set_codec_str(s, os->ctx->streams[0]->codecpar, frame_rate, os->codec_str, sizeof(os->codec_str));
 
     return 0;
 }
@@ -1700,7 +1704,7 @@ static int dash_write_packet(AVFormatContext *s, AVPacket *pkt)
     int64_t seg_end_duration, elapsed_duration;
     int ret;
 
-    ret = update_stream_extradata(s, os, st->codecpar, &st->avg_frame_rate);
+    ret = update_stream_extradata(s, os, pkt, &st->avg_frame_rate);
     if (ret < 0)
         return ret;
 
-- 
2.22.0



More information about the ffmpeg-devel mailing list