From patchwork Tue May 21 13:29:45 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gyan Doshi X-Patchwork-Id: 13222 Return-Path: X-Original-To: patchwork@ffaux-bg.ffmpeg.org Delivered-To: patchwork@ffaux-bg.ffmpeg.org Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by ffaux.localdomain (Postfix) with ESMTP id 26EDC448026 for ; Tue, 21 May 2019 16:29:59 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 00F2F68A7A6; Tue, 21 May 2019 16:29:58 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mx1.mailbox.org (mx1.mailbox.org [80.241.60.212]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id B724168A56C for ; Tue, 21 May 2019 16:29:52 +0300 (EEST) Received: from smtp1.mailbox.org (smtp1.mailbox.org [80.241.60.240]) (using TLSv1.2 with cipher ECDHE-RSA-CHACHA20-POLY1305 (256/256 bits)) (No client certificate requested) by mx1.mailbox.org (Postfix) with ESMTPS id BD5A6501A2 for ; Tue, 21 May 2019 15:29:51 +0200 (CEST) X-Virus-Scanned: amavisd-new at heinlein-support.de Received: from smtp1.mailbox.org ([80.241.60.240]) by spamfilter06.heinlein-hosting.de (spamfilter06.heinlein-hosting.de [80.241.56.125]) (amavisd-new, port 10030) with ESMTP id hRK0sLFypihl for ; Tue, 21 May 2019 15:29:48 +0200 (CEST) To: FFmpeg development discussions and patches From: Gyan Message-ID: Date: Tue, 21 May 2019 18:59:45 +0530 MIME-Version: 1.0 Content-Language: en-US Subject: [FFmpeg-devel] [PATCH] avformat/segment: populate empty outer stream extradata from packet X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Fixes playback in QT for me. Gyan From 3b7c51ebb8e26aafe27170e1c8e969b854c985ff Mon Sep 17 00:00:00 2001 From: Gyan Doshi 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(+) 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 ?