[FFmpeg-devel] avformat/segment: populate empty outer stream extradata from packet

Submitted by Gyan on May 21, 2019, 1:29 p.m.

Details

Message ID c63822b9-a6c5-b5e7-c6ce-888bc0e05025@gyani.pro
State Accepted
Commit eae251ead9e380c722dce7ac3f4e97017bff9a7b
Headers show

Commit Message

Gyan May 21, 2019, 1:29 p.m.
Fixes playback in QT for me.

Gyan
From 3b7c51ebb8e26aafe27170e1c8e969b854c985ff Mon Sep 17 00:00:00 2001
From: Gyan Doshi <ffmpeg@gyani.pro>
Date: Tue, 21 May 2019 17:15:54 +0530
Subject: [PATCH] avformat/segment: populate empty outer stream extradata from
 packet

At present, if the outer stream extradata is empty but first packet
has extradata as a side data element, then only the first segment's
muxer instance may be able to extract this side data and use it.
For all other segments, extradata in packet side data could be missing
and generated segments may be invalid or unplayable in some apps
e.g. for an ADTS AAC stream segmented to MP4, the adtstoasc BSF will
add extradata to the first packet. The MOV muxer for the first segment
will add this to codecpar for the inner stream and write
Decoder Specific Information within the esds box. For other segments,
their esds' will not have this decSpecificInfo and they can't be opened
in Quicktime player or by services like nginx-vod-module.
---
 libavformat/segment.c | 14 ++++++++++++++
 1 file changed, 14 insertions(+)

Comments

Gyan May 23, 2019, 1:10 p.m.
On 21-05-2019 06:59 PM, Gyan wrote:
> Fixes playback in QT for me.
>
> Gyan
>
>
Ping.
Gyan May 25, 2019, 1:52 p.m.
On 23-05-2019 06:40 PM, Gyan wrote:
>
>
> On 21-05-2019 06:59 PM, Gyan wrote:
>> Fixes playback in QT for me.
>>
>> Gyan
>>
>>
> Ping.

Pong.

Gyan
Gyan May 27, 2019, 4:36 a.m.
On 25-05-2019 07:22 PM, Gyan wrote:
>
>
> On 23-05-2019 06:40 PM, Gyan wrote:
>>
>>
>> On 21-05-2019 06:59 PM, Gyan wrote:
>>> Fixes playback in QT for me.
>>>
>>> Gyan
>>>
>>>
>> Ping.
>
> Pong.

Plan to push tomorrow.

Gyan
Gyan May 28, 2019, 7:02 a.m.
On 27-05-2019 10:06 AM, Gyan wrote:
>
>
> On 25-05-2019 07:22 PM, Gyan wrote:
>>
>>
>> On 23-05-2019 06:40 PM, Gyan wrote:
>>>
>>>
>>> On 21-05-2019 06:59 PM, Gyan wrote:
>>>> Fixes playback in QT for me.
>>>>
>>>> Gyan
>>>>
>>>>
>>> Ping.
>>
>> Pong.
>
> Plan to push tomorrow.

Pushed as eae251ead9e380c722dce7ac3f4e97017bff9a7b

Gyan

Patch hide | download patch | download mbox

diff --git a/libavformat/segment.c b/libavformat/segment.c
index 90004600bd..6e37707f9f 100644
--- a/libavformat/segment.c
+++ b/libavformat/segment.c
@@ -859,6 +859,20 @@  static int seg_write_packet(AVFormatContext *s, AVPacket *pkt)
     if (!seg->avf || !seg->avf->pb)
         return AVERROR(EINVAL);
 
+    if (!st->codecpar->extradata_size) {
+        int pkt_extradata_size = 0;
+        uint8_t *pkt_extradata = av_packet_get_side_data(pkt, AV_PKT_DATA_NEW_EXTRADATA, &pkt_extradata_size);
+        if (pkt_extradata && pkt_extradata_size > 0) {
+            ret = ff_alloc_extradata(st->codecpar, pkt_extradata_size);
+            if (ret < 0) {
+                av_log(s, AV_LOG_WARNING, "Unable to add extradata to stream. Output segments may be invalid.\n");
+                goto calc_times;
+            }
+            memcpy(st->codecpar->extradata, pkt_extradata, pkt_extradata_size);
+            st->codecpar->extradata_size = pkt_extradata_size;
+        }
+    }
+
 calc_times:
     if (seg->times) {
         end_pts = seg->segment_count < seg->nb_times ?