Jeremy Richard moving pictures editor Est. 2008

%0Xd

using ffmpeg 2.3

The command line tool ffmpeg handles sequential images using a unique command, so no need to enter the names of each images or having to use a batch file.

For the ones who would like to test what follows but do not know how to install ffmpeg here is another post showing how to do it, for both Windows and OSX users: http://jeremyrichard.com/tip/install-the-ffmpeg-command-line-tool/.

Process

For the following explanation we will assume that we have a series of images called tunnel_0001.tif, tunnel_0002.tif, tunnel_0003.tif and so on, that are located inside a folder called ‘tunnel’. Also two things are to be remembered before we start:

So here is the process:

  1. Open the Terminal or Console and execute the following command: cd /*path*/tunnel. Here we change directory (cd) to go in the folder called ‘tunnel’ where our images are located (/*path*/tunnel);* 1
  2. Now, being inside the folder, we can execute the following command in the terminal: ffmpeg -i tunnel_%04d.tif tunnel.mov.2 Here, a video file (tunnel.mov) is being created inside the same folder using all the tiff files (.tif) starting by tunnel_ (-i tunnel_) with four placeholders (%04d).
It is this %04d which makes it possible for ffmpeg to grab a series of images to make a video file
%04d makes it possible for ffmpeg to grab a series of images which have four placeholders

* In case we are not sure of the exact written path (but we know ‘visually’ where the file is):

The command

What matters the most in to transforming our image sequence to a video file is the following command: ffmpeg -i tunnel_%04d.tif tunnel.mov

-i tunnel_%04d.tif: that is where the magic happens; as an input (-i) we grab all (%) our tiff images (.tif) that have a common name (tunnel_) with the definition (d) of its numerical placeholders (04):

Framerate

For this particular command, ffmpeg works by default in 25 frames per second. So if this is not the framerate we want to apply, we can change it:

ffmpeg -r 23.98 -i tunnel_%04d.tif tunnel.mov

Here we set our framerate (-r) to 23.98 frames per second.

Uncompressed version

We might want to to keep the original codec and quality of the original images into the outputted video file, so we are certain to work with an uncompressed video. It is useful when having to do some effects or rotoscoping on the outputted video, for example. The following command line will allow exactly that:

ffmpeg -i tunnel_%04d.tif -c:v copy tunnel.mov

The -c:v function allows us to precise the video codec of our video output. And by putting copy we are simply copying the codec from the original images; there is no re-encoding when creating the video file.

There is an interesting and more in depth forum post about the subject available here: http://jeremyrichard.com/documents/lossless-and-uncompressed-using-ffmpeg/.

Proxy version

For editing purposes we can make proxy videos out of our image sequence so our (old) computer won’t suffer to much of our 4K images… So for example, if working on Media Composer, we can execute the following command line:

ffmpeg -i tunnel_%04d.tif -c:v dnxhd -b:v 120MB tunnel.mov

Here we tell ffmpeg to encode our sequence using the DNxHD codec (-c:v dnxhd) at a bitrate of 120 megabytes (-b:v 120MB). That is if we want to use the DNxHD120 codec, having 185MB instead, for example, would mean that we want to use the DNxHD185 codec.

If we need to enter another codec such as ProRes or H264 after the -c:v function, we can execute the following command to list the codecs available with ffmpeg: ffmpeg -codecs. The ‘s’ at the end of codecs is not to be forgotten.

Image sequence

Starting number

One downside of how the program handles this, is that it needs the sequence to start by 0 or 1, but if it is not the case we can still renumber the sequence by doing a batch.

As it is not part of ffmpeg functionalities, the explanation of how to create a batch to renumber a file sequence has its own post, which can be find to the following link: http://jeremyrichard.com/tip/batch-renumber-files-with-zero-padded-sequential-number/. There are explanations for both OSX and Windows users with no need of third parties software.

Broken numbers

If the numbers of our image sequence appears to be broken, ffmpeg will simply stops the process where the break happens. So if our sequence appears like this: tunnel_001.tif, tunnel_002.tif, tunnel_003.tif, tunnel_009.tif, tunnel_010.tif, etc, ffmpeg will stop to add the images together once he reaches the tunnel_003.tif file, as the next image in the series is tunnel_009.tif and not tunnel_004.tif. The video file would then be composed of only the images between tunnel_001.tif and tunnel_003.tif.

Screenshot of the Finder
If the sequence is broken in our image sequence’s number, ffmpeg will stop where the digits don’t follow.

If we do want all the images to be put together, despite the break, there is a command to achieve this (by cheating a bit):

ffmpeg -pattern_type glob -i '*.tif' tunnel.mov.

As I understand it, -pattern_type is there to tell ffmpeg that we are looking for something that comes back (a common pattern) in the files which should be in the files’ names, hence the glob parameter. We also precise that we do the search in all the files (*) with a tiff extension (.tif).5 Finally we enter the name and extension we want for the video (tunnel.mov). We can also add a specific framerate (-r), bitrate (-b:v), codec (-c:v) and so on.

The End