From patchwork Mon Oct 12 09:18:13 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Liu Steven X-Patchwork-Id: 22869 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 2C51244B8F2 for ; Mon, 12 Oct 2020 12:18:48 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 0287B68BB8F; Mon, 12 Oct 2020 12:18:48 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from smtpbgbr2.qq.com (smtpbgbr2.qq.com [54.207.22.56]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 60E3F68BB3A for ; Mon, 12 Oct 2020 12:18:39 +0300 (EEST) X-QQ-mid: bizesmtp12t1602494296txsgla6x Received: from localhost (unknown [103.107.216.230]) by esmtp6.qq.com (ESMTP) with id ; Mon, 12 Oct 2020 17:18:15 +0800 (CST) X-QQ-SSF: 01100000002000Z0Z000B00A0000000 X-QQ-FEAT: DAlkLFix89V4ZWyk5dwadL+tStKai62bt1lsl8RDBw7qB9xdpXhavx18WcM59 vUpkzfttRuGZucCLttyxfYL+Mi1ImPhxFhjDvjPfd4CbK1Fqz9y9acmPY1/GrcsPzzinF0H 1v371qjgi6O+MbD2jgh/oRMo1PPklYyZ4WwSyC0vcaH2wfLXze6rSHv7Jv0GH1LAak43Ayd Ai5DEfzJtLt/J+Wh13YZNJK6iqJc8ZcSrWb/Q+fA5bt6WrPxZ82lAZGUUjUSWBtiG9ZL7xE 4mG+LFxwjykq4p5uoPCKMPjE0T3fpRZe1/eccQf0hjr8b5E6ABjK6194c= X-QQ-GoodBg: 0 From: Steven Liu To: ffmpeg-devel@ffmpeg.org Date: Mon, 12 Oct 2020 17:18:13 +0800 Message-Id: <20201012091813.55564-1-lq@chinaffmpeg.org> X-Mailer: git-send-email 2.25.0 MIME-Version: 1.0 X-QQ-SENDSIZE: 520 Feedback-ID: bizesmtp:chinaffmpeg.org:qybgforeign:qybgforeign5 X-QQ-Bgrelay: 1 Subject: [FFmpeg-devel] [PATCH] avformat/hlsenc: support CODECS Attribute in hevc EXT-X-STREAM-INF 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 Cc: Steven Liu Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" fix ticket: 8904 parse the SPS from extradata and get profile_tier_level write the profile_tier_level info into CODECS Attribute reference to :https://developer.apple.com/documentation/http_live_streaming/hls_authoring_specification_for_apple_devices/hls_authoring_specification_for_apple_devices_appendixes Signed-off-by: Steven Liu --- libavformat/hlsenc.c | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/libavformat/hlsenc.c b/libavformat/hlsenc.c index cb31d6aed7..574d9f81e9 100644 --- a/libavformat/hlsenc.c +++ b/libavformat/hlsenc.c @@ -337,6 +337,43 @@ static void write_codec_attr(AVStream *st, VariantStream *vs) } else { goto fail; } + } else if (st->codecpar->codec_id == AV_CODEC_ID_HEVC) { + uint8_t *data = st->codecpar->extradata; + int i = 0; + int profile = FF_PROFILE_UNKNOWN; + int level = FF_LEVEL_UNKNOWN; + + if (st->codecpar->profile != FF_PROFILE_UNKNOWN) + profile = st->codecpar->profile; + if (st->codecpar->level != FF_LEVEL_UNKNOWN) + level = st->codecpar->level; + + while (data && (data - st->codecpar->extradata) < st->codecpar->extradata_size) { + /* get HEVC SPS NAL and seek to profile_tier_level */ + if (data && (data[0] | data[1] | data[2]) == 0 && data[3] == 1 && ((data[4] & 0x42) == 0x42)) { + int rbsp_byte_size; + data += 7; + /* process by reference General NAL unit syntax */ + profile = *data & 0x1f; + rbsp_byte_size = st->codecpar->extradata_size - (data - st->codecpar->extradata); + for (i = 0; i < rbsp_byte_size; i++, data++) { + if (data[0] == 0 && data[1] == 0 && data[2] == 3) { + data += 2; + i++; + } + /* skip 8 + 32 + 4 + 43 + 1 bit */ + if (i == 11) + level = *data; + } + break; + } + data++; + } + if (st->codecpar->codec_tag == MKTAG('h','v','c','1') && + profile != FF_PROFILE_UNKNOWN && + level != FF_LEVEL_UNKNOWN) { + snprintf(attr, sizeof(attr), "%s.%d.4.L%d.B01", av_fourcc2str(st->codecpar->codec_tag), profile, level); + } } else if (st->codecpar->codec_id == AV_CODEC_ID_MP2) { snprintf(attr, sizeof(attr), "mp4a.40.33"); } else if (st->codecpar->codec_id == AV_CODEC_ID_MP3) { @@ -2247,6 +2284,10 @@ static int hls_write_header(AVFormatContext *s) continue; } avpriv_set_pts_info(outer_st, inner_st->pts_wrap_bits, inner_st->time_base.num, inner_st->time_base.den); + if (outer_st->codecpar->codec_id == AV_CODEC_ID_HEVC && + outer_st->codecpar->codec_tag != MKTAG('h','v','c','1')) { + av_log(s, AV_LOG_WARNING, "Stream HEVC is not hvc1, you should use tag:v hvc1 to set it.\n"); + } write_codec_attr(outer_st, vs); }