From patchwork Fri Jun 28 03:12:18 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: hectorqin X-Patchwork-Id: 13737 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 E0B614494F2 for ; Fri, 28 Jun 2019 06:12:29 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id BF69B68A8D5; Fri, 28 Jun 2019 06:12:29 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from m13-105.163.com (m13-105.163.com [220.181.13.105]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 49E976898F6 for ; Fri, 28 Jun 2019 06:12:22 +0300 (EEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=163.com; s=s110527; h=Date:From:Subject:MIME-Version:Message-ID; bh=Pe+6Q TZJlzWzP09aBp2PO8GOjKm+3AOCUkHazdIMX3g=; b=ntBfP/7CnnJFLBSKkMe89 7vJO6xws+kWvjfVD2rBCdAai7Wymc2spOMCpz8Rscpu0u+SNI+JdeHzCCHGl1QXg zRUvUVQElXEoNdl9wYkPLl9vVJZU0ntZ9PgWxZM4XO58FjrbABKa6cGmAXz3vy+P NicLB6C6y9ylAKQFcvmfT4= Received: from hectorqin$163.com ( [61.144.147.157] ) by ajax-webmail-wmsvr105 (Coremail) ; Fri, 28 Jun 2019 11:12:18 +0800 (GMT+08:00) X-Originating-IP: [61.144.147.157] Date: Fri, 28 Jun 2019 11:12:18 +0800 (GMT+08:00) From: hectorqin To: ffmpeg-devel X-Priority: 3 X-Mailer: Coremail Webmail Server Version SP_ntes V3.5 build 20180820(5a019900) Copyright (c) 2002-2019 www.mailtech.cn 163com MIME-Version: 1.0 Message-ID: <228be254.122d.16b9c11c48e.Coremail.hectorqin@163.com> X-Coremail-Locale: zh_CN X-CM-TRANSID: acGowAAXJpmShRVdHdEtAA--.60698W X-CM-SenderInfo: xkhf30hutl0qqrwthudrp/1tbiLg7hi1SIiIO1CgABsj X-Coremail-Antispam: 1U5529EdanIXcx71UUUUU7vcSsGvfC2KfnxnUU== X-Content-Filtered-By: Mailman/MimeDel 2.1.20 Subject: [FFmpeg-devel] libavformat/segment: add an option to split the rest of stream after the segment_times is set 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" Hi all: Add an option to split the rest of stream after the segment_times is set. It's very useful to set the first some segments to a little small, and then split with a clear duration. Signed-off-by: hectorqin --- doc/muxers.texi | 5 +++++ libavformat/segment.c | 21 +++++++++++++++++++-- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/doc/muxers.texi b/doc/muxers.texi index 59c93bc687..7a0f7d2a52 100644 --- a/doc/muxers.texi +++ b/doc/muxers.texi @@ -1930,6 +1930,11 @@ Specify a list of split points. @var{times} contains a list of comma separated duration specifications, in increasing order. See also the @option{segment_time} option. +@item segment_rest_duration @var{rest_duration} +Set the rest segment duration to @var{rest_duration} when the @var{segment_times} is set, the value must be a duration +specification. Default value is "0", which means don't split the rest part. See also the +@option{segment_time} option. + @item segment_frames @var{frames} Specify a list of split video frame numbers. @var{frames} contains a list of comma separated integer numbers, in increasing order. diff --git a/libavformat/segment.c b/libavformat/segment.c index e3082063d8..8a325cd5e9 100644 --- a/libavformat/segment.c +++ b/libavformat/segment.c @@ -100,6 +100,9 @@ typedef struct SegmentContext { int64_t *times; ///< list of segment interval specification int nb_times; ///< number of elments in the times array + char *rest_duration_str; ///< rest segment duration specification string + int64_t rest_duration; ///< rest segment duration + char *frames_str; ///< segment frame numbers specification string int *frames; ///< list of frame number specification int nb_frames; ///< number of elments in the frames array @@ -698,6 +701,14 @@ static int seg_init(AVFormatContext *s) if (seg->times_str) { if ((ret = parse_times(s, &seg->times, &seg->nb_times, seg->times_str)) < 0) return ret; + if (seg->rest_duration_str) { + if ((ret = av_parse_time(&seg->rest_duration, seg->rest_duration_str, 1)) < 0) { + av_log(s, AV_LOG_ERROR, + "Invalid time duration specification '%s' for segment_rest_duration option\n", + seg->rest_duration_str); + return ret; + } + } } else if (seg->frames_str) { if ((ret = parse_frames(s, &seg->frames, &seg->nb_frames, seg->frames_str)) < 0) return ret; @@ -898,8 +909,13 @@ static int seg_write_packet(AVFormatContext *s, AVPacket *pkt) calc_times: if (seg->times) { - end_pts = seg->segment_count < seg->nb_times ? - seg->times[seg->segment_count] : INT64_MAX; + if (seg->segment_count < seg->nb_times) { + end_pts = seg->times[seg->segment_count]; + } else if (seg->rest_duration > 0) { + end_pts = seg->times[seg->nb_times - 1] + seg->rest_duration * (seg->segment_count + 1 - seg->nb_times); + } else { + end_pts = INT64_MAX; + } } else if (seg->frames) { start_frame = seg->segment_count < seg->nb_frames ? seg->frames[seg->segment_count] : INT_MAX; @@ -1084,6 +1100,7 @@ static const AVOption options[] = { { "segment_time", "set segment duration", OFFSET(time_str),AV_OPT_TYPE_STRING, {.str = NULL}, 0, 0, E }, { "segment_time_delta","set approximation value used for the segment times", OFFSET(time_delta), AV_OPT_TYPE_DURATION, {.i64 = 0}, 0, INT64_MAX, E }, { "segment_times", "set segment split time points", OFFSET(times_str),AV_OPT_TYPE_STRING,{.str = NULL}, 0, 0, E }, + { "segment_rest_duration", "set rest segment duration after out of the segment_times", OFFSET(rest_duration_str), AV_OPT_TYPE_STRING,{.str = NULL}, 0, 0, E }, { "segment_frames", "set segment split frame numbers", OFFSET(frames_str),AV_OPT_TYPE_STRING,{.str = NULL}, 0, 0, E }, { "segment_wrap", "set number after which the index wraps", OFFSET(segment_idx_wrap), AV_OPT_TYPE_INT, {.i64 = 0}, 0, INT_MAX, E }, { "segment_list_entry_prefix", "set base url prefix for segments", OFFSET(entry_prefix), AV_OPT_TYPE_STRING, {.str = NULL}, 0, 0, E },