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 8043F42112 for ; Sun, 25 Dec 2022 18:24:47 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id C75B268B721; Sun, 25 Dec 2022 20:24:44 +0200 (EET) Received: from mout-p-101.mailbox.org (mout-p-101.mailbox.org [80.241.56.151]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 57CBC68A23A for ; Sun, 25 Dec 2022 20:24:36 +0200 (EET) Received: from smtp102.mailbox.org (smtp102.mailbox.org [IPv6:2001:67c:2050:b231:465::102]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-384) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mout-p-101.mailbox.org (Postfix) with ESMTPS id 4Ng8TF0JvGz9sLw for ; Sun, 25 Dec 2022 19:24:33 +0100 (CET) Message-ID: <47aab062-4ef2-8d78-3470-3bd49ac23fde@gyani.pro> Date: Sun, 25 Dec 2022 23:54:16 +0530 MIME-Version: 1.0 To: ffmpeg-devel@ffmpeg.org References: <20221221153857.2515-1-ffmpeg@gyani.pro> Content-Language: en-US From: Gyan Doshi In-Reply-To: <20221221153857.2515-1-ffmpeg@gyani.pro> X-Rspamd-Queue-Id: 4Ng8TF0JvGz9sLw Subject: Re: [FFmpeg-devel] [PATCH] avformat/segment: add option min_seg_duration 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 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="us-ascii"; Format="flowed" Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Archived-At: List-Archive: List-Post: On 2022-12-21 09:08 pm, Gyan Doshi wrote: > New option can be used to avoid creating very short segments with inputs > whose GOP size is variable or unharmonic with segment_time. > > Only effective with segment_time. Comments? > --- > doc/muxers.texi | 5 +++++ > libavformat/segment.c | 12 +++++++++++- > 2 files changed, 16 insertions(+), 1 deletion(-) > > diff --git a/doc/muxers.texi b/doc/muxers.texi > index 4edbb22b00..ed5341be39 100644 > --- a/doc/muxers.texi > +++ b/doc/muxers.texi > @@ -2369,6 +2369,11 @@ Note that splitting may not be accurate, unless you force the > reference stream key-frames at the given time. See the introductory > notice and the examples below. > > +@item min_seg_duration @var{time} > +Set minimum segment duration to @var{time}, the value must be a duration > +specification. This prevents the muxer ending segments at a duration below > +this value. Only effective with @code{segment_time}. Default value is "0". > + > @item segment_atclocktime @var{1|0} > If set to "1" split at regular clock time intervals starting from 00:00 > o'clock. The @var{time} value specified in @option{segment_time} is > diff --git a/libavformat/segment.c b/libavformat/segment.c > index c904e20708..c19c2a94ae 100644 > --- a/libavformat/segment.c > +++ b/libavformat/segment.c > @@ -93,6 +93,7 @@ typedef struct SegmentContext { > int list_type; ///< set the list type > AVIOContext *list_pb; ///< list file put-byte context > int64_t time; ///< segment duration > + int64_t min_seg_duration; ///< minimum segment duration > int use_strftime; ///< flag to expand filename with strftime > int increment_tc; ///< flag to increment timecode if found > > @@ -710,6 +711,10 @@ static int seg_init(AVFormatContext *s) > } > seg->clocktime_offset = seg->time - (seg->clocktime_offset % seg->time); > } > + if (seg->min_seg_duration > seg->time) { > + av_log(s, AV_LOG_ERROR, "min_seg_duration cannot be greater than segment_time\n"); > + return AVERROR(EINVAL); > + } > } > > if (seg->list) { > @@ -839,7 +844,7 @@ static int seg_write_packet(AVFormatContext *s, AVPacket *pkt) > { > SegmentContext *seg = s->priv_data; > AVStream *st = s->streams[pkt->stream_index]; > - int64_t end_pts = INT64_MAX, offset; > + int64_t end_pts = INT64_MAX, offset, pkt_pts_avtb; > int start_frame = INT_MAX; > int ret; > struct tm ti; > @@ -890,11 +895,15 @@ calc_times: > pkt->flags & AV_PKT_FLAG_KEY, > pkt->stream_index == seg->reference_stream_index ? seg->frame_count : -1); > > + if (pkt->pts != AV_NOPTS_VALUE) > + pkt_pts_avtb = av_rescale_q(pkt->pts, st->time_base, AV_TIME_BASE_Q); > + > if (pkt->stream_index == seg->reference_stream_index && > (pkt->flags & AV_PKT_FLAG_KEY || seg->break_non_keyframes) && > (seg->segment_frame_count > 0 || seg->write_empty) && > (seg->cut_pending || seg->frame_count >= start_frame || > (pkt->pts != AV_NOPTS_VALUE && > + pkt_pts_avtb - seg->cur_entry.start_pts >= seg->min_seg_duration && > av_compare_ts(pkt->pts, st->time_base, > end_pts - seg->time_delta, AV_TIME_BASE_Q) >= 0))) { > /* sanitize end time in case last packet didn't have a defined duration */ > @@ -1031,6 +1040,7 @@ static const AVOption options[] = { > { "segment_clocktime_wrap_duration", "set segment clocktime wrapping duration", OFFSET(clocktime_wrap_duration), AV_OPT_TYPE_DURATION, {.i64 = INT64_MAX}, 0, INT64_MAX, E}, > { "segment_time", "set segment duration", OFFSET(time),AV_OPT_TYPE_DURATION, {.i64 = 2000000}, INT64_MIN, INT64_MAX, 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 }, > + { "min_seg_duration", "set minimum segment duration", OFFSET(min_seg_duration), 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_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 }, _______________________________________________ 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".