From patchwork Wed Jan 6 15:35:31 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lance Wang X-Patchwork-Id: 24809 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 96F8944BC83 for ; Wed, 6 Jan 2021 17:43:52 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 7903F68A429; Wed, 6 Jan 2021 17:43:52 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-pg1-f170.google.com (mail-pg1-f170.google.com [209.85.215.170]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 47C5C68A0FE for ; Wed, 6 Jan 2021 17:43:46 +0200 (EET) Received: by mail-pg1-f170.google.com with SMTP id c22so2440811pgg.13 for ; Wed, 06 Jan 2021 07:43:46 -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=qUIOfVpICFUAm0pphpqT2bLzrPajKCFbu5lNNu49mrM=; b=Kuuw72iCiPAYigI8SY8r+HqFavHX9RKT6DuUyhxHLR6/2w3rNCmFA6an2aMyA/+agy hMbUeCqEKSpYRZWwpp37Wg0e04FtfQdzbubloUk4ri9SfSzNEIYXTtxvbQk1VZKtAC9G PT3Q6HPaTgo59G3wiTajGSrsSXFiZbT3+NSAwYygMcXTF/bwwTo/7LCod3j5gvKp0Ye0 e+AW5YFfnSBwuvo4QwC2fuS+9N7/exfYYYqJu/+xf4skgrE2SGPTcR24rpVR/560Epmr 33pXmzaKnUo0iIhHpynqHSy+RCfGe13YF5Plx4SsO1WrlX1C5h8jRi4Q1bwdTaaOI6FX lNhg== 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=qUIOfVpICFUAm0pphpqT2bLzrPajKCFbu5lNNu49mrM=; b=IPL45ks08yH6WbZJHkp4ZdOq3X1MnY9KjaNbYB5tbm8wvMWYR1xTrRVd4tk5Jkk3Qn eBrFPLUq4/VmRlUh5VMn3wTQxnWgBv92XpVSYlRPwPublYZ7d7y+aHIHGt8UCRcVjdG1 SVhLHmT7qigGjyKv9b3yHfTbZ8loRvkIelvbOyiRKnKiBPIbl6QIB4JxJitwWVOjeQtJ Az2YyfUtt8sLnLyJ5V04xWXjpmFEhdDHlkXAWeaG4YHd6eum8pqsdV/q1Rmo111Dv/Zx MxZCexld5N+phl83HMFpP39xOnOomUyLH+XKO+hGedVB1z9shW+YHo5GioDs27w0Ekkp 164g== X-Gm-Message-State: AOAM5304/MQyscWGGdnMJBkpbwEfGCCX2poQwiv1yGL/0PvGbGBq75V2 IXe9d5w1MWzN8BV2J1kuzJL8xdw8DXU= X-Google-Smtp-Source: ABdhPJyZGYvnZvW0LMXryMVIMXnwLc9T4vTQ6jvZSvMyPkkKaxRQLaPriU65GfBl2W9VQFcsuKxrHw== X-Received: by 2002:a63:220b:: with SMTP id i11mr5168475pgi.2.1609947345804; Wed, 06 Jan 2021 07:35:45 -0800 (PST) Received: from vpn2.localdomain ([161.117.202.209]) by smtp.gmail.com with ESMTPSA id v15sm2937963pfn.217.2021.01.06.07.35.44 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 06 Jan 2021 07:35:45 -0800 (PST) From: lance.lmwang@gmail.com To: ffmpeg-devel@ffmpeg.org Date: Wed, 6 Jan 2021 23:35:31 +0800 Message-Id: <1609947331-6849-5-git-send-email-lance.lmwang@gmail.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1609947331-6849-1-git-send-email-lance.lmwang@gmail.com> References: <1609947331-6849-1-git-send-email-lance.lmwang@gmail.com> Subject: [FFmpeg-devel] [PATCH 5/5] 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 | 4 ++-- libavformat/hlsenc.c | 18 +++++++++--------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/doc/muxers.texi b/doc/muxers.texi index 8e12aca..044c16b 100644 --- a/doc/muxers.texi +++ b/doc/muxers.texi @@ -609,13 +609,13 @@ segmentation. This muxer supports the following options: @table @option -@item hls_init_time @var{seconds} +@item hls_init_time @var{duration} Set the initial target segment length in seconds. Default value is @var{0}. 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} +@item hls_time @var{duration} Set the target segment length in seconds. Default value is 2. Segment will be cut on the next key frame after this time has passed. diff --git a/libavformat/hlsenc.c b/libavformat/hlsenc.c index 7f38db7..021a1ea 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 in seconds", OFFSET(time), AV_OPT_TYPE_DURATION, {.i64 = 2000000}, 0, INT64_MAX, E}, + {"hls_init_time", "set segment length in seconds 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},