Thursday, January 6, 2011

Downloading YouTube clips, stitching together MP3 files, and encoding MP4 files in Ubuntu 10.04 Lucid

Ever wanted to download YouTube clips, extract various audio clips from MP3 files and stitch them together, or simply re-encode DVD-clips from your home video collection into MP4 files so you can share?

All the tools for Ubuntu to download are available. However, many of them don't work out of the box. Here are the tools of trade:

youtube-dl - The one that comes with Ubuntu Lucid seems to have trouble downloading YouTube clips. You often see "ERROR: format not available for video" error messages. It seems that YouTube keeps changing their API interface to render the distro version obsolute. I had to download the latest Python script from the site in order to get anything to work. There is a bug filed at https://bugs.launchpad.net/ubuntu/+source/youtube-dl/+bug/609545. It may be better simply to just download the latest Python script at https://bitbucket.org/rg3/youtube-dl/wiki/Home

ffmpeg - The one that comes with Ubuntu 10.04 has issues with encoding AAC, MP3, MPEG4 files, effectively rendering the distribution version not very useful. What you want to do is install Medibuntu, which is the media package not distributed with vanilla Ubuntu because of licensing restrictions. Medibuntu comes with an ffmpeg version that is compiled to support AAC/MP3/MP4 encoding (assuming the accompanying libraries are added). Take a look at http://www.unixmen.com/linux-tutorials/937-things-to-do-after-installing-ubuntu-1004-lts-lucid-lynx. You can use ffmpeg to extract MP3 clips from video files (check out http://www.catswhocode.com/blog/19-ffmpeg-commands-for-all-needs)

handbrake-gtk / handbrake-cli - You use this tool to encode DVD clips into MP4 files. The versions that comes with the Ubuntu 10.04 has the "Start" button disabled, which makes them non usable too. Video file sharing sites like SmugMug limit uploads to 10 minutes and 1Gb, but you can use the tool to save the output into separate files using handbrake-gtk and designating the chapter #'s to save. You can use the Handbrake GTK interface to add these chapters into a queue, so that you can batch everything up. You can also use the Handbrake CLI interface,
such as the following example which searches for all VOB files, creates a HandBrake CLI command for each file, and dumps out to stdout (you can pipe to 'sh' to execute):
find *.VOB | awk '{print "HandBrakeCLI -e x264  -q 20.0 -r 29.97 --pfr  -a 1 -E faac -B 160 -6 dpl2 -R Auto  -D 0.0 -f mp4 -4 -X 1024 --loose-anamorphic -m -i \"/mnt/cdrom/VIDEO_TS/"$0"\" -o \"/destdir/"$0".mp4\""}' 

You may be better off invoking "HandBrakeCIL --preset-list" and "HandbrakeCLI --help" to see how these commands work. But basically this find command will look for all VOB files and output them to their appropriate MP4 files.

For appending together MP3 files, make sure they are using the same bit-rate encoding.

http://stackoverflow.com/questions/62618/what-is-the-best-way-to-merge-mp3-files
fmpeg -i originalA.mp3 -f mp3 -ab 128kb -ar 44100 -ac 2 intermediateA.mp3  
ffmpeg -i originalB.mp3 -f mp3 -ab 128kb -ar 44100 -ac 2 intermediateB.mp3
Then, at runtime, concat your files together:

cat intermediateA.mp3 intermediateB.mp3 > output.mp3

SmugMug video uploading: Also, keep in mind that SmugMug gives you very little feedback about why an "Upload failed" with their new HTML5 drag-and-drop uploader. You have to rename the files to an .mp4 because it doesn't recognize the file format automatically and limit the size of your uploads to less than 1 Gb.

1 comment: