[FFmpeg-devel] [PATCH] Option to change picture numbering

Alexander Sorockin sorockin
Sat Jan 8 20:43:04 CET 2011


The other day I was making videos from a bunch of pictures and I needed
ffmpeg to be able to start from a particular file without having to rename
the whole sequence. (I know I could use symbolic links instead as suggested
in FAQ, but it's still inconvenient when you have to do it multiple times.)
Below is a simple patch that adds option first_index specifying the number
ffmpeg starts counting picture files from. Cheers.

Index: libavformat/avformat.h
===================================================================
--- libavformat/avformat.h	(revision 26251)
+++ libavformat/avformat.h	(working copy)
@@ -915,6 +915,9 @@
       * - decoding: Unused.
       */
      int64_t start_time_realtime;
+
+    int first_index;
+
  } AVFormatContext;

  typedef struct AVPacketList {
Index: libavformat/options.c
===================================================================
--- libavformat/options.c	(revision 26251)
+++ libavformat/options.c	(working copy)
@@ -61,6 +61,7 @@
  {"fdebug", "print specific debug info", OFFSET(debug), FF_OPT_TYPE_FLAGS,  
DEFAULT, 0, INT_MAX, E|D, "fdebug"},
  {"ts", NULL, 0, FF_OPT_TYPE_CONST, FF_FDEBUG_TS, INT_MIN, INT_MAX, E|D,  
"fdebug"},
  {"max_delay", "maximum muxing or demuxing delay in microseconds",  
OFFSET(max_delay), FF_OPT_TYPE_INT, DEFAULT, 0, INT_MAX, E|D},
+{"first_index", "index of the first image file", OFFSET(first_index),  
FF_OPT_TYPE_INT, INT_MAX, 0, INT_MAX, E|D},
  {NULL},
  };

Index: libavformat/img2.c
===================================================================
--- libavformat/img2.c	(revision 26251)
+++ libavformat/img2.c	(working copy)
@@ -122,10 +122,11 @@
                              const char *path)
  {
      char buf[1024];
-    int range, last_index, range1, first_index;
+    int range, first_index = *pfirst_index,
+        last_index = first_index + 5, range1;

      /* find the first image */
-    for(first_index = 0; first_index < 5; first_index++) {
+    for(; first_index < last_index; first_index++) {
          if (av_get_frame_filename(buf, sizeof(buf), path, first_index) <  
0){
              *pfirst_index =
              *plast_index = 1;
@@ -136,7 +137,7 @@
          if (url_exist(buf))
              break;
      }
-    if (first_index == 5)
+    if (first_index == last_index)
          goto fail;

      /* find the last image */
@@ -223,6 +224,7 @@
      }

      if (!s->is_pipe) {
+        first_index = s1->first_index == INT_MAX ? 0 : s1->first_index ;
          if (find_image_range(&first_index, &last_index, s->path) < 0)
              return AVERROR(ENOENT);
          s->img_first = first_index;
@@ -324,7 +326,7 @@
  {
      VideoData *img = s->priv_data;

-    img->img_number = 1;
+    img->img_number = s->first_index == INT_MAX ? 1 : s->first_index;
      av_strlcpy(img->path, s->filename, sizeof(img->path));

      /* find format */



More information about the ffmpeg-devel mailing list