Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
 help / color / mirror / Atom feed
From: Gyan Doshi <ffmpeg@gyani.pro>
To: ffmpeg-devel@ffmpeg.org
Subject: Re: [FFmpeg-devel] [PATCH] avformat/segment: add option min_seg_duration
Date: Thu, 29 Dec 2022 15:46:02 +0530
Message-ID: <9d1619f3-7c87-baf3-7773-5ecf6180a8c4@gyani.pro> (raw)
In-Reply-To: <26911bed-234e-978a-4863-8f74488aaf24@gyani.pro>



On 2022-12-28 09:26 am, Gyan Doshi wrote:
> Plan to push tomorrow.

Pushed as d39b34123daadce3c7db2851120cf10b4c3511db with a small change 
to ensure this is limited to segment_time.

>
> On 2022-12-25 11:54 pm, Gyan Doshi wrote:
>>
>>
>> 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".
>
> _______________________________________________
> 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".

_______________________________________________
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".

      reply	other threads:[~2022-12-29 10:16 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-12-21 15:38 Gyan Doshi
2022-12-25 18:24 ` Gyan Doshi
2022-12-28  3:56   ` Gyan Doshi
2022-12-29 10:16     ` Gyan Doshi [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=9d1619f3-7c87-baf3-7773-5ecf6180a8c4@gyani.pro \
    --to=ffmpeg@gyani.pro \
    --cc=ffmpeg-devel@ffmpeg.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

This inbox may be cloned and mirrored by anyone:

	git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \
		ffmpegdev@gitmailbox.com
	public-inbox-index ffmpegdev

Example config snippet for mirrors.


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git