Commit 8dc31f8d authored by Stefano Sabatini's avatar Stefano Sabatini

lavf/segment: make use of av_parse_time() when parsing the -segment_time value

Increase flexibility/consistency.

Also rename recording_time field to time, for enhanced
consistency/readability.
parent 0a7b8eff
......@@ -472,8 +472,8 @@ the segment start and end time expressed in seconds.
@end table
Default value is "flat".
@item segment_time @var{t}
Set segment duration to @var{t} seconds. Default value is 2.
@item segment_time @var{time}
Set segment duration to @var{time}. Default value is "2".
@item segment_wrap @var{limit}
Wrap around segment index once it reaches @var{limit}.
@end table
......
......@@ -45,9 +45,9 @@ typedef struct {
int list_size; ///< number of entries for the segment list file
ListType list_type; ///< set the list type
AVIOContext *list_pb; ///< list file put-byte context
float time; ///< segment duration
int wrap; ///< number after which the index wraps
int64_t recording_time;
char *time_str; ///< segment duration specification string
int64_t time; ///< segment duration
int has_video;
double start_time, end_time;
} SegmentContext;
......@@ -143,7 +143,13 @@ static int seg_write_header(AVFormatContext *s)
int ret, i;
seg->number = 0;
seg->recording_time = seg->time * 1000000;
if ((ret = av_parse_time(&seg->time, seg->time_str, 1)) < 0) {
av_log(s, AV_LOG_ERROR,
"Invalid time duration specification '%s' for segment_time option\n",
seg->time_str);
return ret;
}
oc = avformat_alloc_context();
......@@ -215,7 +221,7 @@ static int seg_write_packet(AVFormatContext *s, AVPacket *pkt)
SegmentContext *seg = s->priv_data;
AVFormatContext *oc = seg->avf;
AVStream *st = oc->streams[pkt->stream_index];
int64_t end_pts = seg->recording_time * seg->number;
int64_t end_pts = seg->time * seg->number;
int ret;
/* if the segment has video, start a new segment *only* with a key video frame */
......@@ -256,6 +262,9 @@ static int seg_write_trailer(struct AVFormatContext *s)
int ret = segment_end(s);
if (seg->list)
avio_close(seg->list_pb);
av_opt_free(seg);
oc->streams = NULL;
oc->nb_streams = 0;
avformat_free_context(oc);
......@@ -266,7 +275,7 @@ static int seg_write_trailer(struct AVFormatContext *s)
#define E AV_OPT_FLAG_ENCODING_PARAM
static const AVOption options[] = {
{ "segment_format", "set container format used for the segments", OFFSET(format), AV_OPT_TYPE_STRING, {.str = NULL}, 0, 0, E },
{ "segment_time", "set segment length in seconds", OFFSET(time), AV_OPT_TYPE_FLOAT, {.dbl = 2}, 0, FLT_MAX, E },
{ "segment_time", "set segment duration", OFFSET(time_str),AV_OPT_TYPE_STRING, {.str = "2"}, 0, 0, E },
{ "segment_list", "set the segment list filename", OFFSET(list), AV_OPT_TYPE_STRING, {.str = NULL}, 0, 0, E },
{ "segment_list_size", "set the maximum number of playlist entries", OFFSET(list_size), AV_OPT_TYPE_INT, {.dbl = 5}, 0, INT_MAX, E },
{ "segment_list_type", "set the segment list type", OFFSET(list_type), AV_OPT_TYPE_INT, {.dbl = LIST_TYPE_FLAT}, 0, LIST_TYPE_NB-1, E, "list_type" },
......
......@@ -31,7 +31,7 @@
#define LIBAVFORMAT_VERSION_MAJOR 54
#define LIBAVFORMAT_VERSION_MINOR 15
#define LIBAVFORMAT_VERSION_MICRO 101
#define LIBAVFORMAT_VERSION_MICRO 102
#define LIBAVFORMAT_VERSION_INT AV_VERSION_INT(LIBAVFORMAT_VERSION_MAJOR, \
LIBAVFORMAT_VERSION_MINOR, \
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment