[FFmpeg-devel] [PATCH] lavf/segment: make use of av_parse_time() when parsing the -segment_time value

Stefano Sabatini stefasab at gmail.com
Wed Jul 4 01:21:51 CEST 2012


Increase flexibility/consistency.

Also rename recording_time field to time, for enhanced
consistency/readability.

FIXME: bump micro version
---
 doc/muxers.texi       |    4 ++--
 libavformat/segment.c |   19 ++++++++++++++-----
 2 files changed, 16 insertions(+), 7 deletions(-)

diff --git a/doc/muxers.texi b/doc/muxers.texi
index c78c6f2..7531a52 100644
--- a/doc/muxers.texi
+++ b/doc/muxers.texi
@@ -455,8 +455,8 @@ The segment muxer supports the following options:
 @item segment_format @var{format}
 Override the inner container format, by default it is guessed by the filename
 extension.
- at item segment_time @var{t}
-Set segment duration to @var{t} seconds. Default value is 2.
+ at item segment_time @var{time}
+Set segment duration to @var{time}. Default value is "2".
 @item segment_list @var{name}
 Generate also a listfile named @var{name}. If not specified no
 listfile is generated.
diff --git a/libavformat/segment.c b/libavformat/segment.c
index 90373df..429ca1e 100644
--- a/libavformat/segment.c
+++ b/libavformat/segment.c
@@ -38,9 +38,9 @@ typedef struct {
     char *list;            ///< filename for the segment list file
     int   list_size;       ///< number of entries for the segment list file
     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;
@@ -131,7 +131,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();
 
@@ -203,7 +209,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 */
@@ -244,6 +250,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);
@@ -254,7 +263,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_wrap",      "set number after which the index wraps",     OFFSET(wrap),    AV_OPT_TYPE_INT,    {.dbl = 0},     0, INT_MAX, E },
-- 
1.7.5.4



More information about the ffmpeg-devel mailing list