[FFmpeg-devel] [PATCH] lavf/segment: add -segment_delta option
Stefano Sabatini
stefasab at gmail.com
Wed Jul 4 01:22:05 CEST 2012
FIXME: bump micro version
---
doc/muxers.texi | 11 +++++++++++
libavformat/segment.c | 13 +++++++++++++
2 files changed, 24 insertions(+), 0 deletions(-)
diff --git a/doc/muxers.texi b/doc/muxers.texi
index c63356a..2f7d572 100644
--- a/doc/muxers.texi
+++ b/doc/muxers.texi
@@ -452,6 +452,17 @@ segment start and end time expressed in seconds.
The segment muxer supports the following options:
@table @option
+ at item segment_delta @var{delta}
+Specify the accuracy in seconds when selecting the start time for a
+segment. Default value is 0.
+
+This is especially useful with video segments, which are split at GOP
+boundaries. When delta is specified a given key-frame is selected if
+its PTS satisfies the relation:
+ at example
+PTS >= start_time - delta
+ at end example
+
@item segment_format @var{format}
Override the inner container format, by default it is guessed by the filename
extension.
diff --git a/libavformat/segment.c b/libavformat/segment.c
index 54b9f9a..4f145d4 100644
--- a/libavformat/segment.c
+++ b/libavformat/segment.c
@@ -43,6 +43,8 @@ typedef struct {
int64_t time; ///< segment duration
char *times_str; ///< segment times specification string
int64_t *times; ///< list of segment interval specification
+ char *delta_str; ///< approximation value duration used for the segment times
+ int64_t delta;
int nb_times; ///< number of elments in the times array
int has_video;
double start_time, end_time;
@@ -195,6 +197,15 @@ static int seg_write_header(AVFormatContext *s)
}
}
+ if (seg->delta_str) {
+ if ((ret = av_parse_time(&seg->delta, seg->delta_str, 1)) < 0) {
+ av_log(s, AV_LOG_ERROR,
+ "Invalid time duration specification '%s' for delta option\n",
+ seg->delta_str);
+ return ret;
+ }
+ }
+
oc = avformat_alloc_context();
if (!oc)
@@ -315,6 +326,7 @@ static int seg_write_trailer(struct AVFormatContext *s)
av_opt_free(seg);
av_freep(&seg->times);
+ av_freep(&seg->delta_str);
oc->streams = NULL;
oc->nb_streams = 0;
@@ -325,6 +337,7 @@ static int seg_write_trailer(struct AVFormatContext *s)
#define OFFSET(x) offsetof(SegmentContext, x)
#define E AV_OPT_FLAG_ENCODING_PARAM
static const AVOption options[] = {
+ { "segment_delta", "set approximation value used for the segment times", OFFSET(delta_str), AV_OPT_TYPE_STRING, {.str = NULL}, 0, 0, E },
{ "segment_format", "set container format used for the segments", OFFSET(format), AV_OPT_TYPE_STRING, {.str = NULL}, 0, 0, E },
{ "segment_time", "set segment duration", OFFSET(time_str), AV_OPT_TYPE_STRING,{.str = NULL}, 0, 0, E },
{ "segment_times", "set segment split time points", OFFSET(times_str), AV_OPT_TYPE_STRING, {.str = NULL}, 0, 0, E },
--
1.7.5.4
More information about the ffmpeg-devel
mailing list