[FFmpeg-devel] [PATCH 1/3] concatdec: allow to set explicitly file input format

Nicolas George george at nsup.org
Mon Jun 23 16:54:30 CEST 2014


Le quintidi 5 messidor, an CCXXII, Andrey Utkin a écrit :
> ---
>  libavformat/concatdec.c | 26 ++++++++++++++++++++++++--
>  1 file changed, 24 insertions(+), 2 deletions(-)
> 
> diff --git a/libavformat/concatdec.c b/libavformat/concatdec.c
> index 4590dc5..b3e6a37 100644
> --- a/libavformat/concatdec.c
> +++ b/libavformat/concatdec.c
> @@ -43,6 +43,7 @@ typedef struct {
>      int64_t duration;
>      ConcatStream *streams;
>      int nb_streams;
> +    char *format; /* Optional explicit input format */
>  } ConcatFile;
>  
>  typedef struct {
> @@ -278,17 +279,29 @@ static int open_file(AVFormatContext *avf, unsigned fileno)
>  {
>      ConcatContext *cat = avf->priv_data;
>      ConcatFile *file = &cat->files[fileno];
> +    AVInputFormat *format = NULL;
>      int ret;
>  
>      if (cat->avf)
>          avformat_close_input(&cat->avf);
>  
> +    if (file->format) {
> +        format = av_find_input_format(file->format);
> +        if (!format) {

> +            av_log(avf, AV_LOG_ERROR,
> +                    "Format '%s' not found (requested for file '%s')\n",
> +                    file->format, file->url);

Nit: spurious alignment.

> +            return AVERROR_DEMUXER_NOT_FOUND;
> +        }
> +    }
> +
>      cat->avf = avformat_alloc_context();
>      if (!cat->avf)
>          return AVERROR(ENOMEM);
>  
>      cat->avf->interrupt_callback = avf->interrupt_callback;
> -    if ((ret = avformat_open_input(&cat->avf, file->url, NULL, NULL)) < 0 ||
> +
> +    if ((ret = avformat_open_input(&cat->avf, file->url, format, NULL)) < 0 ||
>          (ret = avformat_find_stream_info(cat->avf, NULL)) < 0) {
>          av_log(avf, AV_LOG_ERROR, "Impossible to open '%s'\n", file->url);
>          avformat_close_input(&cat->avf);
> @@ -314,6 +327,7 @@ static int concat_read_close(AVFormatContext *avf)
>      for (i = 0; i < cat->nb_files; i++) {
>          av_freep(&cat->files[i].url);
>          av_freep(&cat->files[i].streams);
> +        av_freep(&cat->files[i].format);
>      }
>      av_freep(&cat->files);
>      return 0;
> @@ -374,12 +388,20 @@ static int concat_read_header(AVFormatContext *avf)
>          } else if (!strcmp(keyword, "ffconcat")) {
>              char *ver_kw  = get_keyword(&cursor);
>              char *ver_val = get_keyword(&cursor);

> -            if (strcmp(ver_kw, "version") || strcmp(ver_val, "1.0")) {
> +            if (strcmp(ver_kw, "version")
> +                    || (strcmp(ver_val, "1.0") && strcmp(ver_val, "1.1"))) {

Not useful, see my other mail.

>                  av_log(avf, AV_LOG_ERROR, "Line %d: invalid version\n", line);
>                  FAIL(AVERROR_INVALIDDATA);
>              }
>              if (cat->safe < 0)
>                  cat->safe = 1;
> +        } else if (!strcmp(keyword, "format")) {
> +            if (!file) {
> +                av_log(avf, AV_LOG_ERROR, "Line %d: format without file\n",
> +                       line);
> +                FAIL(AVERROR_INVALIDDATA);
> +            }

> +            file->format = av_strdup(get_keyword(&cursor));

Missing error checks for get_keyword() and av_strdup().

>          } else {
>              av_log(avf, AV_LOG_ERROR, "Line %d: unknown keyword '%s'\n",
>                     line, keyword);

Thanks for the patch, it is a very useful feature.

Regards,

-- 
  Nicolas George
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 819 bytes
Desc: Digital signature
URL: <https://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20140623/05bb9b83/attachment.asc>


More information about the ffmpeg-devel mailing list