Note
Good GUI for all this mess: k9copy

Backing Up Stubborn DVDs

Some DVDs really piss me off. It’s important that you use a DVD player that is not so fussy about disks and will just follow your instructions to read all the 1s and 0s off the accursed disk. Here’s what you do:

ddrescue -n -b 2048 /dev/dvd output_raw.iso
dvdbackup -M -i output.iso -o dvd_structure
mkisofs -dvd-video -o clean_dvd.iso dvd_structure

Been liking acidrip lately. Good GUI for all the complex mess.

Rotating with mencoder

Sometimes you take a video with your phone and it should be in portrait, but players play it in landscape. This command rotated a goofy 3gp video file from my Andriod phone:

mencoder -vf rotate=1 -ovc lavc -oac pcm fromphone.3gp -o portrait.mp4

ffmpeg

ffmpeg is a great tool for converting video from something to something else. See the ffmpeg documentation.

First you might need to install exotic codecs. If things don’t quite work, try this:

$ sudo apt-get install  libavcodec-dev libavcodec-extra-52 libavcodec-unstripped-52

A good way to shrink videos from the Canon A590 to send to fb:

ffmpeg -i mvi_0378.avi -f avi -vcodec mpeg4 -s 320x240 -r 20 -ar 22050 -b 1000000 ski2.mpg

Another application to shrink videos to save space (factor of 5 without noticeable quality loss):

ffmpeg -i inputfile.avi -ar 32000 -s 480x360 -b 1252.4k outputfile.avi

The -s is the new size. The -ar is the audio bitrate.

Here is another way to select a portion of a video to make a smaller one:

ffmpeg -i SK8.mp4 -ss 00:08:10.0 -vframes 5100  -acodec copy -vcodec copy -async 1 OSK8-test.mp4

Note that ffmpeg has a -t option to set the duration time of the video, but I’ve never gotten it to work and have seen reports of others with the same problem. But -vframes does seem to cut off the video at the right place. It’s annoying they don’t just have start time and stop time which would make sense. To get the correct vframes value you have to figure out the duration in seconds you want and then multiply by the frame rate (often 30). To get frame rate, play the video with mplayer and watch its console output for "FPS".

youtube-dl

Also use youtube-dl to get videos from YouTube:

youtube-dl -o Nobodys_Fool.flv http://www.youtube.com/watch?v=MCOrtJMQmVs

Sometimes you get the annoying webm format that mplayer is not so good with (maybe that will get fixed). So it’s sometimes good to try and get a "better" file format, where better doesn’t necessarily mean image quality.

First you need to see what’s available:

$ youtube-dl --all-formats --get-filename http://www.youtube.com/watch?v=MCOrtJMQmVs
MCOrtJMQmVs-43.webm
MCOrtJMQmVs-35.flv
MCOrtJMQmVs-34.flv
MCOrtJMQmVs-18.mp4
MCOrtJMQmVs-5.flv

Then you need to download the one that makes sense:

youtube-dl -f 35 http://www.youtube.com/watch?v=MCOrtJMQmVs

Another useful option is -t which names the file after the title of the video instead of the messy (to us) hashed name.

Avidemux

After having way too much trouble doing simple track substitutions with the command line tools, I installed this:

sudo apt-get install avidemux

And it was able to put an mp3 over a video no problem. I didn’t figure out 1% of what this thing did but it seemed to work for that task pretty easily.

JPEG to Video

The following technique is useful for making stop motion animation videos and videos of slide shows. It takes a list of jpeg files (and only jpeg files as I understand it) and converts them into a video format. The following was able to take hundreds of jpegs and make them into a video that could be uploaded to YouTube.

$ ffmpeg -r 10 -b 1800 -i %03d.jpg bd4d-10.mp4

The -r is the framerate, here 10 frames per second.

Note
There may be other ways of doing this, but the easiest is to name all the jpegs to use 001.jpg, 002.jpg, etc. If the sequence is broken, ffmpeg will stop encoding. So make sure the names are in order. (Look into using Chris' numbfile program).

Video to MP3

Extract mp3 track of the video to sound files with:

ffmpeg -i DubFX-Made.flv -acodec copy DubFX-Flow.mp3

This assumes that the video has an mp3 encoded sound track. YouTube appears to do this. Here’s a more complicated way to do this that might be necessary:

ffmpeg -y -i INPUT.flv -acodec libmp3lame  -ar 22050 -ab 128000 OUTPUT.mp3

Here’s a function that can turn Youtube videos into mp3 files on the fly:

function ripme {
    youtube-dl -q -o - "$1" | \
    ffmpeg -y -i - -acodec libmp3lame  -ar 22050 -ab 128000 "$2.mp3"
} # End function ripme.
# Call like so:
ripme http://www.youtube.com/watch?v=CknuCTRAW_I Dire_Straits-Walk_Of_Life

To check what streams, audio and video, are in a video file:

ffmpeg -i inputvideo.flv

To actually convert some other audio stream:

ffmpeg -i inpuvvideofile.flv -ab 128k outputaudiofile.mp3

Where -ab specifies the audio bitrate.

To extract a subset of video to a new video:

mencoder -ss 2693.0 -endpos 1350.0 All_Four_Episodes.avi  -ovc copy -oac copy -idx -o Episode_Three.avi

Not that the -ss is the start always in seconds. The -endpos is more ambiguous. If an -ss is used, it means seconds running time of the subset. If -ss isn’t used, it means the same thing and it actually corresponds to endposition (time of subset from zero). This is why in the example, the "end position" is less than the -ss, starting position.

General ripping:

/usr/bin/mencoder dvd:// -dvd-device /dev/sr0 -ovc xvid -xvidencopts pass=2:bitrate=1000 -ni -alang en -oac mp3lame -lameopts vbr=3 -o moviename.avi

Webcam Tricks

Cheese

$ sudo apt-get install cheese

This program is a nice GUI client to the webcam and an easy way to test to see if it’s working properly. Also it can take still snapshots which turns your laptop with a camera into a digital camera. There are "effects" that are helpful when the camera needs to be reversed or turned upside down, etc.

The Program Called "motion"

motion is a very excellent program that will turn on your camera and save what it sees only if there is something changing (if it sees "motion"). This is excellent for security cameras. Fairly easy to use on Ubuntu:

$ sudo apt-get install motion
$ sudo vi /etc/motion/motion.conf
$ sudo /etc/init.d/motion start
$ ls /tmp/motion # Find output here.

mplayer with the webcam

If your webcam puts a feed in an obvious place, mplayer can probably do nice things with it. Here are some examples: This takes a single snapshot off the webcam:

$ mplayer -frames 1 -vo jpeg:outdir=/home/xed/capturedir/ tv://

Watch the camera and specify where it is:

$ mplayer -tv device=/dev/video tv://

Is your camera upside down? This might help:

$ mplayer -vf flip,mirror -tv device=/dev/video0 tv://

Got no graphics? Have no fear! Use ASCII using libcaca:

$ mplayer -vo caca tv://