lavf/hls: add hls_ts_option

Same as COMMITID 4f5493fe23.

Signed-off-by: Stefano Sabatini <stefasab@gmail.com>
pull/113/head
Steven Liu 10 years ago committed by Stefano Sabatini
parent 3a0c70f1e3
commit 2c21e8b1a4
  1. 5
      doc/muxers.texi
  2. 22
      libavformat/hlsenc.c
  3. 2
      libavformat/version.h

@ -224,6 +224,11 @@ Set the segment length in seconds. Default value is 2.
Set the maximum number of playlist entries. If set to 0 the list file Set the maximum number of playlist entries. If set to 0 the list file
will contain all the segments. Default value is 5. will contain all the segments. Default value is 5.
@item hls_ts_options @var{options_list}
Set output format options using a :-separated list of key=value
parameters. Values containing @code{:} special characters must be
escaped.
@item hls_wrap @var{wrap} @item hls_wrap @var{wrap}
Set the number after which the segment filename number (the number Set the number after which the segment filename number (the number
specified in each segment file) wraps. If set to 0 the number will be specified in each segment file) wraps. If set to 0 the number will be

@ -73,6 +73,8 @@ typedef struct HLSContext {
char *basename; char *basename;
char *baseurl; char *baseurl;
char *format_options_str;
AVDictionary *format_options;
AVIOContext *pb; AVIOContext *pb;
} HLSContext; } HLSContext;
@ -226,6 +228,7 @@ static int hls_write_header(AVFormatContext *s)
int ret, i; int ret, i;
char *p; char *p;
const char *pattern = "%d.ts"; const char *pattern = "%d.ts";
AVDictionary *options = NULL;
int basename_size = strlen(s->filename) + strlen(pattern) + 1; int basename_size = strlen(s->filename) + strlen(pattern) + 1;
hls->sequence = hls->start_sequence; hls->sequence = hls->start_sequence;
@ -235,6 +238,14 @@ static int hls_write_header(AVFormatContext *s)
if (hls->flags & HLS_SINGLE_FILE) if (hls->flags & HLS_SINGLE_FILE)
pattern = ".ts"; pattern = ".ts";
if (hls->format_options_str) {
ret = av_dict_parse_string(&hls->format_options, hls->format_options_str, "=", ":", 0);
if (ret < 0) {
av_log(s, AV_LOG_ERROR, "Could not parse format options list '%s'\n", hls->format_options_str);
goto fail;
}
}
for (i = 0; i < s->nb_streams; i++) for (i = 0; i < s->nb_streams; i++)
hls->has_video += hls->has_video +=
s->streams[i]->codec->codec_type == AVMEDIA_TYPE_VIDEO; s->streams[i]->codec->codec_type == AVMEDIA_TYPE_VIDEO;
@ -273,11 +284,17 @@ static int hls_write_header(AVFormatContext *s)
if ((ret = hls_start(s)) < 0) if ((ret = hls_start(s)) < 0)
goto fail; goto fail;
if ((ret = avformat_write_header(hls->avf, NULL)) < 0) av_dict_copy(&options, hls->format_options, 0);
ret = avformat_write_header(hls->avf, &options);
if (av_dict_count(options)) {
av_log(s, AV_LOG_ERROR, "Some of provided format options in '%s' are not recognized\n", hls->format_options_str);
ret = AVERROR(EINVAL);
goto fail; goto fail;
}
fail: fail:
av_dict_free(&options);
if (ret) { if (ret) {
av_free(hls->basename); av_free(hls->basename);
if (hls->avf) if (hls->avf)
@ -375,6 +392,7 @@ static const AVOption options[] = {
{"start_number", "set first number in the sequence", OFFSET(start_sequence),AV_OPT_TYPE_INT64, {.i64 = 0}, 0, INT64_MAX, E}, {"start_number", "set first number in the sequence", OFFSET(start_sequence),AV_OPT_TYPE_INT64, {.i64 = 0}, 0, INT64_MAX, E},
{"hls_time", "set segment length in seconds", OFFSET(time), AV_OPT_TYPE_FLOAT, {.dbl = 2}, 0, FLT_MAX, E}, {"hls_time", "set segment length in seconds", OFFSET(time), AV_OPT_TYPE_FLOAT, {.dbl = 2}, 0, FLT_MAX, E},
{"hls_list_size", "set maximum number of playlist entries", OFFSET(max_nb_segments), AV_OPT_TYPE_INT, {.i64 = 5}, 0, INT_MAX, E}, {"hls_list_size", "set maximum number of playlist entries", OFFSET(max_nb_segments), AV_OPT_TYPE_INT, {.i64 = 5}, 0, INT_MAX, E},
{"hls_ts_options","set hls mpegts list of options for the container format used for hls", OFFSET(format_options_str), AV_OPT_TYPE_STRING, {.str = NULL}, 0, 0, E},
{"hls_wrap", "set number after which the index wraps", OFFSET(wrap), AV_OPT_TYPE_INT, {.i64 = 0}, 0, INT_MAX, E}, {"hls_wrap", "set number after which the index wraps", OFFSET(wrap), AV_OPT_TYPE_INT, {.i64 = 0}, 0, INT_MAX, E},
{"hls_base_url", "url to prepend to each playlist entry", OFFSET(baseurl), AV_OPT_TYPE_STRING, {.str = NULL}, 0, 0, E}, {"hls_base_url", "url to prepend to each playlist entry", OFFSET(baseurl), AV_OPT_TYPE_STRING, {.str = NULL}, 0, 0, E},
{"hls_flags", "set flags affecting HLS playlist and media file generation", OFFSET(flags), AV_OPT_TYPE_FLAGS, {.i64 = 0 }, 0, UINT_MAX, E, "flags"}, {"hls_flags", "set flags affecting HLS playlist and media file generation", OFFSET(flags), AV_OPT_TYPE_FLAGS, {.i64 = 0 }, 0, UINT_MAX, E, "flags"},

@ -31,7 +31,7 @@
#define LIBAVFORMAT_VERSION_MAJOR 56 #define LIBAVFORMAT_VERSION_MAJOR 56
#define LIBAVFORMAT_VERSION_MINOR 4 #define LIBAVFORMAT_VERSION_MINOR 4
#define LIBAVFORMAT_VERSION_MICRO 101 #define LIBAVFORMAT_VERSION_MICRO 102
#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, \

Loading…
Cancel
Save