From patchwork Fri Nov 24 09:34:27 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Jeyapal, Karthick" X-Patchwork-Id: 6328 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.2.161.94 with SMTP id m30csp1899025jah; Fri, 24 Nov 2017 01:34:47 -0800 (PST) X-Google-Smtp-Source: AGs4zMYaAA7cqFPq1QiN9yapGdVMQgWI17UVf49M/Eva9LnMAmRWsnhRo6ln95IcP4V/MpWo0Yn4 X-Received: by 10.28.209.141 with SMTP id i135mr8861307wmg.153.1511516087121; Fri, 24 Nov 2017 01:34:47 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1511516086; cv=none; d=google.com; s=arc-20160816; b=lr7MnDmp5nVfSb2G9i16mmGQ54lmNCu2QKgFq78o/7SKCbzbxQ+EXpHKEBsc4EQQkR D9Q/H9oEwpRLuNIaEhcr/Q4CvEsmdmWTEmJpwbLOVB/gVKf8jw4qwnVdso4BkqExjM0h sZtlwQmgNBcxCRhNvKEF/SvTLMQ9GZd9V5lFGAOfqceKQNhi5eUaVstvlcvK0t61JvYX 4R6v55BWospzXh4stHftiAOB9+6Z7D615VkYbgdkfIf4Za9R2iGNPoOCuYfHkp5If6p+ nw/T3CpFYhPeCRij6EIvg7jD7xut6t3wcbO7S+boVMllARmCNzzKLic/WqjYrW9taIOO yqiA== 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=Du6NDNe+tc3L1KDvKu5cJwE0YXarrRUXmhPfjckQgp4=; b=yPoT4djRsOsVKgzgbyxKx/ljMFZU0lhIHtjGZhSOx6x0697HbR42s9HdsdiWKJ69MB CZj0JThERmnhmVR5CyUurTGLUsqtwiUj7ruvhCV3g0FTVRe4DZ6Xjghrhg8rTkOKM1Lv 73glywqZET/02Lc4Hn+Q49mds5P04vDJLOcZPenFqT4PowX1dVWVYdU9vnQhF6zCn3wl QLpV3DIRgBzTUepLgr8HQurgnbucp84hQUbzIFv4A/6y8TY1wJh+0gmLuatchCaXPJty IVxWrK8zhM74uWGlkQV+fu3WynN5qoBBRgtzuMKqGJJeDIrSD+qMsT/TtzIOliM74pOI XiJQ== 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=ofgnQXr8; 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 w83si6663836wma.41.2017.11.24.01.34.46; Fri, 24 Nov 2017 01:34:46 -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=ofgnQXr8; 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 F1424689FF7; Fri, 24 Nov 2017 11:34:43 +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 5CDA9689FC9 for ; Fri, 24 Nov 2017 11:34:37 +0200 (EET) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=smtpservice.net; s=m78bu0.a1-4.dyn; x=1511516983; h=Feedback-ID: X-Smtpcorp-Track:Message-Id:Date:Subject:To:From:Reply-To:Sender: List-Unsubscribe; bh=50v1zM9JjWwPz4Hvf9ikqNm/FafWZUtdT2UfVM3/T0s=; b=ofgnQXr8 09v5Y30g4Z4Rr9drd09ynLPbXtgrI7cClld/D++oOO1gT3e+9cPtNOd7ufHguJFmc0KrOB7DdTENH dp6Ow3za/8awbrdTJikK4vfpVeAjF9jpa5MGNn37ACbZRZQLHJEwTfPobEZ4JkdXjQRQCTmNhTA9V eA/akPG6Halw0PIzQOJPuqxqfCOcUCBCDmbOGiDeA2vTbSgRlB9RqtxYVKZAqf/YoEtGX7+nB2NAC dM2avTy2V8cQu+4SYBFzjpWNAI5h7AuF6XPwiNHJRiDaE4Zg+xJfNU5UXioyHqhpHCOP7rGyd2NSp mISh3SBic6w/xPxXW8ahVmjObg==; From: Karthick J To: ffmpeg-devel@ffmpeg.org Date: Fri, 24 Nov 2017 15:04:27 +0530 Message-Id: <1511516067-19633-1-git-send-email-kjeyapal@akamai.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: References: X-Smtpcorp-Track: 1-mjNVNmF8R88F.F6-oA8AN9 Feedback-ID: 337386m:337386asVRLGB:337386st2VIYxma1:SMTPCORP X-Report-Abuse: Please forward a copy of this message, including all headers, to Subject: [FFmpeg-devel] [PATCH v2 1/3] avformat/hlsenc:addition of #EXT-X-MEDIA tag and AUDIO attribute 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 --- doc/muxers.texi | 12 ++++++++++ libavformat/hlsenc.c | 63 ++++++++++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 73 insertions(+), 2 deletions(-) diff --git a/doc/muxers.texi b/doc/muxers.texi index 9d9ca31..7e6d594 100644 --- a/doc/muxers.texi +++ b/doc/muxers.texi @@ -831,6 +831,18 @@ be a video only stream with video bitrate 1000k, the second variant stream will be an audio only stream with bitrate 64k and the third variant stream will be a video only stream with bitrate 256k. Here, three media playlist with file names out_1.m3u8, out_2.m3u8 and out_3.m3u8 will be created. +@example +ffmpeg -re -i in.ts -b:a:0 32k -b:a:1 64k -b:v:0 1000k -b:v:1 3000k \ + -map 0:a -map 0:a -map 0:v -map 0:v -f hls \ + -var_stream_map "a:0,agroup:aud_low a:1,agroup:aud_high v:0,agroup:aud_low v:1,agroup:aud_high" \ + -master_pl_name master.m3u8 \ + http://example.com/live/out.m3u8 +@end example +This example creates two audio only and two video only variant streams. In +addition to the #EXT-X-STREAM-INF tag for each variant stream in the master +playlist, #EXT-X-MEDIA tag is also added for the two audio only variant streams +and they are mapped to the two video only variant streams with audio group names +'aud_low' and 'aud_high'. By default, a single hls variant containing all the encoded streams is created. diff --git a/libavformat/hlsenc.c b/libavformat/hlsenc.c index 30ccf73..58d7c58 100644 --- a/libavformat/hlsenc.c +++ b/libavformat/hlsenc.c @@ -147,6 +147,7 @@ typedef struct VariantStream { AVStream **streams; unsigned int nb_streams; int m3u8_created; /* status of media play-list creation */ + char *agroup; /* audio group name */ char *baseurl; } VariantStream; @@ -1069,7 +1070,7 @@ static int create_master_playlist(AVFormatContext *s, VariantStream * const input_vs) { HLSContext *hls = s->priv_data; - VariantStream *vs; + VariantStream *vs, *temp_vs; AVStream *vid_st, *aud_st; AVIOContext *master_pb = 0; AVDictionary *options = NULL; @@ -1104,6 +1105,34 @@ static int create_master_playlist(AVFormatContext *s, avio_printf(master_pb, "#EXTM3U\n"); avio_printf(master_pb, "#EXT-X-VERSION:%d\n", hls->version); + /* For audio only variant streams add #EXT-X-MEDIA tag with attributes*/ + for (i = 0; i < hls->nb_varstreams; i++) { + vs = &(hls->var_streams[i]); + + if (vs->has_video || vs->has_subtitle || !vs->agroup) + continue; + + m3u8_name_size = strlen(vs->m3u8_name) + 1; + m3u8_rel_name = av_malloc(m3u8_name_size); + if (!m3u8_rel_name) { + ret = AVERROR(ENOMEM); + goto fail; + } + av_strlcpy(m3u8_rel_name, vs->m3u8_name, m3u8_name_size); + ret = get_relative_url(hls->master_m3u8_url, vs->m3u8_name, + m3u8_rel_name, m3u8_name_size); + if (ret < 0) { + av_log(s, AV_LOG_ERROR, "Unable to find relative URL\n"); + goto fail; + } + + avio_printf(master_pb, "#EXT-X-MEDIA:TYPE=AUDIO,GROUP-ID=\"group_%s\"", + vs->agroup); + avio_printf(master_pb, ",NAME=\"audio_0\",DEFAULT=YES,URI=\"%s\"\n", + m3u8_rel_name); + av_freep(&m3u8_rel_name); + } + /* For variant streams with video add #EXT-X-STREAM-INF tag with attributes*/ for (i = 0; i < hls->nb_varstreams; i++) { vs = &(hls->var_streams[i]); @@ -1136,6 +1165,25 @@ static int create_master_playlist(AVFormatContext *s, continue; } + /** + * Traverse through the list of audio only rendition streams and find + * the rendition which has highest bitrate in the same audio group + */ + if (vs->agroup) { + for (j = 0; j < hls->nb_varstreams; j++) { + temp_vs = &(hls->var_streams[j]); + if (!temp_vs->has_video && !temp_vs->has_subtitle && + temp_vs->agroup && + !strcmp(temp_vs->agroup, vs->agroup)) { + if (!aud_st) + aud_st = temp_vs->streams[0]; + if (temp_vs->streams[0]->codecpar->bit_rate > + aud_st->codecpar->bit_rate) + aud_st = temp_vs->streams[0]; + } + } + } + bandwidth = 0; if (vid_st) bandwidth += vid_st->codecpar->bit_rate; @@ -1154,6 +1202,10 @@ static int create_master_playlist(AVFormatContext *s, if (vid_st && vid_st->codecpar->width > 0 && vid_st->codecpar->height > 0) avio_printf(master_pb, ",RESOLUTION=%dx%d", vid_st->codecpar->width, vid_st->codecpar->height); + + if (vs->agroup && aud_st) + avio_printf(master_pb, ",AUDIO=\"group_%s\"", vs->agroup); + avio_printf(master_pb, "\n%s\n\n", m3u8_rel_name); av_freep(&m3u8_rel_name); @@ -1546,6 +1598,7 @@ static int parse_variant_stream_mapstring(AVFormatContext *s) /** * Expected format for var_stream_map string is as below: * "a:0,v:0 a:1,v:1" + * "a:0,agroup:a0 a:1,agroup:a1 v:0,agroup:a0 v:1,agroup:a1" * This string specifies how to group the audio, video and subtitle streams * into different variant streams. The variant stream groups are separated * by space. @@ -1554,6 +1607,7 @@ static int parse_variant_stream_mapstring(AVFormatContext *s) * respectively. Allowed values are 0 to 9 digits (limited just based on * practical usage) * + * agroup: is key to specify audio group. A string can be given as value. */ p = av_strdup(hls->var_stream_map); q = p; @@ -1592,7 +1646,10 @@ static int parse_variant_stream_mapstring(AVFormatContext *s) while (keyval = av_strtok(varstr, ",", &saveptr2)) { varstr = NULL; - if (av_strstart(keyval, "v:", &val)) { + if (av_strstart(keyval, "agroup:", &val)) { + vs->agroup = av_strdup(val); + continue; + } else if (av_strstart(keyval, "v:", &val)) { codec_type = AVMEDIA_TYPE_VIDEO; } else if (av_strstart(keyval, "a:", &val)) { codec_type = AVMEDIA_TYPE_AUDIO; @@ -2050,6 +2107,7 @@ fail: av_freep(&vs->m3u8_name); av_freep(&vs->vtt_m3u8_name); av_freep(&vs->streams); + av_freep(&vs->agroup); av_freep(&vs->baseurl); if (vs->avf) avformat_free_context(vs->avf); @@ -2289,6 +2347,7 @@ static int hls_write_trailer(struct AVFormatContext *s) av_free(old_filename); av_freep(&vs->m3u8_name); av_freep(&vs->streams); + av_freep(&vs->agroup); av_freep(&vs->baseurl); }