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 a static image and the music I wanted to upload..
After briefly digging for a simple software to do that, which I could not found, I said “hey, why not doing it with liquidsoap !”. Well, that is fairly easy ! Video support in liquidsoap is very young, but the amount of things that can be done is already quite important, so I though 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...
From the scripting point of view, the only difficult thing is to have liquidsoap stop at the end of the song.. As liquidsoap is mainly a streaming language, it is not designed to be able to stop easily. It should be made better soon, but for now I had to use a special trick: compose sequentially the song with a blank source. On the blank source, I add special metadata such that the output file is reopened with a new title when the song has ended. Eventually, the shutdown is triggered when adding the new metadata on the blank source.
Here is the code:
# Log to stdout set("log.file",false) set("log.stdout",true) # Disable real-time processing, # to process with the maximun 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 song. audio = single("/tmp/bla.mp3") # The special metadata function, that # also triggers the shutdown.. def end_meta(_) = shutdown () [("title","prout")] end # This is the blank source bl = map_metadata(insert_missing=true, update=false,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, reopen on # new metadata.. output.file.theora(reopen_on_metadata=true, "/tmp/$(title).ogv",final)
Reproduced from blog.rastageeks.org