From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by master.gitmailbox.com (Postfix) with ESMTP id A7313431D4 for ; Fri, 24 Jun 2022 03:58:40 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 86EF668B590; Fri, 24 Jun 2022 06:58:37 +0300 (EEST) Received: from mail-ed1-f48.google.com (mail-ed1-f48.google.com [209.85.208.48]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id D08CE68B19D for ; Fri, 24 Jun 2022 06:58:31 +0300 (EEST) Received: by mail-ed1-f48.google.com with SMTP id z11so1659051edp.9 for ; Thu, 23 Jun 2022 20:58:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=VjcklQnYJ3aQgng+xY/X00MP68N4yLL0Juh1a9ZqoHg=; b=HLSO6OazWIWkIZR0i9SAjpNV3GhN/HnC9VbUJAGApIGuspDUshHNHOMbOlfDyA0It7 k6bBu3jBt2AcyfGMcriQnOBdnz1JZd5wNRtRg7MXiDQTC4+CkouahIp3s0B4O3uVPRaf yZ/GF6/h1yPnXobjF/SuWSqaDv4KY1evAgk9N5dtuNJkZK00clgmXweooJ49Ebh03le7 YgdYVxnVKxNj/KUQ951jtO6TL1Peg7s8UalFuU+2x9qnqbTt2rHkVMpahwv6GWBvFMmA VqtXayTkJCUwVSYg5H3icwDZSPnhQR64jamVgq21rA54ADGpVHDIPzxdZDwxwPIlVAFp FNAg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=VjcklQnYJ3aQgng+xY/X00MP68N4yLL0Juh1a9ZqoHg=; b=ROqM/YkaKaw19K7tgDyD1IzOh94ZHLIcdn2FWg5bTowcIdfgoLA6RSx2pThe/02dV0 xkCjzI3zbpjEBwon0oWZzD/xtXPtja9W9A2fUnda8G+ph05FNwDF+NRVxPbslYBnQTPr Do7WBYEgOEQ0aGLy9x+eGsLePetA7PVOEXRkGO6CuJZGrKqEE/ATGP0PgkrN8as/ItE4 2uumoTbIwQJQIPy6VMNOcPsVTczjB3RudFWmD6kqK+PaxMpIs/Bjv8IBKBmzi6WFpbtq bAXdfOn167Jtq/wRLi5YfG3FWNoVoS2iE1BoTV3+XcxOD5axXAojD+w2FyPszShByURr QttQ== X-Gm-Message-State: AJIora932JSMMlyd+/msQ0dOtNfOspVE0ErzZoj7D5fgkwAtiSJBgnNL gbyk0QMgJsLU+4ld8X+yhG1Z/3BAKf1H6ZLe84Y= X-Google-Smtp-Source: AGRyM1uQ9e+oxvADyPjQliL83DuUKUSZLoRzMZ/by4GRWUZ7BCL+Cf+P09AdG7sw5IaD/oS0R/+rwCyFjX4WDLLdx84= X-Received: by 2002:a05:6402:f1b:b0:436:d3c4:aef2 with SMTP id i27-20020a0564020f1b00b00436d3c4aef2mr1309127eda.27.1656043111075; Thu, 23 Jun 2022 20:58:31 -0700 (PDT) MIME-Version: 1.0 References: <20220623150040.1981341-1-wolfleekay@gmail.com> In-Reply-To: From: =?UTF-8?B?5bCR5a6H5p2O?= Date: Fri, 24 Jun 2022 11:58:19 +0800 Message-ID: To: Steven Liu X-Content-Filtered-By: Mailman/MimeDel 2.1.29 Subject: Re: [FFmpeg-devel] [PATCH] avformat/hls:use EXT-X-START instead of live_start_index if it's in playlist X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 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: FFmpeg development discussions and patches Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Archived-At: List-Archive: List-Post: > > > Hi, Steven I got it. User could use "live_start_index" option even if #EXT-X-START in the playlist. I changed the priority about #EXT-X-START/live_start_index, this is new bellow: --- libavformat/hls.c | 69 +++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 64 insertions(+), 5 deletions(-) diff --git a/libavformat/hls.c b/libavformat/hls.c index b736f093a9..309471efce 100644 --- a/libavformat/hls.c +++ b/libavformat/hls.c @@ -120,6 +120,8 @@ struct playlist { enum PlaylistType type; int64_t target_duration; int64_t start_seq_no; + int time_offset_flag; + int64_t start_time_offset; int n_segments; struct segment **segments; int needed; @@ -741,6 +743,7 @@ static int parse_playlist(HLSContext *c, const char *url, struct segment **prev_segments = NULL; int prev_n_segments = 0; int64_t prev_start_seq_no = -1; + const char *p; if (is_http && !in && c->http_persistent && c->playlist_pb) { in = c->playlist_pb; @@ -889,6 +892,18 @@ static int parse_playlist(HLSContext *c, const char *url, cur_init_section->key = NULL; } + } else if (av_strstart(line, "#EXT-X-START:", &ptr)) { + ret = ensure_playlist(c, &pls, url); + if (ret < 0) { + goto fail; + } + if (av_strstart(ptr, "TIME-OFFSET=", &p)) { + float offset = strtof(p, NULL); + pls->start_time_offset = offset * AV_TIME_BASE; + pls->time_offset_flag = 1; + } else { + goto fail; + } } else if (av_strstart(line, "#EXT-X-ENDLIST", &ptr)) { if (pls) pls->finished = 1; @@ -1721,10 +1736,54 @@ static int64_t select_cur_seq_no(HLSContext *c, struct playlist *pls) /* If this is a live stream, start live_start_index segments from the * start or end */ - if (c->live_start_index < 0) - return pls->start_seq_no + FFMAX(pls->n_segments + c->live_start_index, 0); - else - return pls->start_seq_no + FFMIN(c->live_start_index, pls->n_segments - 1); + if (c->live_start_index != INT_MIN) { + if (c->live_start_index < 0) + return pls->start_seq_no + FFMAX(pls->n_segments + + c->live_start_index, 0); + else + return pls->start_seq_no + FFMIN(c->live_start_index, + pls->n_segments - 1); + } else if (c->live_start_index == INT_MIN && !pls->time_offset_flag) { + return pls->start_seq_no + FFMAX(pls->n_segments - 3, 0); + } else { + /* If playlist indicate a TIME-OFFSET and user not use live_start_index, + * need to recalculate seq_no */ + int i; + int64_t start_timestamp; + int64_t playlist_duration = 0; + int64_t cur_timestamp = c->cur_timestamp == AV_NOPTS_VALUE ? 0 : + c->cur_timestamp; + + for (i = 0; i < pls->n_segments; i++) { + playlist_duration += pls->segments[i]->duration; + } + /* If the absolute value of TIME-OFFSET exceeds + * the duration of the playlist, it indicates either the end of the + * playlist (if positive) or the beginning of the playlist (if + * negative). */ + if (pls->start_time_offset >=0 && + pls->start_time_offset > playlist_duration) + start_timestamp = cur_timestamp + playlist_duration; + else if (pls->start_time_offset >= 0 && + pls->start_time_offset <= playlist_duration) + start_timestamp = cur_timestamp + pls->start_time_offset; + else if (pls->start_time_offset < 0 && + pls->start_time_offset < -playlist_duration) + start_timestamp = cur_timestamp; + else if (pls->start_time_offset < 0 && + pls->start_time_offset > -playlist_duration) + start_timestamp = cur_timestamp + playlist_duration + + pls->start_time_offset; + else + start_timestamp = cur_timestamp; + + find_timestamp_in_playlist(c, pls, start_timestamp, &seq_no, NULL); + av_log(c, AV_LOG_DEBUG, "start_timestamp: %" PRId64 + "cur_timestamp:%" PRId64 + "cur_seq_no:%" PRId64 "\n", + start_timestamp, cur_timestamp, seq_no); + return seq_no; + } } /* Otherwise just start on the first segment. */ @@ -2475,7 +2534,7 @@ static int hls_probe(const AVProbeData *p) #define FLAGS AV_OPT_FLAG_DECODING_PARAM static const AVOption hls_options[] = { {"live_start_index", "segment index to start live streams at (negative values are from the end)", - OFFSET(live_start_index), AV_OPT_TYPE_INT, {.i64 = -3}, INT_MIN, INT_MAX, FLAGS}, + OFFSET(live_start_index), AV_OPT_TYPE_INT, {.i64 = INT_MIN}, INT_MIN, INT_MAX, FLAGS}, {"allowed_extensions", "List of file extensions that hls is allowed to access", OFFSET(allowed_extensions), AV_OPT_TYPE_STRING, {.str = "3gp,aac,avi,ac3,eac3,flac,mkv,m3u8,m4a,m4s,m4v,mpg,mov,mp2,mp3,mp4,mpeg,mpegts,ogg,ogv,oga,ts,vob,wav"}, -- 2.24.1 (Apple Git-126) Thanks Steven _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".