From patchwork Wed Feb 8 02:54:06 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Liu Steven X-Patchwork-Id: 2448 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.103.89.21 with SMTP id n21csp2561109vsb; Tue, 7 Feb 2017 18:56:12 -0800 (PST) X-Received: by 10.28.54.226 with SMTP id y95mr14902789wmh.105.1486522572515; Tue, 07 Feb 2017 18:56:12 -0800 (PST) Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id m139si683913wmb.28.2017.02.07.18.56.11; Tue, 07 Feb 2017 18:56:12 -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; 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 227D26899AB; Wed, 8 Feb 2017 04:56:06 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from smtpbg321.qq.com (smtpbg321.qq.com [14.17.32.30]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 4811A680A85 for ; Wed, 8 Feb 2017 04:55:58 +0200 (EET) X-QQ-mid: bizesmtp1t1486522452tau8r36y9 Received: from localhost (unknown [47.90.47.25]) by esmtp4.qq.com (ESMTP) with id ; Wed, 08 Feb 2017 10:54:11 +0800 (CST) X-QQ-SSF: 01100000002000F0F820000A0000000 X-QQ-FEAT: FRkVFvYdryWcmuWs1RfliKKNC40CGDfjVhdrnn9Lsxs/5gioXox4IaYkCY6yZ QSxpIUCZ3BpWkPewq02npjyQsakhM90E+5IoX3DDS0+cVA4I411uPnJZ0HxKkOFT7RkKedN ks0whJjgtn/3WW/vEo9794y0i1LtJup/dh9UetopaO0vQDP0Sp+PWyWdpgwawJ6QXPt3EEv GRK3DoUyot6F/DR/5UzaUDv2+Dbr05mjmNBITbXjGFSDyZidKt+MXO/qsgJSLv+tEYedQUR I9+J+GZMeRpI+q X-QQ-GoodBg: 0 From: Steven Liu To: ffmpeg-devel@ffmpeg.org Date: Wed, 8 Feb 2017 10:54:06 +0800 Message-Id: <20170208025406.2202-1-lq@chinaffmpeg.org> X-Mailer: git-send-email 2.10.1.382.ga23ca1b.dirty X-QQ-SENDSIZE: 520 X-QQ-Bgrelay: 1 Subject: [FFmpeg-devel] [PATCH] avformat/hlsenc: deprecate hls_wrap option 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: Steven Liu MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" When user use the hls_wrap, there have many problem: 1. some platform refersh the old but usefull segment 2. CDN(Content Delivery Network) Deliver HLS not friendly The hls_wrap is used to wrap segments for use little space, now user can use hls_list_size and hls_flags delete_segments instead it. Signed-off-by: Steven Liu --- doc/muxers.texi | 5 ++--- libavformat/hlsenc.c | 24 ++++++++++++++++++++++++ libavformat/version.h | 4 ++++ 3 files changed, 30 insertions(+), 3 deletions(-) diff --git a/doc/muxers.texi b/doc/muxers.texi index cb875a4..c00e296 100644 --- a/doc/muxers.texi +++ b/doc/muxers.texi @@ -441,9 +441,8 @@ parameters. Values containing @code{:} special characters must be escaped. @item hls_wrap @var{wrap} -Set the number after which the segment filename number (the number -specified in each segment file) wraps. If set to 0 the number will be -never wrapped. Default value is 0. +This is a deprecated option, you can use @code {hls_list_size} +and @code{hls_flags delete_segments} instead it This option is useful to avoid to fill the disk with many segment files, and limits the maximum number of segment files written to disk diff --git a/libavformat/hlsenc.c b/libavformat/hlsenc.c index 17d4fe4..736c949 100644 --- a/libavformat/hlsenc.c +++ b/libavformat/hlsenc.c @@ -101,7 +101,9 @@ typedef struct HLSContext { float time; // Set by a private option. float init_time; // Set by a private option. int max_nb_segments; // Set by a private option. +#ifdef FF_API_HLS_WRAP int wrap; // Set by a private option. +#endif uint32_t flags; // enum HLSFlags uint32_t pl_type; // enum PlaylistType char *segment_filename; @@ -566,7 +568,11 @@ static int hls_append_segment(struct AVFormatContext *s, HLSContext *hls, double hls->initial_prog_date_time += en->duration; hls->segments = en->next; if (en && hls->flags & HLS_DELETE_SEGMENTS && +#ifdef FF_API_HLS_WRAP !(hls->flags & HLS_SINGLE_FILE || hls->wrap)) { +#else + !(hls->flags & HLS_SINGLE_FILE)) { +#endif en->next = hls->old_segments; hls->old_segments = en; if ((ret = hls_delete_old_segments(hls)) < 0) @@ -834,7 +840,11 @@ static int hls_start(AVFormatContext *s) sizeof(vtt_oc->filename)); } else if (c->max_seg_size > 0) { if (replace_int_data_in_filename(oc->filename, sizeof(oc->filename), +#ifdef FF_API_HLS_WRAP c->basename, 'd', c->wrap ? c->sequence % c->wrap : c->sequence) < 1) { +#else + c->basename, 'd', c->sequence) < 1) { +#endif av_log(oc, AV_LOG_ERROR, "Invalid segment filename template '%s', you can try to use -use_localtime 1 with it\n", c->basename); return AVERROR(EINVAL); } @@ -853,7 +863,11 @@ static int hls_start(AVFormatContext *s) if (!filename) return AVERROR(ENOMEM); if (replace_int_data_in_filename(oc->filename, sizeof(oc->filename), +#ifdef FF_API_HLS_WRAP filename, 'd', c->wrap ? c->sequence % c->wrap : c->sequence) < 1) { +#else + filename, 'd', c->sequence) < 1) { +#endif av_log(c, AV_LOG_ERROR, "Invalid second level segment filename template '%s', " "you can try to remove second_level_segment_index flag\n", @@ -910,13 +924,21 @@ static int hls_start(AVFormatContext *s) av_free(fn_copy); } } else if (replace_int_data_in_filename(oc->filename, sizeof(oc->filename), +#ifdef FF_API_HLS_WRAP c->basename, 'd', c->wrap ? c->sequence % c->wrap : c->sequence) < 1) { +#else + c->basename, 'd', c->sequence) < 1) { +#endif av_log(oc, AV_LOG_ERROR, "Invalid segment filename template '%s' you can try to use -use_localtime 1 with it\n", c->basename); return AVERROR(EINVAL); } if( c->vtt_basename) { if (replace_int_data_in_filename(vtt_oc->filename, sizeof(vtt_oc->filename), +#ifdef FF_API_HLS_WRAP c->vtt_basename, 'd', c->wrap ? c->sequence % c->wrap : c->sequence) < 1) { +#else + c->vtt_basename, 'd', c->sequence) < 1) { +#endif av_log(vtt_oc, AV_LOG_ERROR, "Invalid segment filename template '%s'\n", c->vtt_basename); return AVERROR(EINVAL); } @@ -1421,7 +1443,9 @@ static const AVOption options[] = { {"hls_list_size", "set maximum number of playlist entries", OFFSET(max_nb_segments), AV_OPT_TYPE_INT, {.i64 = 5}, 0, INT_MAX, E}, {"hls_ts_options","set hls mpegts list of options for the container format used for hls", OFFSET(format_options_str), AV_OPT_TYPE_STRING, {.str = NULL}, 0, 0, E}, {"hls_vtt_options","set hls vtt list of options for the container format used for hls", OFFSET(vtt_format_options_str), AV_OPT_TYPE_STRING, {.str = NULL}, 0, 0, E}, +#ifdef FF_API_HLS_WRAP {"hls_wrap", "set number after which the index wraps", OFFSET(wrap), AV_OPT_TYPE_INT, {.i64 = 0}, 0, INT_MAX, E}, +#endif {"hls_allow_cache", "explicitly set whether the client MAY (1) or MUST NOT (0) cache media segments", OFFSET(allowcache), AV_OPT_TYPE_INT, {.i64 = -1}, INT_MIN, INT_MAX, E}, {"hls_base_url", "url to prepend to each playlist entry", OFFSET(baseurl), AV_OPT_TYPE_STRING, {.str = NULL}, 0, 0, E}, {"hls_segment_filename", "filename template for segment files", OFFSET(segment_filename), AV_OPT_TYPE_STRING, {.str = NULL}, 0, 0, E}, diff --git a/libavformat/version.h b/libavformat/version.h index ff3f06d..2194f80 100644 --- a/libavformat/version.h +++ b/libavformat/version.h @@ -85,6 +85,10 @@ #ifndef FF_API_HTTP_USER_AGENT #define FF_API_HTTP_USER_AGENT (LIBAVFORMAT_VERSION_MAJOR < 58) #endif +#ifndef FF_API_HLS_WRAP +#define FF_API_HLS_WRAP (LIBAVFORMAT_VERSION_MAJOR < 58) +#endif + #ifndef FF_API_R_FRAME_RATE #define FF_API_R_FRAME_RATE 1