#!/bin/sh # This script records video streams via VLC, or better via cvlc which is VLC without its GUI. # Its main purpose is to record video streams from a RTSP playlist like the one used by free.fr for FreeTV. # You may record one stream at a time, as all instances of VLC get badly killed in the end. # To use it, make the script executable: # chmod +x video-stream-recording.sh # Then type : sh video-stream-recording.sh # DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE # TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION # 0. You just DO WHAT THE FUCK YOU WANT TO. DEFAULT_URL='rtsp://mafreebox.freebox.fr/freeboxtv' DEFAULT_CHANNEL=204 DEFAULT_FILENAME='capture' DEFAULT_DEST_FOLDER=$HOME'/Videos' DEFAULT_COMPRESSION=4 # INPUT echo "You may record all sorts of video streams via VLC, provided VLC can handle the stream protocol." echo "You may interrupt programming at every moment with Ctrl+C." # choose a stream echo "Please supply your stream URL, leave blank for FreeboxTV Multiposte (http://mafreebox.freebox.fr/freeboxtv/playlist.m3u)" read url : ${url:=$DEFAULT_URL} if [ "$url" = "rtsp://mafreebox.freebox.fr/freeboxtv" ]; then echo "Select a channel (default: ${DEFAULT_CHANNEL}) (can range from 201 to 110080)" read channel : ${channel:=$DEFAULT_CHANNEL} if [ $channel -lt 201 ] || [ $channel -gt 110080 ]; then echo 1>&2 Usage: For channels see http://mafreebox.freebox.fr/freeboxtv/playlist.m3u exit 1 fi url="$url/$channel" fi echo ">>>>>>>>>> Your stream is located at $url " # choose destination folder echo "Select the destination folder: default is ${DEFAULT_DEST_FOLDER}" read folder : ${folder:=$DEFAULT_DEST_FOLDER} # test if the folder exists if test ! -d $folder then echo "The folder does not exist: $folder" echo "Create it? (y/N)" read makefolder : ${makefolder:="n"} # otherwise make it if [ "$makefolder" = "y" ]; then mkdir -p $DEFAULT_DEST_FOLDER fi fi # choose a filename echo "Select a filename: default location is $folder/$DEFAULT_FILENAME" read filename : ${filename:=$DEFAULT_FILENAME} # unclean adding of file extension, would maybe be better in the VLC part. file=$folder'/'$filename'.mpg' echo ">>>>>>>>>> Your file will be saved as $file" # choose a compression level echo -n "Select compression level: 1 - MPEG2 - excellent quality " [ x$DEFAULT_COMPRESSION = x"1" ] && echo -n "(default)" echo -n " 2 - MPEG4 - good quality " [ x$DEFAULT_COMPRESSION = x"2" ] && echo -n "(default)" echo -n " 3 - MPEG1 - extraordinary quality, scaled 75%" [ x$DEFAULT_COMPRESSION = x"3" ] && echo -n "(default)" read compressionlevel if [ x"$compressionlevel" = x1 ] && [ x"$compressionlevel" != x2 ] && [ x"$compressionlevel" != x3 ] ; then echo 1>&2 Usage: 1 - mpeg2, 2 - mpeg4 or 3 - mpeg1 exit 1 fi # choose start time echo "Start recording at? e.g. type 15:35 (default: now)" read startrecording : ${startrecording:='now'} #choose stop time echo "Stop recording at? e.g. type 17:00"; read stoprecording; # go! # make sure atd is running echo "In order to work, we need the at daemon to be running." sudo /etc/init.d/atd start case $compressionlevel in # MPEG2 1) echo "/usr/bin/cvlc $url --intf=dummy --vout-filter deinterlace:bob ':sout=#transcode{vcodec=mp2v,vb=1024,acodec=mp3,ab=192,channels=2}:std{access=file,mux=ts,url=$file}}':sout-all" | at $startrecording;; #MPEG4 2) echo "/usr/bin/cvlc $url --intf=dummy --vout-filter deinterlace:bob ':sout=#transcode{vcodec=mp4v,vb=512,acodec=mpga,ab=128}:std{access=file,mux=ts,url=$file}}':sout-all" | at $startrecording;; #MPEG1, VideoBitrate: 512, Scale: 75%, audio codec: mp3, AUdioBitrate: 96 3) echo "/usr/bin/cvlc $url --intf=dummy --vout-filter deinterlace:bob ':sout=#transcode{vcodec=mp1v,vb=512,scale=0.75,acodec=mp3,ab=96,channels=2}:std{access=file,mux=ps,url=$file}}':sout-all" | at $startrecording;; esac # stop recording & terminate script echo killall cvlc | at $stoprecording exit 0