Skip to content
Snippets Groups Projects
Commit 5a1ac463 authored by Stefano Sabatini's avatar Stefano Sabatini
Browse files

lavf/segment: do not pre-increment segment_idx value

Increment the value just when a new segment with the given index is
started. Simplify logic, improve readability.
parent 2b31aa88
No related branches found
No related tags found
No related merge requests found
...@@ -142,11 +142,12 @@ static int segment_start(AVFormatContext *s, int write_header) ...@@ -142,11 +142,12 @@ static int segment_start(AVFormatContext *s, int write_header)
oc = seg->avf; oc = seg->avf;
} }
seg->segment_idx++;
if (seg->segment_idx_wrap) if (seg->segment_idx_wrap)
seg->segment_idx %= seg->segment_idx_wrap; seg->segment_idx %= seg->segment_idx_wrap;
if (av_get_frame_filename(oc->filename, sizeof(oc->filename), 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); av_log(oc, AV_LOG_ERROR, "Invalid segment filename template '%s'\n", s->filename);
return AVERROR(EINVAL); return AVERROR(EINVAL);
} }
...@@ -407,7 +408,7 @@ static int seg_write_header(AVFormatContext *s) ...@@ -407,7 +408,7 @@ static int seg_write_header(AVFormatContext *s)
oc = seg->avf; oc = seg->avf;
if (av_get_frame_filename(oc->filename, sizeof(oc->filename), 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); ret = AVERROR(EINVAL);
goto fail; goto fail;
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment