From patchwork Fri Nov 24 15:30:39 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Jeyapal, Karthick" X-Patchwork-Id: 6337 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.2.161.94 with SMTP id m30csp2325012jah; Fri, 24 Nov 2017 07:30:54 -0800 (PST) X-Google-Smtp-Source: AGs4zMYBsD804jGqR+C8xomYZKITzK1wCRexavh1Ah2VqxcN4rJq3bjP4prllpe15b/bbWfqEZSt X-Received: by 10.28.90.65 with SMTP id o62mr9672964wmb.16.1511537454780; Fri, 24 Nov 2017 07:30:54 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1511537454; cv=none; d=google.com; s=arc-20160816; b=DyBK7wCbOBiTJ2LDRKBrf4PkYPd98dO2k0wgX50RX3g1PHhW8sJEF9JfRLqUwduEtE 7GgakrxY6vivmqAM/Fi6Dc/99D66y/Ye8LMtmNNLHaHbzfxTzyp0sF4MvVXt2ahpQzLT ARA8Al/pDEbAuwxyHTKotOC51bUduqmFjUcEH6YfieoU4TvVSK4ndIqCkMUO9tfahks4 aNuL9ik4F854+gEtZbUciSdiFSVvXp0f8IvsYy04rpS6ti6ywHpR0QZwfhJ4B8/u+zER S2gQxAnyJHysNbE0GGkAUsuIebpEHAWohqVSu4Yw+4Gk1BPabpzWOe6ZCU8mY1hWDJPh asaw== 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=YY9UUtUAXy8qelgpPShwycZfmOR1xZ2rHwVeUC8nEx4=; b=LHSMVsndHyB1IDhFe4TYrlAYsxgGDrQ4I/tnkY33JG5kf2zEWijp+Lae3qNeJgRUQC JPlVHHuo8EKqJJLw5cZ2vcYA1doRxlbflJfqBL5EdZfqN83F+MS9ywotR7Wop/NUpmB7 Y7yEPFeyRg+tiUOlrYgeDk29Od4mTrdvOqy8XtShTEc1MBOYrMlhZ7ZQtrzB3oPVbOx1 Y90RLDX/yMx4Z37Mik1G0YU4YkmgYAueesPrpTMHYx8DAmZ/8EoaLzzmdgoyr1+/0jpi WVo0QFtAdTRdbmz2Ux2pOa3qPQxgW9U3v983opJUA7Y+2RagjIvFhb7Xh5NEdptYwp+O vEcQ== 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=T+CB9tgr; 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 r3si3043682wmb.174.2017.11.24.07.30.54; Fri, 24 Nov 2017 07:30:54 -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=T+CB9tgr; 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 C0A1D68A25F; Fri, 24 Nov 2017 17:30:52 +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 EE7D86809EC for ; Fri, 24 Nov 2017 17:30:46 +0200 (EET) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=smtpservice.net; s=m78bu0.a1-4.dyn; x=1511538353; h=Feedback-ID: X-Smtpcorp-Track:Message-Id:Date:Subject:To:From:Reply-To:Sender: List-Unsubscribe; bh=+EvfzSi0mH0MskkWq8cieSTCvNF3+jVE3Yu696M24Ic=; b=T+CB9tgr at3tvkta6/D7yzO5Zqu+TsTk+1FYMiytUkl95ZkuxIr8kNdn1sy6XD4LtwhEMp4rVDYbfj6v0jVJj 79ypHJAwkID9JWNTDeyo1eN9rszLlhHGrP45C76eDlOIXgK7tw5tWTzF06Hkzv6NdJzfaV+hiAsab hQDc+lUkvFBLyhOMjJ6+mBLtQOrHPFzlphsfCco4p7SCDqSrS48aloFgoG48c9IEERwKfuFJWX9mQ xaLPD8Jz+9P+cFNlDjOuvaNfLC0YLbaxMsxaIaMbfEuIe8HiXngjO0Vt7ZFr7ZuCdm2+/JIBRb5bi hELMB7m3Y/U9fAjEVSEDnQpiTA==; From: Karthick J To: ffmpeg-devel@ffmpeg.org Date: Fri, 24 Nov 2017 21:00:39 +0530 Message-Id: <1511537439-13604-1-git-send-email-kjeyapal@akamai.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <172a80f9-3bc5-3a5c-81f1-f14f8bdad64e@jkqxz.net> References: <172a80f9-3bc5-3a5c-81f1-f14f8bdad64e@jkqxz.net> X-Smtpcorp-Track: 1-mFwDDIIdiNG9.GHskklYeF Feedback-ID: 337386m:337386asVRLGB:337386sW2p_0tqba:SMTPCORP X-Report-Abuse: Please forward a copy of this message, including all headers, to Subject: [FFmpeg-devel] [PATCH v4 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: Vishwanath Dixit MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" From: Vishwanath Dixit --- libavformat/hlsenc.c | 67 +++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 66 insertions(+), 1 deletion(-) diff --git a/libavformat/hlsenc.c b/libavformat/hlsenc.c index 58d7c58..d48963c 100644 --- a/libavformat/hlsenc.c +++ b/libavformat/hlsenc.c @@ -39,6 +39,7 @@ #include "libavutil/avstring.h" #include "libavutil/intreadwrite.h" #include "libavutil/random_seed.h" +#include "libavutil/reverse.h" #include "libavutil/opt.h" #include "libavutil/log.h" #include "libavutil/time_internal.h" @@ -1066,6 +1067,63 @@ static int get_relative_url(const char *master_url, const char *media_url, return 0; } +static char *get_codec_str(AVStream *vid_st, AVStream *aud_st) { + size_t codec_str_size = 64; + char *codec_str = av_malloc(codec_str_size); + int video_str_len = 0; + + if (!codec_str) + return NULL; + + if (!vid_st && !aud_st) { + goto fail; + } + + if (vid_st) { + if (vid_st->codecpar->profile != FF_PROFILE_UNKNOWN && + vid_st->codecpar->level != FF_LEVEL_UNKNOWN && + vid_st->codecpar->codec_id == AV_CODEC_ID_H264) { + snprintf(codec_str, codec_str_size, "avc1.%02x%02x%02x", + vid_st->codecpar->profile & 0xFF, + ff_reverse[(vid_st->codecpar->profile >> 8) & 0xFF], + vid_st->codecpar->level); + } else { + goto fail; + } + video_str_len = strlen(codec_str); + } + + if (aud_st) { + char *audio_str = codec_str; + if (video_str_len) { + codec_str[video_str_len] = ','; + video_str_len += 1; + audio_str += video_str_len; + codec_str_size -= video_str_len; + } + if (aud_st->codecpar->codec_id == AV_CODEC_ID_MP2) { + snprintf(audio_str, codec_str_size, "mp4a.40.33"); + } else if (aud_st->codecpar->codec_id == AV_CODEC_ID_MP3) { + snprintf(audio_str, codec_str_size, "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(audio_str, codec_str_size, "mp4a.40.2"); + } else if (aud_st->codecpar->codec_id == AV_CODEC_ID_AC3) { + snprintf(audio_str, codec_str_size, "mp4a.A5"); + } else if (aud_st->codecpar->codec_id == AV_CODEC_ID_EAC3) { + snprintf(audio_str, codec_str_size, "mp4a.A6"); + } else { + goto fail; + } + } + + return codec_str; + +fail: + av_free(codec_str); + return NULL; +} + static int create_master_playlist(AVFormatContext *s, VariantStream * const input_vs) { @@ -1076,7 +1134,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, *codec_str; input_vs->m3u8_created = 1; if (!hls->master_m3u8_created) { @@ -1203,6 +1261,13 @@ static int create_master_playlist(AVFormatContext *s, avio_printf(master_pb, ",RESOLUTION=%dx%d", vid_st->codecpar->width, vid_st->codecpar->height); + codec_str = get_codec_str(vid_st, aud_st); + + if (codec_str) { + avio_printf(master_pb, ",CODECS=\"%s\"", codec_str); + av_free(codec_str); + } + if (vs->agroup && aud_st) avio_printf(master_pb, ",AUDIO=\"group_%s\"", vs->agroup);