1 Title: Recording video from cron using VLC
2 Tags: english, nuug, video
5 <p>One think I have wanted to figure out for a along time is how to
6 run vlc from cron to do recording of video streams on the net. The
7 task is trivial with mplayer, but I do not really trust the security
8 of mplayer (it crashes too often on strange input), and thus prefer
9 vlc. I finally found a way to do it today. I spent an hour or so
10 searching the web for recipes and reading the documentation. The
11 hardest part was to get rid of the GUI window, but after finding the
12 dummy interface, the command line finally presented itself:</p>
14 <blockquote><pre>URL=http://www.ping.uio.no/video/rms-oslo_2009.ogg
16 DISPLAY= vlc -q $URL \
17 --sout="#duplicate{dst=std{access=file,url='$SAVEFILE'},dst=nodisplay}" \
18 --intf=dummy</pre></blockquote>
20 <p>The command stream the URL and store it in the SAVEFILE by
21 duplicating the output stream to "nodisplay" and the file, using the
22 dummy interface. The dummy interface and the nodisplay output make
23 sure no X interface is needed.</p>
25 <p>The cron job then need to start this job with the appropriate URL
26 and file name to save, sleep for the duration wanted, and then kill
27 the vlc process with SIGTERM. Here is a complete script
28 <tt>vlc-record</tt> to use from <tt>at</tt> or <tt>cron</tt>:</p>
30 <blockquote><pre>#!/bin/sh
35 DISPLAY= vlc -q "$URL" \
36 --sout="#duplicate{dst=std{access=file,url='$SAVEFILE'},dst=nodisplay}" \
37 --intf=dummy < /dev/null > /dev/null 2>&1 &
41 wait $pid</pre></blockquote>