How to convert YouTube videos to DivX or XviD

776

By Manolis Tzanidakis

Before starting the conversion you need to download the videos to your computer. Youtube-dl is the perfect tool for the job; check Joe Barr’s article for more information. If you use Firefox you can also try the VideoDownloader extension. You will need a recent version of MPlayer with Mencoder built with support for Flash Video; if you can play the .flv videos with MPlayer you’re good to go.

Now save the following lines as flv2avi.sh. Make the file executable with chmod 755 flv2avi.sh and copy it in a directory in your PATH (/usr/local/bin is a good candidate):

#!/bin/shif [ -z "$1" ]; then  
echo "Usage: $0 {-divx|-xvid} list_of_flv_files"  
exit 1fi# video encoding bit rateV_BITRATE=1000while [ "$1" ]; 
do  case "$1" in    -divx)      MENC_OPTS="-ovc lavc -lavcopts 
\        vcodec=mpeg4:vbitrate=$V_BITRATE:mbd=2:v4mv:autoaspect"
;; -xvid)
     MENC_OPTS="-ovc xvid -xvidencopts bitrate=$V_BITRATE:autoaspect"
;; *)
     if file "$1" | grep -q "Macromedia Flash Video"; then
       mencoder "$1" $MENC_OPTS -vf pp=lb -oac mp3lame 
\          -lameopts fast:preset=standard -o 
\          "`basename $1 .flv`.avi"      
else
        echo "$1 is not Flash Video. Skipping"      fi      
;; esac shiftdone

This script converts a list of .flv files to either DivX or XviD, depending on whether you give the -divx or -xvid option, and saves them with their original file name followed by the .avi extension. Usage is very simple: flv2avi.sh -divx first_vid.flv second_vid.flv etc.flv. For more information about the options used on the mencoder commands you can read its man page.

You might also want to create a video DVD with your favorite YouTube videos; check my previous article on the subject.