[FFmpeg-devel] [PATCH] libavformat/segment.c: Continue using last provided segment size
Michael Ensly
michael.ensly at twobulls.com
Mon Feb 29 00:40:39 CET 2016
For a project recently I had a need for a live stream to be split into
different size segments at startup to speed-up the time to get the first
few segments. The current behaviour of segment_times when the list ends is
to transcode the rest of the input as a single segment. For a single file,
this makes some sense, but for a live stream it hangs indefinitely and
would be better to stay using one of the segment times provided.
I used the patch below to switch to my desired behaviour, but a more
flexible alternative to allow both behaviours would be to use the
segment_time argument. Currently these two arguments are mutually
exclusive, so some documentation and errors would probably need changing to
accommodate that change. I'm happy to do that change and submit a new patch
that is a feature that is desired for ffmpeg.
diff --git a/libavformat/segment.c b/libavformat/segment.c
index 0c1f633..f7680d8 100644
--- a/libavformat/segment.c
+++ b/libavformat/segment.c
@@ -764,11 +764,11 @@ static int seg_write_packet(AVFormatContext *s,
AVPacket *pkt)
return AVERROR(EINVAL);
if (seg->times) {
- end_pts = seg->segment_count < seg->nb_times ?
- seg->times[seg->segment_count] : INT64_MAX;
+ end_pts = seg->times[seg->segment_count < seg->nb_times ?
+ seg->segment_count : seg->nb_times - 1];
} else if (seg->frames) {
- start_frame = seg->segment_count < seg->nb_frames ?
- seg->frames[seg->segment_count] : INT_MAX;
+ start_frame = seg->frames[seg->segment_count < seg->nb_frames ?
+ seg->segment_count : seg->nb_frames - 1];
} else {
if (seg->use_clocktime) {
int64_t avgt = av_gettime();
More information about the ffmpeg-devel
mailing list