@@ -474,6 +474,28 @@ the segment start and end time expressed in seconds. | |||||
Default value is "flat". | Default value is "flat". | ||||
@item segment_time @var{time} | @item segment_time @var{time} | ||||
Set segment duration to @var{time}. Default value is "2". | Set segment duration to @var{time}. Default value is "2". | ||||
@item segment_time_delta @var{delta} | |||||
Specify the accuracy time when selecting the start time for a | |||||
segment. Default value is "0". | |||||
When delta is specified a key-frame will start a new segment if its | |||||
PTS satisfies the relation: | |||||
@example | |||||
PTS >= start_time - time_delta | |||||
@end example | |||||
This option is useful when splitting video content, which is always | |||||
split at GOP boundaries, in case a key frame is found just before the | |||||
specified split time. | |||||
In particular may be used in combination with the @file{ffmpeg} option | |||||
@var{force_key_frames}. The key frame times specified by | |||||
@var{force_key_frames} may not be set accurately because of rounding | |||||
issues, with the consequence that a key frame time may result set just | |||||
before the specified time. For constant frame rate videos a value of | |||||
1/2*@var{frame_rate} should address the worst case mismatch between | |||||
the specified time and the time set by @var{force_key_frames}. | |||||
@item segment_times @var{times} | @item segment_times @var{times} | ||||
Specify a list of split points. @var{times} contains a list of comma | Specify a list of split points. @var{times} contains a list of comma | ||||
separated duration specifications, in increasing order. | separated duration specifications, in increasing order. | ||||
@@ -499,6 +521,18 @@ points specified by the @var{segment_times} option: | |||||
ffmpeg -i in.mkv -codec copy -map 0 -f segment -segment_list_type ext -segment_list out.list -segment_list_size 0 -segment_times 1,2,3,5,8,13,21 out%03d.nut | ffmpeg -i in.mkv -codec copy -map 0 -f segment -segment_list_type ext -segment_list out.list -segment_list_size 0 -segment_times 1,2,3,5,8,13,21 out%03d.nut | ||||
@end example | @end example | ||||
@item | |||||
As the example above, but use the @code{ffmpeg} @var{force_key_frames} | |||||
option to force key frames in the input at the specified location, together | |||||
with the segment option @var{segment_time_delta} to account for | |||||
possible roundings operated when setting key frame times. | |||||
@example | |||||
ffmpeg -i in.mkv -force_key_frames 1,2,3,5,8,13,21 -vcodec mpeg4 -acodec pcm_s16le -map 0 \ | |||||
-f segment -segment_list_type ext -segment_list out.list -segment_list_size 0 -segment_times 1,2,3,5,8,13,21 -segment_time_delta 0.05 out%03d.nut | |||||
@end example | |||||
In order to force key frames on the input file, transcoding is | |||||
required. | |||||
@item | @item | ||||
To convert the @file{in.mkv} to TS segments using the @code{libx264} | To convert the @file{in.mkv} to TS segments using the @code{libx264} | ||||
and @code{libfaac} encoders: | and @code{libfaac} encoders: | ||||
@@ -52,6 +52,8 @@ typedef struct { | |||||
char *times_str; ///< segment times specification string | char *times_str; ///< segment times specification string | ||||
int64_t *times; ///< list of segment interval specification | int64_t *times; ///< list of segment interval specification | ||||
int nb_times; ///< number of elments in the times array | int nb_times; ///< number of elments in the times array | ||||
char *time_delta_str; ///< approximation value duration used for the segment times | |||||
int64_t time_delta; | |||||
int has_video; | int has_video; | ||||
double start_time, end_time; | double start_time, end_time; | ||||
} SegmentContext; | } SegmentContext; | ||||
@@ -222,6 +224,15 @@ static int seg_write_header(AVFormatContext *s) | |||||
} | } | ||||
} | } | ||||
if (seg->time_delta_str) { | |||||
if ((ret = av_parse_time(&seg->time_delta, seg->time_delta_str, 1)) < 0) { | |||||
av_log(s, AV_LOG_ERROR, | |||||
"Invalid time duration specification '%s' for delta option\n", | |||||
seg->time_delta_str); | |||||
return ret; | |||||
} | |||||
} | |||||
oc = avformat_alloc_context(); | oc = avformat_alloc_context(); | ||||
if (!oc) | if (!oc) | ||||
@@ -304,7 +315,7 @@ static int seg_write_packet(AVFormatContext *s, AVPacket *pkt) | |||||
/* if the segment has video, start a new segment *only* with a key video frame */ | /* if the segment has video, start a new segment *only* with a key video frame */ | ||||
if ((st->codec->codec_type == AVMEDIA_TYPE_VIDEO || !seg->has_video) && | if ((st->codec->codec_type == AVMEDIA_TYPE_VIDEO || !seg->has_video) && | ||||
av_compare_ts(pkt->pts, st->time_base, | av_compare_ts(pkt->pts, st->time_base, | ||||
end_pts, AV_TIME_BASE_Q) >= 0 && | |||||
end_pts-seg->time_delta, AV_TIME_BASE_Q) >= 0 && | |||||
pkt->flags & AV_PKT_FLAG_KEY) { | pkt->flags & AV_PKT_FLAG_KEY) { | ||||
av_log(s, AV_LOG_DEBUG, "Next segment starts with packet stream:%d pts:%"PRId64" pts_time:%f\n", | av_log(s, AV_LOG_DEBUG, "Next segment starts with packet stream:%d pts:%"PRId64" pts_time:%f\n", | ||||
@@ -359,6 +370,7 @@ static const AVOption options[] = { | |||||
{ "flat", "flat format", 0, AV_OPT_TYPE_CONST, {.dbl=LIST_TYPE_FLAT }, INT_MIN, INT_MAX, 0, "list_type" }, | { "flat", "flat format", 0, AV_OPT_TYPE_CONST, {.dbl=LIST_TYPE_FLAT }, INT_MIN, INT_MAX, 0, "list_type" }, | ||||
{ "ext", "extended format", 0, AV_OPT_TYPE_CONST, {.dbl=LIST_TYPE_EXT }, INT_MIN, INT_MAX, 0, "list_type" }, | { "ext", "extended format", 0, AV_OPT_TYPE_CONST, {.dbl=LIST_TYPE_EXT }, INT_MIN, INT_MAX, 0, "list_type" }, | ||||
{ "segment_time", "set segment duration", OFFSET(time_str),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_time_delta","set approximation value used for the segment times", OFFSET(time_delta_str), AV_OPT_TYPE_STRING, {.str = "0"}, 0, 0, E }, | |||||
{ "segment_times", "set segment split time points", OFFSET(times_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 }, | ||||
{ "segment_wrap", "set number after which the index wraps", OFFSET(wrap), AV_OPT_TYPE_INT, {.dbl = 0}, 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 }, | ||||
{ NULL }, | { NULL }, | ||||
@@ -31,7 +31,7 @@ | |||||
#define LIBAVFORMAT_VERSION_MAJOR 54 | #define LIBAVFORMAT_VERSION_MAJOR 54 | ||||
#define LIBAVFORMAT_VERSION_MINOR 15 | #define LIBAVFORMAT_VERSION_MINOR 15 | ||||
#define LIBAVFORMAT_VERSION_MICRO 103 | |||||
#define LIBAVFORMAT_VERSION_MICRO 104 | |||||
#define LIBAVFORMAT_VERSION_INT AV_VERSION_INT(LIBAVFORMAT_VERSION_MAJOR, \ | #define LIBAVFORMAT_VERSION_INT AV_VERSION_INT(LIBAVFORMAT_VERSION_MAJOR, \ | ||||
LIBAVFORMAT_VERSION_MINOR, \ | LIBAVFORMAT_VERSION_MINOR, \ | ||||