From patchwork Sun Jan 17 02:13:20 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lance Wang X-Patchwork-Id: 24994 Return-Path: X-Original-To: patchwork@ffaux-bg.ffmpeg.org Delivered-To: patchwork@ffaux-bg.ffmpeg.org Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by ffaux.localdomain (Postfix) with ESMTP id BE0A144B31B for ; Sun, 17 Jan 2021 04:13:36 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 86624680812; Sun, 17 Jan 2021 04:13:36 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-pf1-f177.google.com (mail-pf1-f177.google.com [209.85.210.177]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 5FA5E6807B4 for ; Sun, 17 Jan 2021 04:13:29 +0200 (EET) Received: by mail-pf1-f177.google.com with SMTP id b3so8057230pft.3 for ; Sat, 16 Jan 2021 18:13:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=enHMT7TAJAS17wv0h+r5hd5mQ1dSskZIGRegXRUvUcc=; b=sGDaLQRHuzoPZKmOH4vNHQ3p+hxrsxAJyviGfTSitdgjXI8Y7izdj3k5WfWyRoyNLe QMkGvZRCtEL7SIPLFqR4bA6kbMkLO6I71rRW5G/mvXIagGSOxkC/zF8EI9VzlqZmskJF Mcz7JN3fORl7nK/Sm5n3SdmI9NAjutpYHJpKQeqx2wmtcXIJ4k6bCM+WtcIauVfPDLxO 9H65ikKB362+lSpc5tOeiYbZKKiXDIp6NRIuEBY9PHJpA5k0BxrlIiUGRolcOl8PfrmQ 2KuxiMmYaKvjZbdmz5r/r4L5Zh3H2ihvqgRHdT0oPESuIBoYWXqedt38MUpXPP6jcyZg XEaw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=enHMT7TAJAS17wv0h+r5hd5mQ1dSskZIGRegXRUvUcc=; b=Ks3Dyr4dcW321N99t/bipCMln0MT4G4Yh2MSi5rZyipirnCJvn170SfDGf6YOPis+8 n6AWdo6upJed8FxUgVC/gZ7eWJIhbKXBMjRbvPwUXY4qHrnaHVSp1Ci2yTSd0Vk5LkEq 8ramiAgAu5B2i3eSj/ZdZpS+UhL2xsJehClX7VEsNuDkJlgxfKEnyrjcVj/754bbXYvf Eg0+y0YA5zc1jqNbCZGw/jnwj8qOHT1/Tvwu9n+Lj5DHfJ7pR3AByROFdMc9N4goCUfA DLWmDCOk3R0EYykPG/47layxEBCY7CVfevZ7TqqVOctMPBD+lv/9HA9ijoVbcOC+fFpg rbvw== X-Gm-Message-State: AOAM532t9+9Ck7z8ex6DyXV9jaZ5QzcRzUXdiy0a/EnIsymN68/uGKkI HNcFU487n9fT6/LyZU+pgsZ9hxMfeJk= X-Google-Smtp-Source: ABdhPJxPnnn0xpQvtlRanbD/euI4Qjf293mYSaAgmEvaKiKjbFh6xqCA6Ddv+UIh0iaLlX4+MGtyeg== X-Received: by 2002:a63:4559:: with SMTP id u25mr19892310pgk.306.1610849607339; Sat, 16 Jan 2021 18:13:27 -0800 (PST) Received: from vpn2.localdomain ([161.117.202.209]) by smtp.gmail.com with ESMTPSA id 6sm3580376pjm.31.2021.01.16.18.13.25 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sat, 16 Jan 2021 18:13:26 -0800 (PST) From: lance.lmwang@gmail.com To: ffmpeg-devel@ffmpeg.org Date: Sun, 17 Jan 2021 10:13:20 +0800 Message-Id: <1610849600-18575-1-git-send-email-lance.lmwang@gmail.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1609947331-6849-5-git-send-email-lance.lmwang@gmail.com> References: <1609947331-6849-5-git-send-email-lance.lmwang@gmail.com> Subject: [FFmpeg-devel] [PATCH v2] avformat/hlsenc: use AV_OPT_TYPE_DURATION 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: Limin Wang MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" From: Limin Wang Signed-off-by: Limin Wang --- doc/muxers.texi | 15 +++++++++++---- libavformat/hlsenc.c | 18 +++++++++--------- 2 files changed, 20 insertions(+), 13 deletions(-) diff --git a/doc/muxers.texi b/doc/muxers.texi index 8e12aca..1f9f293 100644 --- a/doc/muxers.texi +++ b/doc/muxers.texi @@ -609,14 +609,21 @@ segmentation. This muxer supports the following options: @table @option -@item hls_init_time @var{seconds} -Set the initial target segment length in seconds. Default value is @var{0}. +@item hls_init_time @var{duration} +Set the initial target segment length. Default value is @var{0}. + +@var{duration} must be a time duration specification, +see @ref{time duration syntax,,the Time duration section in the ffmpeg-utils(1) manual,ffmpeg-utils}. + Segment will be cut on the next key frame after this time has passed on the first m3u8 list. After the initial playlist is filled @command{ffmpeg} will cut segments at duration equal to @code{hls_time} -@item hls_time @var{seconds} -Set the target segment length in seconds. Default value is 2. +@item hls_time @var{duration} +Set the target segment length. Default value is 2. + +@var{duration} must be a time duration specification, +see @ref{time duration syntax,,the Time duration section in the ffmpeg-utils(1) manual,ffmpeg-utils}. Segment will be cut on the next key frame after this time has passed. @item hls_list_size @var{size} diff --git a/libavformat/hlsenc.c b/libavformat/hlsenc.c index 7f38db7..94fd505 100644 --- a/libavformat/hlsenc.c +++ b/libavformat/hlsenc.c @@ -196,8 +196,8 @@ typedef struct HLSContext { int64_t start_sequence; uint32_t start_sequence_source_type; // enum StartSequenceSourceType - float time; // Set by a private option. - float init_time; // Set by a private option. + int64_t time; // Set by a private option. + int64_t init_time; // Set by a private option. int max_nb_segments; // Set by a private option. int hls_delete_threshold; // Set by a private option. #if FF_API_HLS_WRAP @@ -2454,9 +2454,9 @@ static int hls_write_packet(AVFormatContext *s, AVPacket *pkt) if (vs->sequence - vs->nb_entries > hls->start_sequence && hls->init_time > 0) { /* reset end_pts, hls->recording_time at end of the init hls list */ - int64_t init_list_dur = hls->init_time * vs->nb_entries * AV_TIME_BASE; - int64_t after_init_list_dur = (vs->sequence - hls->start_sequence - vs->nb_entries) * (hls->time * AV_TIME_BASE); - hls->recording_time = hls->time * AV_TIME_BASE; + int64_t init_list_dur = hls->init_time * vs->nb_entries; + int64_t after_init_list_dur = (vs->sequence - hls->start_sequence - vs->nb_entries) * hls->time; + hls->recording_time = hls->time; end_pts = init_list_dur + after_init_list_dur ; } @@ -2941,7 +2941,7 @@ static int hls_init(AVFormatContext *s) av_log(hls, AV_LOG_DEBUG, "start_number evaluated to %"PRId64"\n", hls->start_sequence); } - hls->recording_time = (hls->init_time ? hls->init_time : hls->time) * AV_TIME_BASE; + hls->recording_time = hls->init_time ? hls->init_time : hls->time; if (hls->flags & HLS_SPLIT_BY_TIME && hls->flags & HLS_INDEPENDENT_SEGMENTS) { // Independent segments cannot be guaranteed when splitting by time @@ -3094,7 +3094,7 @@ static int hls_init(AVFormatContext *s) av_log(s, AV_LOG_WARNING, "append_list mode does not support hls_init_time," " hls_init_time value will have no effect\n"); hls->init_time = 0; - hls->recording_time = hls->time * AV_TIME_BASE; + hls->recording_time = hls->time; } } @@ -3110,8 +3110,8 @@ static int hls_init(AVFormatContext *s) #define E AV_OPT_FLAG_ENCODING_PARAM static const AVOption options[] = { {"start_number", "set first number in the sequence", OFFSET(start_sequence),AV_OPT_TYPE_INT64, {.i64 = 0}, 0, INT64_MAX, E}, - {"hls_time", "set segment length in seconds", OFFSET(time), AV_OPT_TYPE_FLOAT, {.dbl = 2}, 0, FLT_MAX, E}, - {"hls_init_time", "set segment length in seconds at init list", OFFSET(init_time), AV_OPT_TYPE_FLOAT, {.dbl = 0}, 0, FLT_MAX, E}, + {"hls_time", "set segment length", OFFSET(time), AV_OPT_TYPE_DURATION, {.i64 = 2000000}, 0, INT64_MAX, E}, + {"hls_init_time", "set segment length at init list", OFFSET(init_time), AV_OPT_TYPE_DURATION, {.i64 = 0}, 0, INT64_MAX, E}, {"hls_list_size", "set maximum number of playlist entries", OFFSET(max_nb_segments), AV_OPT_TYPE_INT, {.i64 = 5}, 0, INT_MAX, E}, {"hls_delete_threshold", "set number of unreferenced segments to keep before deleting", OFFSET(hls_delete_threshold), AV_OPT_TYPE_INT, {.i64 = 1}, 1, INT_MAX, E}, {"hls_ts_options","set hls mpegts list of options for the container format used for hls", OFFSET(format_options), AV_OPT_TYPE_DICT, {.str = NULL}, 0, 0, E},