From patchwork Thu Nov 23 03:37:36 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Dixit, Vishwanath" X-Patchwork-Id: 6290 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.2.161.94 with SMTP id m30csp275312jah; Wed, 22 Nov 2017 19:38:21 -0800 (PST) X-Google-Smtp-Source: AGs4zMbexp6H9uU5KlLHjd2hw0ZMYAEgrNRkpJViAGC79sKmuVD2mcxe4j1+C4hbFGg50I4+W5U4 X-Received: by 10.223.139.67 with SMTP id v3mr20245111wra.70.1511408301341; Wed, 22 Nov 2017 19:38:21 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1511408301; cv=none; d=google.com; s=arc-20160816; b=iUYryHV952zss2QOnGxTg2+FjuaedXL9YFHKp0hLcFgmA9lZFP/M4+7h/vjnhTMBgF RlJOJqHSyUhYifWw5vkPNPw7KfgcPYw/rUnKiMTDppaGYrqcs/xr3LVhWijYsomGHlP5 LOWeihpNup9GQiZhU+oOEQwuHY/oOD8jrVdFD+NUc5cFfFM0RgkHzYlBonGdK2adee3G VLj1+pZIa4/vqgFTeunJ9GSwB/0WnVE/HwVY8ZVTbmhrlw+21fGmQi2sVbjBGf6ZBIzF 2KANny+AQAeN/CWaWuEbi4XuxkdWIhIPYB0meSxzkBNVP5KxMupDfrom2K+ERefjJ8gC wK0w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version:cc:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:feedback-id:references:in-reply-to :message-id:date:to:from:dkim-signature:delivered-to :arc-authentication-results; bh=t80gA2RKsHHq7Byqdq2SaIgJy3G0WLAk10IGxQBjff8=; b=J7r8t4Grzf/AQyzJgtTFAEHjqwHEn1WE+tKAaCnZ/8u/l751GE1WfAB4oeSQcwnVlT aFFwp/wJv9C4Sy8GB3MX6OLj++VbdUlUQ3rL+fdc4KZC+XvL+oOK89ak+9R1od9EllKy ctiBtjDB7OwYpAeMeHp8pWQuBj4yFQU+mQfPBKNecCKiinYecXCbYIzQRXsdqN9SKnJe WyG0cyv8UOThuPEwZTJHhBuOXCwuorYocm0SoWFN6o22NFL8Zybenv+wBsmoIyphaJ6U J8LCR0MEatAw/V0FbcNHZTTORkCxixcjmjFLZ7YixwHlrRpgQab3HxjHKpKOp0bRhE/L LkJw== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@smtpservice.net header.s=m78bu0.a1-4.dyn header.b=RGeSoS8F; 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; dmarc=fail (p=QUARANTINE sp=NONE dis=NONE) header.from=akamai.com Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id h196si4769907wma.211.2017.11.22.19.38.20; Wed, 22 Nov 2017 19:38:21 -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; dkim=neutral (body hash did not verify) header.i=@smtpservice.net header.s=m78bu0.a1-4.dyn header.b=RGeSoS8F; 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; dmarc=fail (p=QUARANTINE sp=NONE dis=NONE) header.from=akamai.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 5BD4F68A16C; Thu, 23 Nov 2017 05:38:18 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from a2i831.smtp2go.com (a2i831.smtp2go.com [103.47.207.63]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 3AAA368A143 for ; Thu, 23 Nov 2017 05:38:11 +0200 (EET) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=smtpservice.net; s=m78bu0.a1-4.dyn; x=1511409197; h=Feedback-ID: X-Smtpcorp-Track:Message-Id:Date:Subject:To:From:Reply-To:Sender: List-Unsubscribe; bh=azbYw0BwSsAVAgAoyWaemzGPTIb2GqTAWMeGW9E1R4g=; b=RGeSoS8F J5QTuRZ/tLVU7feYRisqjIH/USDbTbbptD/Hod3WJUXAZxXDooFfF+P7O+E4q4MeogEMrmlvrhvdv 4uK5wYEFCDpdf0rvt93EN3AuypsROsYA5AIrXmJCHVgiRbbpx5wdlf6v5PAUvse36DzP3Goul/Le0 9WBXPjBwRgP8hUCrWhcIr6FmUIbv8D4dVu7ka/EboVLTBgF4kLzZt3TheRPnrGjdF9vj37cjiSp2m 6KYJjsy1UfIlDB6/9pt3fNY8yJl5LgJHQAy3SL45HWttywBGn9XiPb8pyn6MNFx8JCahgkdTuszw2 kepwkS/aETTbOaEIpGSZz23n2A==; From: vdixit@akamai.com To: ffmpeg-devel@ffmpeg.org Date: Thu, 23 Nov 2017 09:07:36 +0530 Message-Id: <1511408256-24718-3-git-send-email-vdixit@akamai.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1511408256-24718-1-git-send-email-vdixit@akamai.com> References: <1511408256-24718-1-git-send-email-vdixit@akamai.com> X-Smtpcorp-Track: 1-HiL1NmFjuEHI.FgK-rtnl7 Feedback-ID: 337386m:337386asVRLGB:337386syiJq4PFoo:SMTPCORP X-Report-Abuse: Please forward a copy of this message, including all headers, to Subject: [FFmpeg-devel] [PATCH 3/3] avformat/hlsenc:addition of CODECS attribute in the master playlist 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: Karthick J , Vishwanath Dixit MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" From: Vishwanath Dixit Signed-off-by: Karthick J --- libavformat/hlsenc.c | 67 +++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 66 insertions(+), 1 deletion(-) diff --git a/libavformat/hlsenc.c b/libavformat/hlsenc.c index 9fed6a3..32246c4 100644 --- a/libavformat/hlsenc.c +++ b/libavformat/hlsenc.c @@ -1065,6 +1065,52 @@ static int get_relative_url(const char *master_url, const char *media_url, return 0; } +static void get_codec_str(AVStream *vid_st, AVStream *aud_st, char *vcodec, + char *acodec, int vcodec_len, int acodec_len) { + if (vcodec_len > 0) + vcodec[0] = '\0'; + else + return; + + if (acodec_len > 0) + acodec[0] = '\0'; + else + return; + + if (!vid_st && !aud_st) { + av_log(NULL, AV_LOG_WARNING, "Atleast one stream shoud be valid\n"); + return; + } + + if (vid_st && vid_st->codecpar->profile != FF_PROFILE_UNKNOWN && + vid_st->codecpar->level != FF_LEVEL_UNKNOWN && + vid_st->codecpar->codec_id == AV_CODEC_ID_H264) { + snprintf(vcodec, vcodec_len, "avc1.%02x00%02x", + vid_st->codecpar->profile, vid_st->codecpar->level); + } + + if (aud_st) { + if (aud_st->codecpar->codec_id == AV_CODEC_ID_MP2) { + snprintf(acodec, acodec_len, "mp4a.40.33"); + } else if (aud_st->codecpar->codec_id == AV_CODEC_ID_MP3) { + snprintf(acodec, acodec_len, "mp4a.40.34"); + } else if (aud_st->codecpar->codec_id == AV_CODEC_ID_AAC) { + /* TODO : For HE-AAC, HE-AACv2, the last digit needs to be set to 5 and 29 respectively */ + snprintf(acodec, acodec_len, "mp4a.40.2"); + } else if (aud_st->codecpar->codec_id == AV_CODEC_ID_AC3) { + snprintf(acodec, acodec_len, "mp4a.A5"); + } else if (aud_st->codecpar->codec_id == AV_CODEC_ID_EAC3) { + snprintf(acodec, acodec_len, "mp4a.A6"); + } + } + + // either provide codec string for both active streams or for none + if (vid_st && aud_st && (!strlen(vcodec) || !strlen(acodec))) { + acodec[0] = vcodec[0] = '\0'; + av_log(NULL, AV_LOG_INFO, "Codec string not available for audio or video stream\n"); + } +} + static int create_master_playlist(AVFormatContext *s, VariantStream * const input_vs) { @@ -1075,7 +1121,7 @@ static int create_master_playlist(AVFormatContext *s, AVDictionary *options = NULL; unsigned int i, j; int m3u8_name_size, ret, bandwidth; - char *m3U8_rel_name; + char *m3U8_rel_name, vcodec[32], acodec[32]; input_vs->m3u8_created = 1; if (!hls->master_m3u8_created) { @@ -1203,6 +1249,25 @@ static int create_master_playlist(AVFormatContext *s, avio_printf(master_pb, ",RESOLUTION=%dx%d", vid_st->codecpar->width, vid_st->codecpar->height); + get_codec_str(vid_st, aud_st, vcodec, acodec, sizeof(vcodec), + sizeof(acodec)); + + if (strlen(vcodec) || strlen(acodec)) + avio_printf(master_pb, ",CODECS=\""); + + if (strlen(vcodec)) { + avio_printf(master_pb, "%s", vcodec); + + if (strlen(acodec)) + avio_printf(master_pb, ","); + } + + if (strlen(acodec)) + avio_printf(master_pb, "%s", acodec); + + if (strlen(vcodec) || strlen(acodec)) + avio_printf(master_pb, "\""); + if (vs->agroup && aud_st) avio_printf(master_pb, ",AUDIO=\"group_%s\"", vs->agroup);