diff options
author | Marton Balint <cus@passwd.hu> | 2020-04-18 22:15:39 +0200 |
---|---|---|
committer | Marton Balint <cus@passwd.hu> | 2020-05-01 17:22:58 +0200 |
commit | d69576294939247d3a0c0904425c219047053421 (patch) | |
tree | 1953eec2865a69f095b919b79406d6324b7b2c49 | |
parent | 6847affcb775e89d9256b33c7dc8a7502d2bb428 (diff) | |
download | ffmpeg-d69576294939247d3a0c0904425c219047053421.tar.gz |
avformat/hlsenc: add support for microseconds since epoch based sequence number
Sequence numbers of segments should be unique, if an encoder is using shorter
than 1 second segments and it is restarted, then future segments will be using
already used sequence numbers if initial sequence number is based on the number
of seconds since epoch and not microseconds.
Signed-off-by: Marton Balint <cus@passwd.hu>
-rw-r--r-- | doc/muxers.texi | 3 | ||||
-rw-r--r-- | libavformat/hlsenc.c | 13 | ||||
-rw-r--r-- | libavformat/version.h | 2 |
3 files changed, 14 insertions, 4 deletions
diff --git a/doc/muxers.texi b/doc/muxers.texi index cb2bb42c32..536433b1d3 100644 --- a/doc/muxers.texi +++ b/doc/muxers.texi @@ -648,6 +648,9 @@ Set the starting sequence numbers according to @var{start_number} option value. @item epoch The start number will be the seconds since epoch (1970-01-01 00:00:00) +@item epoch_us +The start number will be the microseconds since epoch (1970-01-01 00:00:00) + @item datetime The start number will be based on the current date/time as YYYYmmddHHMMSS. e.g. 20161231235759. diff --git a/libavformat/hlsenc.c b/libavformat/hlsenc.c index d75684741f..008a3f3947 100644 --- a/libavformat/hlsenc.c +++ b/libavformat/hlsenc.c @@ -41,6 +41,7 @@ #include "libavutil/random_seed.h" #include "libavutil/opt.h" #include "libavutil/log.h" +#include "libavutil/time.h" #include "libavutil/time_internal.h" #include "avformat.h" @@ -56,6 +57,8 @@ typedef enum { HLS_START_SEQUENCE_AS_START_NUMBER = 0, HLS_START_SEQUENCE_AS_SECONDS_SINCE_EPOCH = 1, HLS_START_SEQUENCE_AS_FORMATTED_DATETIME = 2, // YYYYMMDDhhmmss + HLS_START_SEQUENCE_AS_MICROSECONDS_SINCE_EPOCH = 3, + HLS_START_SEQUENCE_LAST, // unused } StartSequenceSourceType; typedef enum { @@ -2788,9 +2791,12 @@ static int hls_init(AVFormatContext *s) pattern = "%d.m4s"; } if ((hls->start_sequence_source_type == HLS_START_SEQUENCE_AS_SECONDS_SINCE_EPOCH) || + (hls->start_sequence_source_type == HLS_START_SEQUENCE_AS_MICROSECONDS_SINCE_EPOCH) || (hls->start_sequence_source_type == HLS_START_SEQUENCE_AS_FORMATTED_DATETIME)) { - time_t t = time(NULL); // we will need it in either case - if (hls->start_sequence_source_type == HLS_START_SEQUENCE_AS_SECONDS_SINCE_EPOCH) { + time_t t = time(NULL); + if (hls->start_sequence_source_type == HLS_START_SEQUENCE_AS_MICROSECONDS_SINCE_EPOCH) { + hls->start_sequence = av_gettime(); + } else if (hls->start_sequence_source_type == HLS_START_SEQUENCE_AS_SECONDS_SINCE_EPOCH) { hls->start_sequence = (int64_t)t; } else if (hls->start_sequence_source_type == HLS_START_SEQUENCE_AS_FORMATTED_DATETIME) { char b[15]; @@ -3083,9 +3089,10 @@ static const AVOption options[] = { {"event", "EVENT playlist", 0, AV_OPT_TYPE_CONST, {.i64 = PLAYLIST_TYPE_EVENT }, INT_MIN, INT_MAX, E, "pl_type" }, {"vod", "VOD playlist", 0, AV_OPT_TYPE_CONST, {.i64 = PLAYLIST_TYPE_VOD }, INT_MIN, INT_MAX, E, "pl_type" }, {"method", "set the HTTP method(default: PUT)", OFFSET(method), AV_OPT_TYPE_STRING, {.str = NULL}, 0, 0, E}, - {"hls_start_number_source", "set source of first number in sequence", OFFSET(start_sequence_source_type), AV_OPT_TYPE_INT, {.i64 = HLS_START_SEQUENCE_AS_START_NUMBER }, 0, HLS_START_SEQUENCE_AS_FORMATTED_DATETIME, E, "start_sequence_source_type" }, + {"hls_start_number_source", "set source of first number in sequence", OFFSET(start_sequence_source_type), AV_OPT_TYPE_INT, {.i64 = HLS_START_SEQUENCE_AS_START_NUMBER }, 0, HLS_START_SEQUENCE_LAST-1, E, "start_sequence_source_type" }, {"generic", "start_number value (default)", 0, AV_OPT_TYPE_CONST, {.i64 = HLS_START_SEQUENCE_AS_START_NUMBER }, INT_MIN, INT_MAX, E, "start_sequence_source_type" }, {"epoch", "seconds since epoch", 0, AV_OPT_TYPE_CONST, {.i64 = HLS_START_SEQUENCE_AS_SECONDS_SINCE_EPOCH }, INT_MIN, INT_MAX, E, "start_sequence_source_type" }, + {"epoch_us", "microseconds since epoch", 0, AV_OPT_TYPE_CONST, {.i64 = HLS_START_SEQUENCE_AS_MICROSECONDS_SINCE_EPOCH }, INT_MIN, INT_MAX, E, "start_sequence_source_type" }, {"datetime", "current datetime as YYYYMMDDhhmmss", 0, AV_OPT_TYPE_CONST, {.i64 = HLS_START_SEQUENCE_AS_FORMATTED_DATETIME }, INT_MIN, INT_MAX, E, "start_sequence_source_type" }, {"http_user_agent", "override User-Agent field in HTTP header", OFFSET(user_agent), AV_OPT_TYPE_STRING, {.str = NULL}, 0, 0, E}, {"var_stream_map", "Variant stream map string", OFFSET(var_stream_map), AV_OPT_TYPE_STRING, {.str = NULL}, 0, 0, E}, diff --git a/libavformat/version.h b/libavformat/version.h index 719cda6b98..b9a014749c 100644 --- a/libavformat/version.h +++ b/libavformat/version.h @@ -33,7 +33,7 @@ // Also please add any ticket numbers that you believe might be affected here #define LIBAVFORMAT_VERSION_MAJOR 58 #define LIBAVFORMAT_VERSION_MINOR 42 -#define LIBAVFORMAT_VERSION_MICRO 101 +#define LIBAVFORMAT_VERSION_MICRO 102 #define LIBAVFORMAT_VERSION_INT AV_VERSION_INT(LIBAVFORMAT_VERSION_MAJOR, \ LIBAVFORMAT_VERSION_MINOR, \ |