[FFmpeg-devel] [PATCH] lavf/img2dec: document and amend logic in find_image_range()

Stefano Sabatini stefasab at gmail.com
Sat Aug 4 13:22:27 CEST 2012


Also rename the parameter max_start to start_index, which seems more
consistent with the assumed logic.

"start_index" represents the minimum accepted value for the first index,
and not the maximum value as implicitely assumed by the parameter name.

Also we require the start index to start from 1, in order not to break
compatibility with the behavior predating the start_number option
addition.
---
 libavformat/img2dec.c |   23 ++++++++++++++++-------
 1 files changed, 16 insertions(+), 7 deletions(-)

diff --git a/libavformat/img2dec.c b/libavformat/img2dec.c
index 2844ae0..849e8a4 100644
--- a/libavformat/img2dec.c
+++ b/libavformat/img2dec.c
@@ -108,15 +108,25 @@ static int is_glob(const char *path)
 #endif
 }
 
-/* return -1 if no image found */
+#define SEARCH_FIRST_INDEX_RANGE 5
+
+/**
+ * Get number ranges of image files matched by path.
+ *
+ * @param pfirst_index pointer to index updated with the first number in the range
+ * @param plast_index  pointer to index updated with the last number in the range
+ * @param path         path which has to be matched by the image files in the range
+ * @param start_index  min accepted value for the first index in the range
+ * @return -1 if no image file could be found in the range
+ */
 static int find_image_range(int *pfirst_index, int *plast_index,
-                            const char *path, int max_start)
+                            const char *path, int start_index)
 {
     char buf[1024];
     int range, last_index, range1, first_index;
 
     /* find the first image */
-    for (first_index = max_start; first_index < max_start + 5; first_index++) {
+    for (first_index = start_index; first_index < start_index + SEARCH_FIRST_INDEX_RANGE; first_index++) {
         if (av_get_frame_filename(buf, sizeof(buf), path, first_index) < 0){
             *pfirst_index =
             *plast_index = 1;
@@ -127,7 +137,7 @@ static int find_image_range(int *pfirst_index, int *plast_index,
         if (avio_check(buf, AVIO_FLAG_READ) > 0)
             break;
     }
-    if (first_index == 5)
+    if (first_index >= start_index + SEARCH_FIRST_INDEX_RANGE)
         goto fail;
 
     /* find the last image */
@@ -161,7 +171,6 @@ static int find_image_range(int *pfirst_index, int *plast_index,
     return -1;
 }
 
-
 static int read_probe(AVProbeData *p)
 {
     if (p->filename && ff_guess_image2_codec(p->filename)) {
@@ -253,7 +262,7 @@ static int read_header(AVFormatContext *s1)
 #endif
         } else {
             if (find_image_range(&first_index, &last_index, s->path,
-                                 s->start_number - 1) < 0)
+                                 s->start_number) < 0)
                 return AVERROR(ENOENT);
         }
         s->img_first = first_index;
@@ -377,7 +386,7 @@ static const AVOption options[] = {
     { "video_size",   "", OFFSET(video_size),   AV_OPT_TYPE_STRING, {.str = NULL}, 0, 0, DEC },
     { "framerate",    "", OFFSET(framerate),    AV_OPT_TYPE_STRING, {.str = "25"}, 0, 0, DEC },
     { "loop",         "", OFFSET(loop),         AV_OPT_TYPE_INT,    {.dbl = 0},    0, 1, DEC },
-    { "start_number", "first number in the sequence", OFFSET(start_number), AV_OPT_TYPE_INT, {.dbl = 1}, 1, INT_MAX, DEC },
+    { "start_number", "first number in the sequence", OFFSET(start_number), AV_OPT_TYPE_INT, {.dbl = 1}, 0, INT_MAX, DEC },
     { NULL },
 };
 
-- 
1.7.5.4



More information about the ffmpeg-devel mailing list