Creating time-laps with G'MIC

I have an Lua script for darktable to create time-laps videos[1].
In this script I use MEncoder from the MPlayer project to create the video from the single frames. The bad thing is now, that Ubuntu replaced mplayer with mplayer2 and mplayer2 doesn’t include mencoder any longer. :frowning:
Now I’m looking for a new tool and to use ffmpeg or avconv looks as dangerous as mencoder, because it looks like Ubuntu is removing and adding them every now and then.
Thats why I’m here. I’ve seen, that g’mic has the “-files2video” option. But I couldn’t find an example how to use it from the command line. And I’m missing a list of supported codecs.

[1] https://github.com/darktable-org/lua-scripts/blob/master/contrib/video.lua

1 Like

Honestly, I’ve always fallen back to using ffmpeg (or equivalent) to compile all of my frames back into a video. This is assuming you want to script it, of course. Just as often I’ll bring those frames into something like Blender, where I can title, cut, add scenes and transitions, audio, and more.

Are you simply creating video, or muxing audio in as well?

At the moment I’m creating just video without sound. I thought about adding an option to add music, but I’m not sure how useful that is.
What annoyed me about ffmpeg was, that Canonical removed it in Ubuntu 14.04 and 14.10. G’mic could be a nice replacement here. I just need:
programm -input “file1.jpg, 3.jpg, a.jpg” -framerate 15 -output “output.mpeg”

1 Like

I know that @David_Tschumperle added read support for video in G’MIC, I am not so sure about write support, so I’ll defer to him to answer this more fully. :slight_smile: If you want to explore the ffmpeg route (and don’t mind compiling it or finding a repo with it), feel free to hit me up to experiment!

With latest G’MIC version (i.e. 1.6.5.2 and 1.6.6.0_pre), I can create a video like this:

 gmic -files2video frames\*.jpg,output.avi,15

Example:

$ gmic -files2video \*.ppm,foo.avi,15
[gmic]-0./ Start G'MIC interpreter.
[gmic]-0./ Convert image files 'frame_000000.ppm,frame_000001.ppm,frame_000002.ppm,frame_000003.ppm,frame_000004.ppm,frame_000005.ppm,frame_000006.ppm,frame_000...' into frames of output video 'foo.avi', with 15 fps and mp4v codec.
 - Image 100/100 [frame_000099.ppm] -> [foo.avi]                    
[gmic]-0./ End G'MIC interpreter.

Why would you not use ffmpeg for this?

@David_Tschumperle: Where can I find a list with supported video codecs?

  1. I’m a little bit annoyed about the ffmpeg vs. libav battle.
  2. With g’mic in the pipeline I could do more funny stuff in the future.

Tobias the “battle” has nothing to do with this. Seems logical to me to use G’MIC for what G’MIC is best for, and use ffmpeg for what it’s best for, making use of each one’s unique features.

G’MIC uses the OpenCV video writer class to save a video, so it highly depends on your OpenCV installation.
The codec uses the FourCC format, as described here : http://www.fourcc.org/codecs.php
(most of them won’t work probably, so you have to make experiments ).

Why not use x264 directly?

@CarVac

  1. Because I didn’t know about it.
  2. Now that I know it, it looks like it’s “just” an H.264 encoder. I’m not sure if that is enough for my use case.
    I will definitive take a closer look, thanks for the tip.

@David_Tschumperle
OK, then g’mic uses OpenCC using ffmpeg (Depending on the OS) using x264 (Depending on the selected codec)
That looks like that are too many wrapper. :wink:

@Morgan_Hardwood
Do you know if I can use ffmpeg with a list of single images and not filename pattern like “image%d.jpg” or “*.jpg” for the input images?

Probably, but do you have image sequences for time-lapse that doesn’t have the filenames that are sequential or can be globbed?

If you are under Linux or some other *nix system, the easiest solution is probably to make a small bash script that takes an arbitrary list of file names (or maybe a text file with the list?) and creates symlinks with sequential names like image%d.jpg.

I can make a small example of that if needed…

@Tobias if “*.jpg” works, and it works, then I don’t see why “1.jpg 3.jpg cats.jpg” shouldn’t.

I get the filenames from darktable and simply don’t know what I get. Normally it should be a sequence, but perhaps an image from the sequence was deleted…

The idea with the symlinks is nice, should be faster then copying.

I don’t like the idea of calling a bash script from a Lua script. But if you are interested you can look into this Lua script and try to bring it to an other encoder:
https://github.com/darktable-org/lua-scripts/blob/master/contrib/video_mencoder.lua

No it doesn’t I’ve just tried this, and it doesn’t work:

ffmpeg -framerate 1 -pattern_type glob -i FL8A8011.jpg, FL8A8051.jpg -c:v libx264 out.mp4
ffmpeg -framerate 1 -pattern_type glob -i FL8A8011.jpg FL8A8051.jpg -c:v libx264 out.mp4
ffmpeg -framerate 1 -pattern_type glob -i 'FL8A8011.jpg FL8A8051.jpg' -c:v libx264 out.mp4
ffmpeg -framerate 1 -pattern_type glob -i 'FL8A8011.jpg, FL8A8051.jpg' -c:v libx264 out.mp4

But this work:

ffmpeg -framerate 1 -pattern_type glob -i '*.jpg' -c:v libx264 out.mp4

@Tobias: Honestly I have no direct experience with LUA, but I will have a look.

Meanwhile, here is what I would do with PhotoFlow’s batch processor, using a simple bash script (assuming you have a set of CR2 files in the current directory, from which you would like to generate the time lapse. Replace CR2 with whatever format you actually use):

#! /bin/bash
rm -rf __output
i=1
for f in $(ls *.CR2); do
    j=$(printf "%05d" $i)
    pfbatch "$f" raw_params.pfp __output/img${j}.jpg
    i=$((i+1))
done
cd __output
ffmpeg -framerate 1 -pattern_type glob -i '*.jpg' -c:v libx264 out.mp4

raw_params.pfp is the preset that stores your RAW processing parameters for the image sequence (white balance, exposure compensation, output colorspace, etc…). Here is a link that explains how to create such a preset (look toward the end of the page). Actually the preset could contain any sequence of adjustments in addition to the basic RAW processing (saturation, local contrast, sharpening, etc…).

Do you have control over the output filenames when exporting from dt via LUA script? If so, I would imagine that would solve the problem nicely as you could then use the glob pattern in ffmpeg (which makes things much, much easier).

@Tobias
cat a.png h.png 2.png meow.png | ffmpeg -f image2pipe -i pipe:0 out.mkv
though if you find yourself needing to do that then I would look for a way to fix the workflow.

1 Like

No, if I had it would be to simple.