From patchwork Wed Sep 26 05:58:01 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amit Kale X-Patchwork-Id: 10484 Delivered-To: ffmpegpatchwork@gmail.com Received: by 2002:a02:1286:0:0:0:0:0 with SMTP id 6-v6csp326789jap; Tue, 25 Sep 2018 22:58:15 -0700 (PDT) X-Google-Smtp-Source: ACcGV60jMOlh4y/o/Gk+XZPBmwQqmU/3V06kaQuuZMSeLU6FRXPh8i/O9iih+9Kqa97AFJaEg+n0 X-Received: by 2002:adf:ef47:: with SMTP id c7-v6mr3624679wrp.182.1537941495478; Tue, 25 Sep 2018 22:58:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1537941495; cv=none; d=google.com; s=arc-20160816; b=0m88a24T0ggdcF4unOVmxg1r0IXKnsDIC56e7BPfMMtNUEx7lyWTNjYrb8FtaN7WNa a7h8npLEiC5g49OrT00tiQPmkMw/RjtfiqI3RR0/PCQeF0EwqctpD/mHyqvZ8/G9U25D rVtUAs+YFNUV9Kl7X7ZWtRnzn4+7zZNMCAK7jPCn+6bWKx23edJM3wpCY4uwY9hV7BZf 2rf3MdRslZJlODYbG57GqpxZ6w1VZQ2OrL02o8Goq/wBpotzAa+XXaraaCJtocl3Xcxw Um83itZ3hul0CGIMQleP89i3E28ZNfCB3HmKCoM/SleqJpV2y3ztrx+j98WQTB5UKKUy QrVw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:reply-to:list-subscribe :list-help:list-post:list-archive:list-unsubscribe:list-id :precedence:subject:content-language:mime-version:user-agent:date :message-id:from:to:dkim-signature:delivered-to; bh=Gu/ExQqa/JvHqLhgAGtzgGtNfRojkQnBhJwUNxrHIgg=; b=Q1arAsQ/yjiQaUkLXJTRF3us4WM6dRILuFtdk+yN0cq5EAdQWrVJ+Cz4DCoNCIcGtA viG9flY4vlAUciRXRS1hiDWtPFt2xvO+KeuFBH+8pbBMoj0+MLUNAzDhQ01gaHZ8fbQz CGBYqAxTnWlcpLhH3TStoXBwGJRqgX/sKDhuD/kZuHksOQtE9IbYE1cLpdt0ubXPkVTd 7aVQot2mGnvfoI6swzC5GlKUy5gWy9F6ebG1k/YMNC+LGvA8RmoKja1Fg2PS6i4TDkbA ysxwHt3AZ7QPaAuj5NnpmR53QltizyiIGH5lYKsWTVUTBw6kwqByGeLiOaYgmDbeaSMW 3dBg== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@hotstar-com.20150623.gappssmtp.com header.s=20150623 header.b=jCDLuiXs; 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 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id y204-v6si3938829wmb.167.2018.09.25.22.58.15; Tue, 25 Sep 2018 22:58:15 -0700 (PDT) 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=@hotstar-com.20150623.gappssmtp.com header.s=20150623 header.b=jCDLuiXs; 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 Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id D683868A50B; Wed, 26 Sep 2018 08:57:57 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-pg1-f182.google.com (mail-pg1-f182.google.com [209.85.215.182]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 42C0D68A2C1 for ; Wed, 26 Sep 2018 08:57:51 +0300 (EEST) Received: by mail-pg1-f182.google.com with SMTP id t70-v6so8508922pgd.12 for ; Tue, 25 Sep 2018 22:58:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=hotstar-com.20150623.gappssmtp.com; s=20150623; h=to:from:subject:message-id:date:user-agent:mime-version :content-language:content-transfer-encoding; bh=30OYoPURoj9MD0Pe0nnW8M4MK+AEFFVd/GQFWlb7XWE=; b=jCDLuiXs47u1vCnYE1kAX91rdr4asErp1WJvZTBtZwVKNGorhnmT7UkswcTfluSc5h ZYdQvP09AQZeYe5ctdSEk5VUcMplYZHq2+XwDoE2jYz6h31crsO4M2c542xfaFNbGlm9 umsFISAMXVG8FcSMI4HBPu7BtZ9S3GMahUT4lyitZKH6VYdHvy9hr06pJ3WpP0agF2jb 7MEzzBP6/Ru37bc/tQ9mHV9Exhlk4A/3CnBDku+69CJyOTeb0MaYwMLOHebgVmc2tN/W exW5agAWOdd0lmRdYBKYnv65ByW9aM+XvRaTrRrSHvQIWUAVoarXF0i4Qt7Pe6ADrEPj jkXA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:to:from:subject:message-id:date:user-agent :mime-version:content-language:content-transfer-encoding; bh=30OYoPURoj9MD0Pe0nnW8M4MK+AEFFVd/GQFWlb7XWE=; b=UAiYiQYmANHrWPV+o6hTa6FpzFWwlH4wAOwCoPW6W15eIPWLQ7dSt8uc4qzcG97+lf yR+wgexsz9arPOtUr29CkIO2usjR2RoXepjAaly6FUfgbbEM9upAc1rzvbBsNS8h3VRX rnDm6+kmnBjN0tJvrD7pe4RiYTgFJdxvBu97Cd/uzq8t3ok76VHrZfFiDyEYL6WBQdFy eyhcbGaX+h4IiOQI8+0K5M2eZOv2M4yeef6UimW2tfXqY3ZwBpGtz/i5JfB238VwtYup w/q87TM1t5sINxdHgCu6kwqzj5K1trBUmU8LFICUQ7c6Jgn5rXVqPMpQo1uisOlBMWkb rJow== X-Gm-Message-State: ABuFfogjXEuy3+9G6GgnQlfCpQAz9poCEHqZvPt2b2/CG9XUU4PWhpOA Q2z1NqCpTlbdeT3jMWHxTqTHpbcfSNg= X-Received: by 2002:a63:cd02:: with SMTP id i2-v6mr3833361pgg.93.1537941485844; Tue, 25 Sep 2018 22:58:05 -0700 (PDT) Received: from [10.0.2.15] ([14.142.189.250]) by smtp.gmail.com with ESMTPSA id l3-v6sm5125736pff.8.2018.09.25.22.58.04 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 25 Sep 2018 22:58:05 -0700 (PDT) To: ffmpeg-devel@ffmpeg.org From: Amit Kale Message-ID: <9c77a691-6b97-1422-f50b-b039f6f8e208@hotstar.com> Date: Wed, 26 Sep 2018 11:28:01 +0530 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.9.1 MIME-Version: 1.0 Content-Language: en-US Subject: [FFmpeg-devel] [PATCH 3/4] Adds a new hls_flag avg_bw 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 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" If this flag is set, AVERAGE-BANDWIDTH value will be added to a master playlist entry. This flag implies peak_segment_bw. Signed-off-by: Amit Kale --- doc/muxers.texi | 4 ++++ libavformat/dashenc.c | 2 +- libavformat/hlsenc.c | 20 ++++++++++++++++---- libavformat/hlsplaylist.c | 6 ++++-- libavformat/hlsplaylist.h | 4 ++-- 5 files changed, 27 insertions(+), 9 deletions(-) Index: ffmpeg/doc/muxers.texi =================================================================== --- ffmpeg.orig/doc/muxers.texi +++ ffmpeg/doc/muxers.texi @@ -793,6 +793,10 @@ Possible values: If this flag is set, BANDWIDTH value in a master playlist entry will be set to the peak segment bandwidth. +@item avg_bw +If this flag is set, AVERAGE-BANDWIDTH value will be added to a master +playlist entry. This flag implies peak_segment_bw. + @item single_file If this flag is set, the muxer will store all segments in a single MPEG-TS file, and will use byte ranges in the playlist. HLS playlists generated with Index: ffmpeg/libavformat/dashenc.c =================================================================== --- ffmpeg.orig/libavformat/dashenc.c +++ ffmpeg/libavformat/dashenc.c @@ -919,7 +919,7 @@ static int write_manifest(AVFormatContex av_strlcat(codec_str, audio_codec_str, sizeof(codec_str)); } get_hls_playlist_name(playlist_file, sizeof(playlist_file), NULL, i); - ff_hls_write_stream_info(st, out, stream_bitrate, playlist_file, agroup, + ff_hls_write_stream_info(st, out, stream_bitrate, 0, playlist_file, agroup, codec_str, NULL); } avio_close(out); Index: ffmpeg/libavformat/hlsenc.c =================================================================== --- ffmpeg.orig/libavformat/hlsenc.c +++ ffmpeg/libavformat/hlsenc.c @@ -100,6 +100,7 @@ typedef enum HLSFlags { HLS_PERIODIC_REKEY = (1 << 12), HLS_INDEPENDENT_SEGMENTS = (1 << 13), HLS_PEAK_SEGMENT_BW = (1 << 14), + HLS_AVG_BW = (1 << 15), } HLSFlags; typedef enum { @@ -115,6 +116,8 @@ typedef struct VariantStream { AVOutputFormat *vtt_oformat; AVIOContext *out; int packets_written; + int64_t bytes_written; + double total_duration; int init_range_length; AVFormatContext *avf; @@ -1183,7 +1186,7 @@ static int create_master_playlist(AVForm AVStream *vid_st, *aud_st; AVDictionary *options = NULL; unsigned int i, j; - int m3u8_name_size, ret, bandwidth; + int m3u8_name_size, ret, bandwidth, avgbw; char *m3u8_rel_name, *ccgroup; ClosedCaptionsStream *ccs; @@ -1303,7 +1306,9 @@ static int create_master_playlist(AVForm } bandwidth = 0; - if (last && hls->flags & HLS_PEAK_SEGMENT_BW) { + avgbw = 0; + if (last && (hls->flags & HLS_PEAK_SEGMENT_BW || + hls->flags & HLS_AVG_BW)) { HLSSegment *hs = vs->segments; while (hs) { int64_t segment_bandwidth = hs->size * 8 / hs->duration; @@ -1311,6 +1316,8 @@ static int create_master_playlist(AVForm bandwidth = segment_bandwidth; hs = hs->next; } + if (hls->flags & HLS_AVG_BW) + avgbw = (vs->bytes_written * 8) / vs->total_duration; } else { if (vid_st) bandwidth += get_stream_bit_rate(vid_st); @@ -1334,8 +1341,8 @@ static int create_master_playlist(AVForm vs->ccgroup); } - ff_hls_write_stream_info(vid_st, hls->m3u8_out, bandwidth, m3u8_rel_name, - aud_st ? vs->agroup : NULL, vs->codec_attr, ccgroup); + ff_hls_write_stream_info(vid_st, hls->m3u8_out, bandwidth, avgbw, + m3u8_rel_name, aud_st ? vs->agroup : NULL, vs->codec_attr, ccgroup); av_freep(&m3u8_rel_name); } @@ -2211,6 +2218,8 @@ static int hls_write_packet(AVFormatCont new_start_pos = avio_tell(vs->avf->pb); if (hls->segment_type != SEGMENT_TYPE_FMP4) { vs->size = new_start_pos - vs->start_pos; + vs->bytes_written += vs->size; + vs->total_duration += vs->duration; } else { vs->size = new_start_pos; } @@ -2397,6 +2406,8 @@ failed: } else { vs->size = avio_tell(vs->avf->pb); } + vs->bytes_written += vs->size; + vs->total_duration += vs->duration; if (hls->segment_type != SEGMENT_TYPE_FMP4) ff_format_io_close(s, &oc->pb); @@ -2834,6 +2845,7 @@ static const AVOption options[] = { {"fmp4", "make segment file to fragment mp4 files in m3u8", 0, AV_OPT_TYPE_CONST, {.i64 = SEGMENT_TYPE_FMP4 }, 0, UINT_MAX, E, "segment_type"}, {"hls_fmp4_init_filename", "set fragment mp4 file init filename", OFFSET(fmp4_init_filename), AV_OPT_TYPE_STRING, {.str = "init.mp4"}, 0, 0, E}, {"hls_flags", "set flags affecting HLS playlist and media file generation", OFFSET(flags), AV_OPT_TYPE_FLAGS, {.i64 = 0 }, 0, UINT_MAX, E, "flags"}, + {"avg_bandwidth", "sets AVERAGE-BANDWIDTH in master play list, implies peak_segment_bw flag", 0, AV_OPT_TYPE_CONST, {.i64 = HLS_AVG_BW }, 0, UINT_MAX, E, "flags"}, {"peak_segment_bw", "sets bandwidth in master play list to peak segment bandwidth", 0, AV_OPT_TYPE_CONST, {.i64 = HLS_PEAK_SEGMENT_BW }, 0, UINT_MAX, E, "flags"}, {"single_file", "generate a single media file indexed with byte ranges", 0, AV_OPT_TYPE_CONST, {.i64 = HLS_SINGLE_FILE }, 0, UINT_MAX, E, "flags"}, {"temp_file", "write segment to temporary file and rename when complete", 0, AV_OPT_TYPE_CONST, {.i64 = HLS_TEMP_FILE }, 0, UINT_MAX, E, "flags"}, Index: ffmpeg/libavformat/hlsplaylist.c =================================================================== --- ffmpeg.orig/libavformat/hlsplaylist.c +++ ffmpeg/libavformat/hlsplaylist.c @@ -46,8 +46,8 @@ void ff_hls_write_audio_rendition(AVIOCo } void ff_hls_write_stream_info(AVStream *st, AVIOContext *out, - int bandwidth, char *filename, char *agroup, - char *codecs, char *ccgroup) { + int bandwidth, int avgbw, char *filename, + char *agroup, char *codecs, char *ccgroup) { if (!out || !filename) return; @@ -59,6 +59,8 @@ void ff_hls_write_stream_info(AVStream * } avio_printf(out, "#EXT-X-STREAM-INF:BANDWIDTH=%d", bandwidth); + if (avgbw != 0) + avio_printf(out, ",AVERAGE-BANDWIDTH=%d", avgbw); if (st && st->codecpar->width > 0 && st->codecpar->height > 0) avio_printf(out, ",RESOLUTION=%dx%d", st->codecpar->width, st->codecpar->height); Index: ffmpeg/libavformat/hlsplaylist.h =================================================================== --- ffmpeg.orig/libavformat/hlsplaylist.h +++ ffmpeg/libavformat/hlsplaylist.h @@ -40,8 +40,8 @@ void ff_hls_write_playlist_version(AVIOC void ff_hls_write_audio_rendition(AVIOContext *out, char *agroup, char *filename, int name_id, int is_default); void ff_hls_write_stream_info(AVStream *st, AVIOContext *out, - int bandwidth, char *filename, char *agroup, - char *codecs, char *ccgroup); + int bandwidth, int avgbw, char *filename, + char *agroup, char *codecs, char *ccgroup); void ff_hls_write_playlist_header(AVIOContext *out, int version, int allowcache, int target_duration, int64_t sequence, uint32_t playlist_type);