[FFmpeg-devel] [PATCH] lavf/hlsenc: add hls_ts_options option

Stefano Sabatini stefasab at gmail.com
Thu Sep 11 15:54:03 CEST 2014


On date Thursday 2014-09-11 19:52:07 +0800, Steven Liu encoded:
> 
> Signed-off-by: Steven Liu <qi.liu at chinacache.com>

> Signed-off-by: Stefano Sabatini <stefasab at gmail.com>

Probably you should remove this, and mention the equivalent commit in
my patch (referencing the hash is fine).

> ---
>  doc/muxers.texi      |  5 +++++
>  libavformat/hlsenc.c | 24 ++++++++++++++++++++++--
>  2 files changed, 27 insertions(+), 2 deletions(-)
> 
> diff --git a/doc/muxers.texi b/doc/muxers.texi
> index 57e81f4..cc62705dc 100644
> --- a/doc/muxers.texi
> +++ b/doc/muxers.texi
> @@ -220,6 +220,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
>  will contain all the segments. Default value is 5.
>  
> + at 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}
>  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
> diff --git a/libavformat/hlsenc.c b/libavformat/hlsenc.c
> index 11f1e5b..c993d44 100644
> --- a/libavformat/hlsenc.c
> +++ b/libavformat/hlsenc.c
> @@ -63,6 +63,8 @@ typedef struct HLSContext {
>  
>      char *basename;
>      char *baseurl;
> +    char *format_options_str;
> +    AVDictionary *format_options;
>  
>      AVIOContext *pb;
>  } HLSContext;
> @@ -204,12 +206,21 @@ static int hls_write_header(AVFormatContext *s)
>      int ret, i;
>      char *p;
>      const char *pattern = "%d.ts";
> +    AVDictionary *options = NULL;
>      int basename_size = strlen(s->filename) + strlen(pattern) + 1;
>  
>      hls->sequence       = hls->start_sequence;
>      hls->recording_time = hls->time * AV_TIME_BASE;
>      hls->start_pts      = AV_NOPTS_VALUE;
>  
> +    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++)
>          hls->has_video +=
>              s->streams[i]->codec->codec_type == AVMEDIA_TYPE_VIDEO;
> @@ -248,13 +259,21 @@ static int hls_write_header(AVFormatContext *s)
>      if ((ret = hls_start(s)) < 0)
>          goto fail;
>  

> -    if ((ret = avformat_write_header(hls->avf, NULL)) < 0)
> -        goto fail;
> +    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);
> +    }
> +    av_dict_free(&options);
>  
> +    if (ret < 0) {
> +        goto fail;
> +    }

I think this is more correct:

   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;
   }
...

fail:
    av_dict_free(&options);

otherwise it won't fail in case you have unprocessed options (e.g. in
case of typos), and the user will probably not notice that and get an
unexpected result.

[...]

Should be good otherwise.
-- 
FFmpeg = Fast and Friendly Mind-dumbing Powered Elastic Guru


More information about the ffmpeg-devel mailing list