Provide a way to wrap around the segment index so pseudostreaming
live through a web server and html5 browser is simpler.
Also ensure that 0 (disable) is a valid value across the options
providing wrap around.
... | ... |
@@ -353,6 +353,8 @@ Set segment duration to @var{t} seconds. |
353 | 353 |
Generate also a listfile named @var{name}. |
354 | 354 |
@item segment_list_size @var{size} |
355 | 355 |
Overwrite the listfile once it reaches @var{size} entries. |
356 |
+@item segment_wrap @var{limit} |
|
357 |
+Wrap around segment index once it reaches @var{limit}. |
|
356 | 358 |
@end table |
357 | 359 |
|
358 | 360 |
@example |
... | ... |
@@ -39,6 +39,7 @@ typedef struct { |
39 | 39 |
char *list; /**< Set by a private option. */ |
40 | 40 |
float time; /**< Set by a private option. */ |
41 | 41 |
int size; /**< Set by a private option. */ |
42 |
+ int wrap; /**< Set by a private option. */ |
|
42 | 43 |
int64_t offset_time; |
43 | 44 |
int64_t recording_time; |
44 | 45 |
int has_video; |
... | ... |
@@ -51,6 +52,9 @@ static int segment_start(AVFormatContext *s) |
51 | 51 |
AVFormatContext *oc = c->avf; |
52 | 52 |
int err = 0; |
53 | 53 |
|
54 |
+ if (c->wrap) |
|
55 |
+ c->number %= c->wrap; |
|
56 |
+ |
|
54 | 57 |
if (av_get_frame_filename(oc->filename, sizeof(oc->filename), |
55 | 58 |
s->filename, c->number++) < 0) |
56 | 59 |
return AVERROR(EINVAL); |
... | ... |
@@ -206,12 +210,11 @@ static int seg_write_packet(AVFormatContext *s, AVPacket *pkt) |
206 | 206 |
if (seg->list) { |
207 | 207 |
avio_printf(seg->pb, "%s\n", oc->filename); |
208 | 208 |
avio_flush(seg->pb); |
209 |
- if (!(seg->number % seg->size)) { |
|
209 |
+ if (seg->size && !(seg->number % seg->size)) { |
|
210 | 210 |
avio_close(seg->pb); |
211 | 211 |
if ((ret = avio_open2(&seg->pb, seg->list, AVIO_FLAG_WRITE, |
212 | 212 |
&s->interrupt_callback, NULL)) < 0) |
213 | 213 |
goto fail; |
214 |
- |
|
215 | 214 |
} |
216 | 215 |
} |
217 | 216 |
} |
... | ... |
@@ -250,6 +253,7 @@ static const AVOption options[] = { |
250 | 250 |
{ "segment_time", "segment length in seconds", OFFSET(time), AV_OPT_TYPE_FLOAT, {.dbl = 2}, 0, FLT_MAX, E }, |
251 | 251 |
{ "segment_list", "output the segment list", OFFSET(list), AV_OPT_TYPE_STRING, {.str = NULL}, 0, 0, E }, |
252 | 252 |
{ "segment_list_size", "maximum number of playlist entries", OFFSET(size), AV_OPT_TYPE_INT, {.dbl = 5}, 0, INT_MAX, E }, |
253 |
+ { "segment_wrap", "number after which the index wraps", OFFSET(wrap), AV_OPT_TYPE_INT, {.dbl = 0}, 0, INT_MAX, E }, |
|
253 | 254 |
{ NULL }, |
254 | 255 |
}; |
255 | 256 |
|