[FFmpeg-devel] [PATCH] add hls_ts_option into hlsenc

Steven Liu lingjiujianke at gmail.com
Fri Sep 12 12:07:01 CEST 2014


I have refine the patch as Stefano's suggestion:-)

2014-09-12 17:29 GMT+08:00 Stefano Sabatini <stefasab at gmail.com>:

> [resending as I sent it privately]
>
> In data Friday 2014-09-12 10:48:44 +0800, Steven Liu ha scritto:
> > same as COMMITID 4f5493fe2380ad4aba67759baa7d7d4437f2e776
> > ---
> >  doc/muxers.texi      |  5 +++++
> >  libavformat/hlsenc.c | 24 +++++++++++++++++++++++-
> >  2 files changed, 28 insertions(+), 1 deletion(-)
> >
> > 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..5a4ec2b 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;
> > +        }
> > +    }
>
> Please send a patch as an attachment, or it will be mangled by the
> mailer.
>
> > +
> >      for (i = 0; i < s->nb_streams; i++)
> >          hls->has_video +=
> >              s->streams[i]->codec->codec_type == AVMEDIA_TYPE_VIDEO;
> > @@ -248,13 +259,23 @@ static int hls_write_header(AVFormatContext *s)
> >      if ((ret = hls_start(s)) < 0)
> >          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;
> > +    }
> >
> > +    if (ret < 0) {
> > +        goto fail;
> > +    }
> >
>
> >  fail:
> >      if (ret) {
> > +        av_dict_free(&options);
>
> av_dict_free(&options) should be called inconditionally before the if
> (ret) check.
>
> >          av_free(hls->basename);
>
> > +        av_opt_free(&hls->format_options);
>
> This is not required and will cause a crash, remove it.
>
> >          if (hls->avf)
> >              avformat_free_context(hls->avf);
>
> [...]
>
> LGTM otherwise.
>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0001-add-hls_ts_option-into-hlsenc.patch
Type: application/octet-stream
Size: 3879 bytes
Desc: not available
URL: <https://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20140912/b712f85a/attachment.obj>


More information about the ffmpeg-devel mailing list