Liquidsoap 0.9.2 : Video with a static image.

A simple video script

The other day, I wanted to prepare some videos of my favorite reggae and soul tunes for uploading them to YouTube. My goal was very simple: prepare a video with the music, and a static image.

After briefly digging for a simple software to do that, which I could not find, I said “hey, why not doing it with liquidsoap”? Well, that is fairly easy! Video support in liquidsoap is still yound and experimental, but the amount of things that can be done is already quite important, so I thought this would be an interesting example..

All you have to do is to prepare a PPN version of the picture, using

convert /path/to/image.jpeg /path/to/image.ppn 

and have the mp3 or ogg file in an other place...

On the liquidsoap side, the only difficulty is to produce a clean cut file, instead of an inifinite stream as usual. Unfortunately, we cannot easily use a fallible file output as in the cookbook: even though our music source may only produce one track, our video stream is infinite, and thus adding them yields an infinite stream.

We also disable synchronization (root.sync setting) so that liquidsoap runs as fast as possible, instead of decoding the music at a normal rate.

Here is the code:

# Log to stdout
# Don't follow wall-clock time, run at maximum speed!
# Enable video

# The video source using a static image
s = video.image(width=240,height=240,x=40,"/tmp/bla.ppm")
# The audio file
audio = single("/tmp/bla.mp3")

# The special metadata function, that also triggers shutdown.
def end_meta(_) =
# Our special blank source
bl = map_metadata(end_meta,blank())

# And the final source: the sequence song and blank added
# with the video of the static image..
final = add([sequence([audio,bl]),s])

# Output to a theora file
Grab the code!

This should produce on file named <title>.ogv where <title> is the title metadata of your song, and another near-empty file garbage.ogv.

Adapted from