From patchwork Fri Nov 24 15:04:00 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Jeyapal, Karthick" X-Patchwork-Id: 6335 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.2.161.94 with SMTP id m30csp2292243jah; Fri, 24 Nov 2017 07:04:16 -0800 (PST) X-Google-Smtp-Source: AGs4zMZ5faGLl22xCOsuz7VeJGI8//a6FwG9KQuhqEUSdlLOMm7hzImpK5xLaAYG6P2W+5QkgDBG X-Received: by 10.28.99.131 with SMTP id x125mr10168719wmb.32.1511535856207; Fri, 24 Nov 2017 07:04:16 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1511535856; cv=none; d=google.com; s=arc-20160816; b=0hvS9wlWFrNIB/V2BGAM2VU3MBDDbX+Es2wj7omi8NDp2hR4HNs9QaRt37pSup6TqA ge70jrkwcjyVEMwo3Wk4Cfj1SJyhUsQNwKfFmw1+ZhdH9/h2IaSuqVvgmi4/K0HvJ7ML r60ALPstKRvUsjznSVc3SHg5Sl2KJW65P8Z3h5cfT8bN3P9gGOBNnwZSyo4P7s30lrbs rT3+wpFTtwG2UFH5S8Ze12ZOFEggDiQwVHU3lp+LN0PSEndsYimuezPGe7nAkzmt3Up7 q4t3YqdVzirSJfR/pZDjwYouZoZ2WpJbSFuQa568jluvgopAqTud65FO5oi6MRAlyocv 2vyQ== 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=zoeZ5qDJ51CtlH9Zwabx3lmvWQFv029V5R/psu1xcBo=; b=qaZjfA8q4m4HLBFbZYJyCht8Po9IjhYyTil2b/oV2mPtEHlj06JiXOeMBkQiErti8v fmaKuUb+BVHfZxzarfDCKbgulWmtNsvSvDXeUw+oOHZ+6t0tMjSBCKwFzF2A4rz1evJn 5FITwfOn1o/yMKAXZl0TFxb+duM+h9ShpKFtxwFlSChd+av4sG+Umt4qvsLNYHMkRov0 X9l49B23vXbys76476RkcgleqFnEj1ktQgj+topxwBEDk6VX4XQsTjLguTKYWS+OguDB T0iOkCU3Hwcc/0SYUPuke+OuNqS42KCrUfkq/t8cU8B1vaNZt4yF8qasOZokwB6fFu2R wdBQ== 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=sU9CH9s4; 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 z56si18131730wrz.517.2017.11.24.07.04.15; Fri, 24 Nov 2017 07:04:16 -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=sU9CH9s4; 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 0C4D968A265; Fri, 24 Nov 2017 17:04:14 +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 5B22D68A257 for ; Fri, 24 Nov 2017 17:04:07 +0200 (EET) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=smtpservice.net; s=m78bu0.a1-4.dyn; x=1511536753; h=Feedback-ID: X-Smtpcorp-Track:Message-Id:Date:Subject:To:From:Reply-To:Sender: List-Unsubscribe; bh=lRa8XXsFqXaDV2zgAxnXnrorPy5/QFJNEwwsIlyt0s4=; b=sU9CH9s4 5GzVHHiH6y0IuSLSM5+xQnz2jUT6yZw7IMK8u1fVDXcjA+KeBQJTSeI+8ANOhde2soBR1ObCCufjB 9OB4u5n7UQ5qvJJL8j7AD+t3GG9EcEJjWnHub3bkLSrL8NiZPMyGDNIqFufSFtljgNntiMfy5ygxP g0KxnXiOWu/nexN0KIWM2AFj83mdtjuBbAExwcK6x9LThprD1QE60FWKaHEBok7Rh75MHndW9fazR GnkXEwz+e7J6AjZewJtl2sbKaVHUg6JLqvdv7Dq6RskxDJ9P1M71B8zYU+sRDlqLNIReVOts/vooM raAfq5EulD4uwzWZrUIJFLTITQ==; From: Karthick J To: ffmpeg-devel@ffmpeg.org Date: Fri, 24 Nov 2017 20:34:00 +0530 Message-Id: <1511535840-8997-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-mFWONmF9TUCZ.GHT_1u7Oo Feedback-ID: 337386m:337386asVRLGB:337386s6rtNgvVmE:SMTPCORP X-Report-Abuse: Please forward a copy of this message, including all headers, to Subject: [FFmpeg-devel] [PATCH v3 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 | 66 +++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 65 insertions(+), 1 deletion(-) diff --git a/libavformat/hlsenc.c b/libavformat/hlsenc.c index 58d7c58..92c90a1 100644 --- a/libavformat/hlsenc.c +++ b/libavformat/hlsenc.c @@ -1066,6 +1066,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, + ((vid_st->codecpar->profile >> 8) << 4) & 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 +1133,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 +1260,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);