From patchwork Mon Feb 12 08:55:03 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Amit Kale X-Patchwork-Id: 7562 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.2.150.1 with SMTP id c1csp3756784jai; Mon, 12 Feb 2018 01:01:13 -0800 (PST) X-Google-Smtp-Source: AH8x225ypPoVPO0jajndITtiDaoD+O8VjrhZjlcezSzZgtGI/M0jFC5bin94JHY9lqMHNsI4TxDs X-Received: by 10.28.165.4 with SMTP id o4mr2796638wme.66.1518426073298; Mon, 12 Feb 2018 01:01:13 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1518426073; cv=none; d=google.com; s=arc-20160816; b=Dx4NDAgjphSS1dadON99tjw3OrxyyGn2SqfMNYIbmUjHLQ+j7E2cT/iYPTAWt+2n8d UiCGbQeNHqXuHpjbtSQypdSgCjjcNQffqDXjYFV0LQcxQkF8ehQKGifQww0k4N72Jdiu OBkJmbv33Y6hXjM88oY382ScQPs2lBkr1OmSXcxL2CFYcWKRXXq0RChenlcqSAlRQdki 4tbjbTvXOFJ3DMlHWxUWRpAgPdoQvlAtB4mcC+iIPQIEPqa2GbHCBgZSwsgw/sTVnf8w wtTuglakyOWLN3ctR053NNDhFEsBDfef3tgaKCXt6e1DCWc0DTwKBoJETI2RNiexC8xT SubA== 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 :arc-authentication-results; bh=YMX+DbVvZ6YxO9UWf6JJysIZo73cAQ7+LVYOVlXV46Y=; b=rjnl34HHU4BduYg3lIgYBB3I3Lo9ppACSTpnmEjb9YQduzpZ40zOyfO1Mfs1Jo7z9z yZgqXSdHUi8m8LV8N4cuWpcmaM8nFoJh6M9bQo6uLIO6w5yMYYO5qbaHgwy5RnrSwK2X YYxPwzyQPlSRiYofXcZU25C+LTyntMJzCvsHdlZ5322CJ6nb8I+q7TRy41PMO7zgSIyX c1j2XTtKqAws299vogRa7lS42zZ/i4QmpsA0GhO78+uEBZcW8tG4kn5mA8iZAN2yJWoU Qj9XxYVVw7H/DDES8+skAVznfab0LuhQEdqv1isoKlVb9B2U8imGPxq7rE2rYI5t9B6/ Q/qg== 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=DXFYhBnb; 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 x23si3291664wmc.187.2018.02.12.01.01.12; Mon, 12 Feb 2018 01:01:13 -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=@hotstar-com.20150623.gappssmtp.com header.s=20150623 header.b=DXFYhBnb; 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 119CC689A69; Mon, 12 Feb 2018 11:01:01 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-it0-f65.google.com (mail-it0-f65.google.com [209.85.214.65]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id D4D87689A03 for ; Mon, 12 Feb 2018 11:00:53 +0200 (EET) Received: by mail-it0-f65.google.com with SMTP id e1so5693749ita.0 for ; Mon, 12 Feb 2018 01:01:04 -0800 (PST) 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-transfer-encoding:content-language; bh=LpqBZQF0SSoiy8Rw3KWAl2vRtl5fDL7V8c+xVCeCeQg=; b=DXFYhBnbrXCprG41LeBGrwBNPJ+V4cdzk/P0LyGo+k1HeQTVK/Isn3OqytJCAvJomD B4YTjIQ1wfBRtOAs4MeWsGwyJr6+vQZInanA8Qc0ytN2TxOfZbQXmZc2xdST2wKnT+sf V1XGic9HumqpyJpaGrtNG4fSY9nQajlST318mLS/43U6F11/D6QiYSV4Dcyg72T0uHhE vqu34Q7pFabCgP/OA7DGnTFnDzxFOR6SOqcb3HMjClM7npQ9k3h/5P4h4qthIDEyXbHQ qi6oofTWdk8rsbJhaKABreQwZQJRIb7Jkh62MdKESySsolL7LKBQzERuK6OzYCkWmA2L isRg== 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-transfer-encoding:content-language; bh=LpqBZQF0SSoiy8Rw3KWAl2vRtl5fDL7V8c+xVCeCeQg=; b=Mr5Fd9IoOlx4YkKPCLkFpvPnub9l7olQVcCA99rjqGEseiU4uV66ERkuwuPLyo4ivI +Dzx5lhWAkVsYNHD+CiLx/ohWHIzCw3E2PXOOH4DdKNqoOSTRkx03jNOhwpSuoA2gUxy 5RplVkliY/qxxuHYsiaC/HJn6Sb8yMEH8LEKG0SaJeHfjnyICQO7ZfzpZFM+CSazPq3P tmYFppI7FHxf1gHXoNYk/zN3NVQ1UhwiRMBar8/4ETW48Ttmf9pJRDegy2AovqdFZ3zK yDI2o6TR1utuJnFOKTYIIRCy189W+iye8knOwipn1ZfX581F337kFSVPWtS23h8vY+Nt UPCQ== X-Gm-Message-State: APf1xPBjUGIaaQ+GK3zGpZKjGTcF3SL2PbT559XZP85LQ+hbOHIT6eDx bPc9gSST79Rct8BCr8sk1s8xeSKVWyA= X-Received: by 10.36.254.1 with SMTP id w1mr4586170ith.50.1518425706780; Mon, 12 Feb 2018 00:55:06 -0800 (PST) Received: from [192.168.1.104] ([123.201.100.24]) by smtp.gmail.com with ESMTPSA id c13sm6573303itd.27.2018.02.12.00.55.05 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 12 Feb 2018 00:55:06 -0800 (PST) To: FFmpeg development discussions and patches From: Amit Kale Message-ID: Date: Mon, 12 Feb 2018 14:25:03 +0530 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.6.0 MIME-Version: 1.0 Content-Language: en-US Subject: [FFmpeg-devel] [PATCH 3/3] 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. ---  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(-) allowcache,                                    int target_duration, int64_t sequence,                                    uint32_t playlist_type); diff --git a/doc/muxers.texi b/doc/muxers.texi index e2c9cbfa2f..428d4009b3 100644 --- a/doc/muxers.texi +++ b/doc/muxers.texi @@ -745,6 +745,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 diff --git a/libavformat/dashenc.c b/libavformat/dashenc.c index 0f6f4f22fa..a918f7e649 100644 --- a/libavformat/dashenc.c +++ b/libavformat/dashenc.c @@ -827,7 +827,7 @@ static int write_manifest(AVFormatContext *s, int final)                  stream_bitrate += max_audio_bitrate;              }              get_hls_playlist_name(playlist_file, sizeof(playlist_file), NULL, i); -            ff_hls_write_stream_info(st, out, stream_bitrate, playlist_file, agroup, NULL, NULL); +            ff_hls_write_stream_info(st, out, stream_bitrate, 0, playlist_file, agroup, NULL, NULL);          }          avio_close(out);          if (use_rename) diff --git a/libavformat/hlsenc.c b/libavformat/hlsenc.c index f40cd0b98f..aa704c94f8 100644 --- a/libavformat/hlsenc.c +++ b/libavformat/hlsenc.c @@ -99,6 +99,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 { @@ -113,6 +114,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; @@ -1177,7 +1180,7 @@ static int create_master_playlist(AVFormatContext *s,      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; @@ -1294,7 +1297,9 @@ static int create_master_playlist(AVFormatContext *s,          }          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; @@ -1302,6 +1307,8 @@ static int create_master_playlist(AVFormatContext *s,                      bandwidth = segment_bandwidth;                  hs = hs->next;              } +            if (hls->flags & HLS_AVG_BW) +                avgbw = vs->bytes_written / vs->total_duration;          } else {              if (vid_st)                  bandwidth += vid_st->codecpar->bit_rate; @@ -1325,8 +1332,8 @@ static int create_master_playlist(AVFormatContext *s,                          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);      } @@ -2191,6 +2198,8 @@ static int hls_write_packet(AVFormatContext *s, AVPacket *pkt)          new_start_pos = avio_tell(vs->avf->pb);          vs->size = new_start_pos - vs->start_pos; +        vs->bytes_written += vs->size; +        vs->total_duration += vs->duration;          if (!byterange_mode) {              if (hls->segment_type == SEGMENT_TYPE_FMP4) { @@ -2326,6 +2335,8 @@ failed:      av_write_trailer(oc);      if (oc->pb) {          vs->size = avio_tell(vs->avf->pb) - vs->start_pos; +        vs->bytes_written += vs->size; +        vs->total_duration += vs->duration;          if (hls->segment_type != SEGMENT_TYPE_FMP4)              ff_format_io_close(s, &oc->pb); @@ -2765,6 +2776,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"}, diff --git a/libavformat/hlsplaylist.c b/libavformat/hlsplaylist.c index efcbff0009..11772e4ed9 100644 --- a/libavformat/hlsplaylist.c +++ b/libavformat/hlsplaylist.c @@ -46,8 +46,8 @@ void ff_hls_write_audio_rendition(AVIOContext *out, char *agroup,  }  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 *st, AVIOContext *out,      }      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); diff --git a/libavformat/hlsplaylist.h b/libavformat/hlsplaylist.h index 5054b01c8f..d981a5e4ee 100644 --- a/libavformat/hlsplaylist.h +++ b/libavformat/hlsplaylist.h @@ -40,8 +40,8 @@ void ff_hls_write_playlist_version(AVIOContext *out, int version);  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