09 May 2011

YouTube video clip to DVD in one command

You may wish to alter the device on which the DVD is burned via (/dev/sr0 in the example) or the default burn speed, or you may have a more appropriate place to store up to maybe 9GB of temporary files (the DVD content plus an ISO file of the same), however this one command turns a downloaded YouTube clip into a push-in-n-it-plays DVD:

#!/bin/sh
if [ -f "$1" ]; then
    LEN=$(ffmpeg -i "$1" 2>&1 |gawk '/ Duration: / { print gensub(":[0-9][0-9]\\.[0-9][0-9],", "", "g", $2); }')
    if [ $LEN = "" ]; then
        echo No video minutes seen in the file "'$1'"
        return 1
    fi
else
    echo File "'$x'" does not appear to exist or is a dir or device-node
    return 1
fi
rm -rf /tmp/DVD_temporary /tmp/DVD_temporary.iso /tmp/temporary.xml /tmp/temporary.jpg
nice ffmpeg -i "$1" -target ntsc-dvd -y /tmp/temporary.mpg
cat <<ENDOFFILE > /tmp/temporary.xml
<dvdauthor>
    <vmgm />
    <titleset>
        <titles>
            <pgc>
            <vob file="/tmp/temporary.mpg" />
            </pgc>
        </titles>
    </titleset>
</dvdauthor>
ENDOFFILE
dvdauthor -o /tmp/DVD_temporary -x /tmp/temporary.xml
mkisofs -dvd-video -udf -o /tmp/DVD_temporary.iso /tmp/DVD_temporary
wodim -eject -v dev=/dev/sr0 /tmp/DVD_temporary.iso

It is also not too difficult to fetch YouTube downloading scripts & alter this script a little so that “nameofscript http://www.youtube.com/watch?v=ABC123DEF456” (insert real YourTube URL here) results in a clip being downloaded (in off-peak time if it suits) & burned to whatever blank DVD happens to be in the drive about 3 minutes after the download completes.

No comments: