[FFmpeg-devel] [PATCH] lavf/segment: do not pre-increment segment_idx value

Stefano Sabatini stefasab at gmail.com
Sat Nov 17 17:43:41 CET 2012


Increment the value just when a new segment with the given index is
started. Simplify logic, improve readability.
---
 libavformat/segment.c |    5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/libavformat/segment.c b/libavformat/segment.c
index 1ad55ce..f8bbd3b 100644
--- a/libavformat/segment.c
+++ b/libavformat/segment.c
@@ -131,11 +131,12 @@ static int segment_start(AVFormatContext *s, int write_header)
         oc = seg->avf;
     }
 
+    seg->segment_idx++;
     if (seg->segment_idx_wrap)
         seg->segment_idx %= seg->segment_idx_wrap;
 
     if (av_get_frame_filename(oc->filename, sizeof(oc->filename),
-                              s->filename, seg->segment_idx++) < 0) {
+                              s->filename, seg->segment_idx) < 0) {
         av_log(oc, AV_LOG_ERROR, "Invalid segment filename template '%s'\n", s->filename);
         return AVERROR(EINVAL);
     }
@@ -396,7 +397,7 @@ static int seg_write_header(AVFormatContext *s)
     oc = seg->avf;
 
     if (av_get_frame_filename(oc->filename, sizeof(oc->filename),
-                              s->filename, seg->segment_idx++) < 0) {
+                              s->filename, seg->segment_idx) < 0) {
         ret = AVERROR(EINVAL);
         goto fail;
     }
-- 
1.7.9.5



More information about the ffmpeg-devel mailing list