From patchwork Sun Jan 15 21:24:24 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Niedermayer X-Patchwork-Id: 2222 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.103.89.21 with SMTP id n21csp1081355vsb; Sun, 15 Jan 2017 13:24:36 -0800 (PST) X-Received: by 10.28.40.67 with SMTP id o64mr9106794wmo.40.1484515476140; Sun, 15 Jan 2017 13:24:36 -0800 (PST) Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id e79si10094675wmc.113.2017.01.15.13.24.35; Sun, 15 Jan 2017 13:24:36 -0800 (PST) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 03C8168A3EC; Sun, 15 Jan 2017 23:24:24 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from vie01a-dmta-pe03-3.mx.upcmail.net (vie01a-dmta-pe03-3.mx.upcmail.net [62.179.121.162]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 1CF9D68A163 for ; Sun, 15 Jan 2017 23:24:17 +0200 (EET) Received: from [172.31.216.43] (helo=vie01a-pemc-psmtp-pe01) by vie01a-dmta-pe03.mx.upcmail.net with esmtp (Exim 4.87) (envelope-from ) id 1cSsHp-0007D1-W4 for ffmpeg-devel@ffmpeg.org; Sun, 15 Jan 2017 22:24:25 +0100 Received: from localhost ([213.47.41.20]) by vie01a-pemc-psmtp-pe01 with SMTP @ mailcloud.upcmail.net id YlQQ1u01R0S5wYM01lQRft; Sun, 15 Jan 2017 22:24:25 +0100 X-SourceIP: 213.47.41.20 From: Michael Niedermayer To: FFmpeg development discussions and patches Date: Sun, 15 Jan 2017 22:24:24 +0100 Message-Id: <20170115212424.29868-1-michael@niedermayer.cc> X-Mailer: git-send-email 2.11.0 Subject: [FFmpeg-devel] [PATCH] libavformat/mpegtsenc: support hevc with missing in stream headers like h.264 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 MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Signed-off-by: Michael Niedermayer --- libavformat/mpegtsenc.c | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/libavformat/mpegtsenc.c b/libavformat/mpegtsenc.c index cdd7e37a1f..0f394c5fe0 100644 --- a/libavformat/mpegtsenc.c +++ b/libavformat/mpegtsenc.c @@ -1619,9 +1619,39 @@ static int mpegts_write_packet_internal(AVFormatContext *s, AVPacket *pkt) } } } else if (st->codecpar->codec_id == AV_CODEC_ID_HEVC) { + const uint8_t *p = buf, *buf_end = p + size; + uint32_t state = -1; + int extradd = (pkt->flags & AV_PKT_FLAG_KEY) ? st->codecpar->extradata_size : 0; int ret = check_hevc_startcode(s, st, pkt); if (ret < 0) return ret; + + if (extradd && AV_RB24(st->codecpar->extradata) > 1) + extradd = 0; + + do { + p = avpriv_find_start_code(p, buf_end, &state); + av_log(s, AV_LOG_TRACE, "nal %d\n", (state & 0x7e)>>1); + if ((state & 0x7e) == 2*32) + extradd = 0; + } while (p < buf_end && (state & 0x7e) != 2*35 && + (state & 0x7e) >= 2*32); + + if ((state & 0x7e) < 2*16 && (state & 0x7e) >= 2*24) + extradd = 0; + if ((state & 0x7e) != 2*35) { // AUD NAL + data = av_malloc(pkt->size + 7 + extradd); + if (!data) + return AVERROR(ENOMEM); + memcpy(data + 7, st->codecpar->extradata, extradd); + memcpy(data + 7 + extradd, pkt->data, pkt->size); + AV_WB32(data, 0x00000001); + data[4] = 2*35; + data[5] = 1; + data[6] = 0x50; // any slice type (0x4) + rbsp stop one bit + buf = data; + size = pkt->size + 7 + extradd; + } } else if (st->codecpar->codec_id == AV_CODEC_ID_OPUS) { if (pkt->size < 2) { av_log(s, AV_LOG_ERROR, "Opus packet too short\n");