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
set("log.file",false)
set("log.stdout",true)
# Don't follow wall-clock time, run at maximum speed!
set("root.sync",false)
# Enable video
set("frame.video.channels",1)

# 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(_) =
 shutdown()
 [("title","garbage")]
end
# 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
output.file.theora(reopen_on_metadata=true,
                   "/tmp/$(title).ogv",final)
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 blog.rastageeks.org.