segment: basic pattern support and playlist output
Yet another option half implemented, more will follow...
This commit is contained in:
@@ -35,6 +35,7 @@ typedef struct {
|
|||||||
char path[1024];
|
char path[1024];
|
||||||
AVFormatContext *avf;
|
AVFormatContext *avf;
|
||||||
char *format; /**< Set by a private option. */
|
char *format; /**< Set by a private option. */
|
||||||
|
char *pattern; /**< Set by a private option. */
|
||||||
float time; /**< Set by a private option. */
|
float time; /**< Set by a private option. */
|
||||||
int64_t offset_time;
|
int64_t offset_time;
|
||||||
int64_t recording_time;
|
int64_t recording_time;
|
||||||
@@ -49,7 +50,8 @@ static int segment_header(SegmentContext *s)
|
|||||||
|
|
||||||
av_strlcpy(oc->filename, s->path, sizeof(oc->filename));
|
av_strlcpy(oc->filename, s->path, sizeof(oc->filename));
|
||||||
|
|
||||||
av_strlcatf(oc->filename, sizeof(oc->filename), "%03d", s->number++);
|
av_strlcatf(oc->filename, sizeof(oc->filename),
|
||||||
|
s->pattern, s->number++);
|
||||||
|
|
||||||
if ((err = avio_open(&oc->pb, oc->filename, AVIO_FLAG_WRITE)) < 0) {
|
if ((err = avio_open(&oc->pb, oc->filename, AVIO_FLAG_WRITE)) < 0) {
|
||||||
return err;
|
return err;
|
||||||
@@ -116,7 +118,8 @@ static int seg_write_header(AVFormatContext *s)
|
|||||||
|
|
||||||
av_strlcpy(oc->filename, seg->path, sizeof(oc->filename));
|
av_strlcpy(oc->filename, seg->path, sizeof(oc->filename));
|
||||||
|
|
||||||
av_strlcatf(oc->filename, sizeof(oc->filename), "%2d", seg->number++);
|
av_strlcatf(oc->filename, sizeof(oc->filename),
|
||||||
|
seg->pattern, seg->number++);
|
||||||
|
|
||||||
if ((ret = avio_open(&oc->pb, oc->filename, AVIO_FLAG_WRITE)) < 0) {
|
if ((ret = avio_open(&oc->pb, oc->filename, AVIO_FLAG_WRITE)) < 0) {
|
||||||
avformat_free_context(oc);
|
avformat_free_context(oc);
|
||||||
@@ -130,6 +133,9 @@ static int seg_write_header(AVFormatContext *s)
|
|||||||
if (ret)
|
if (ret)
|
||||||
avformat_free_context(oc);
|
avformat_free_context(oc);
|
||||||
|
|
||||||
|
avio_printf(s->pb, "%s\n", oc->filename);
|
||||||
|
avio_flush(s->pb);
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -156,7 +162,8 @@ static int seg_write_packet(AVFormatContext *s, AVPacket *pkt)
|
|||||||
avformat_free_context(oc);
|
avformat_free_context(oc);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
avio_printf(s->pb, "%s\n", oc->filename);
|
||||||
|
avio_flush(s->pb);
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = oc->oformat->write_packet(oc, pkt);
|
ret = oc->oformat->write_packet(oc, pkt);
|
||||||
@@ -179,6 +186,8 @@ static int seg_write_trailer(struct AVFormatContext *s)
|
|||||||
static const AVOption options[] = {
|
static const AVOption options[] = {
|
||||||
{ "container_format", "container format used for the segments", OFFSET(format), FF_OPT_TYPE_STRING, {.str = "nut"}, 0, 0, E },
|
{ "container_format", "container format used for the segments", OFFSET(format), FF_OPT_TYPE_STRING, {.str = "nut"}, 0, 0, E },
|
||||||
{ "segment_time", "segment lenght in seconds", OFFSET(time), FF_OPT_TYPE_FLOAT, {.dbl = 2}, 0, FLT_MAX, E },
|
{ "segment_time", "segment lenght in seconds", OFFSET(time), FF_OPT_TYPE_FLOAT, {.dbl = 2}, 0, FLT_MAX, E },
|
||||||
|
{ "segment_pattern", "pattern to use in segment files", OFFSET(pattern),FF_OPT_TYPE_STRING, {.str = "%03d"}, 0, 0, E },
|
||||||
|
|
||||||
{ NULL },
|
{ NULL },
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user