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

Andrey Utkin andrey.krieger.utkin at gmail.com
Mon Jun 23 13:01:17 CEST 2014


---
 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);
+            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"))) {
                 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));
         } else {
             av_log(avf, AV_LOG_ERROR, "Line %d: unknown keyword '%s'\n",
                    line, keyword);
-- 
1.8.3.2



More information about the ffmpeg-devel mailing list