YouTube page showing the Fatboy Slim 'Weapon of Choice' music video.

A YouTube page viewed with Firefox on a KDE desktop under Linux.

How to download YouTube videos and convert them to XviD and DivX

Many DVD players will play video files, if they are of the proper format — typically XviD. Our goal is to download video files from web pages and convert them into a format that can easily be played on your DVD player and watched on your television.

First, find the videos you want to watch on your DVD player and television. Maybe your taste runs to the sorts of films you can get from Archive.org — perhaps Classic Soviet movies, or possibly 1970 industrial hygiene shorts explaining blasting caps and the dangers they pose to children, If so, you might be able to directly download a DivX file and you problem is already solved! If not, get what you can and skip ahead.

But what if you want to download a video from YouTube?

Download the Video

Start by getting some form of the video onto your system. The easiest choice is keepvid.com or tubegrip.com Just go to the very simple and easy to use KeepVid page or TubeGrip page and copy and paste the YouTube URL into place. You should see a result that looks something like the below:

  Download links

Links found on http://www.youtube.com/watch?v=hBzXChYSOpU
Report any problems to: keepvid.com@gmail.com

>> Download << (FLV - Low Quality)
>> Download << (MP4 - High Quality)

Just right-click on that download link marked as "MP4 - High Quality" and save the file. Change its name to something more useful than the default video.mp4 file name!

An even simpler tool is youtube-dl, a simple command-line program for downloading video files if you know the URL of page. See the youtube-dl page for simple instructions on how to install and use that tool on your system.

What did you get? What do you need?

You should now have an MPEG video file on your system. Let's verify that:

$ file fatboy-slim.mp4
fatboy-slim.mp4: MPEG sequence, v2, program multiplex 

You could play that video on your computer with gmplayer or a similar media player tool. But if you simply burn the file onto CD or DVD media, your DVD player probably won't play it even though your player has a sticker saying "MPEG" on it.

Your player probably needs something in XviD format, a video codec that follows the MPEG-4 Part 2 Advanced Simple Profile standard.

Go ahead, check your DVD player's manual, I'll wait.

If it specifies DivX instead of XviD, I also have a fix for that a little further below.

Convert the video format

There are several ways of doing this. I came across good descriptions of various methods at linux.com, and linuxreviews.org. A very simple method would be to use the transcode tool. Better methods involve ffmpeg or mencoder. See those pages for more details, including how to do two-pass encoding with mencoder, at linuxreviews.org or the mplayer site, including tricks for dealing with the awful Microsoft WMV/ASF/WMX Windows Media formats.

I converted the downloaded video file into two new files, one in XviD and the other in the DivX format. I put both files onto a CD, simply making an ISO-9660 file system with two files, test-xvid.avi and test-xvid.avi, then I loaded that CD into my DVD player and tried to play them. My player, a Samsung DVD-1080P9, will play XviD and DivX files, as would my previous player, an Insignia NS-DRVCR.

Convert YouTube MPEG file input-file.mp4 to XviD file output-xvid.avi:

$ mencoder input-file.mp4 \
	-ovc xvid \
	-xvidencopts bitrate=1000:autoaspect \
	-vf pp=lb -oac mp3lame -lameopts fast:preset=standard \
	-o output-xvid.avi

    input-file.mp4        This is the input file

    -ovc xvid             Select the XviD output video codec

    -xvidencopts          Options for the XviD codec:
        bitrate=1000      1000 kbits/second
	autoaspect        Store the movie aspect internally, automatically taking
                          into account any cropping, expanding, or scaling.

    -vf pp=lb             Video filter: deinterlacing filter

    -oac mp3lame          Select the MP3 output audio codec, generated with LAME

    -lameopts             Options for the LAME MP3 codec:
        fast              Faster encoding
        preset=standard   High quality variable bit-rate encoding, 200-240 kbps.

    -o output-xvid.avi    This is the output file

Convert YouTube MPEG file input-file.mp4 to DivX file output-divx.avi:

$ mencoder input-file.mp4 \
	-ovc lavc \
	-lavcopts vcodec=mpeg4:vbitrate=1000:mbd=2:v4mv:autoaspect \
	-vf pp=lb -oac mp3lame -lameopts fast:preset=standard \
	-o output-divx.avi

    input-file.mp4        This is the input file

    -ovc lavc             Select the libavcodec output video codec

    -lavcopts             Options for the libavcodec codec:
        mpeg4             Use the MPEG=4 codec
        vbitrate=1000     1000 kbits/second for the video stream
	mbd=2             Macroblock decision algorithm #2: use the MB mode with
                          the best rate distortion.
	v4mv              Allow 4 motion vectors per macroblock, slightly better quality.
	autoaspect        Store the movie aspect internally, automatically taking
                          into account any cropping, expanding, or scaling.

    -vf pp=lb             Video filter: deinterlacing filter

    -oac mp3lame          Select the MP3 output audio codec, generated with LAME

    -lameopts             Options for the LAME MP3 codec:
        fast              Faster encoding
        preset=standard   High quality variable bit-rate encoding, 200-240 kbps

    -o output-divx.avi    This is the output file

Convert many video files

If you have any version of Unix or Mac OS X, you can easily automate the conversion of an arbitrary number of files.

First, create two fairly simple shell scripts. Put them in some directory in your PATH.

My ~/bin/script/video-to-xvid contains the following, most of it has to do with cautiously deriving an output file name from the input file name:

#!/bin/bash

INPUT=$1
OUTPUT=$( echo "$1" | sed -e 's/\.[Mm][Pp]4/-xvid.avi/'
                          -e 's/\.[Mm][Pp][Gg]/-xvid.avi/'
                          -e 's/\.[Mm][Pp][Ee][Gg]/-xvid.avi/'
                          -e 's/\.[Vv][Oo][Bb]/-xvid.avi/' )
if [ "$1" = "$2" ]; then
        echo "Refusing to overwrite ${INPUT}!"
        echo "Change it to a name like ${INPUT}.mp4 and try again."
        exit
fi

mencoder "${INPUT}" \
        -ovc xvid \
        -xvidencopts bitrate=1000:autoaspect \
        -vf pp=lb -oac mp3lame -lameopts fast:preset=standard \
        -o "${OUTPUT}"

My ~/bin/script/video-to-divx contains this:

#!/bin/bash

INPUT=$1
OUTPUT=$( echo $1 | sed -e 's/\.[Mm][Pp]4/-xvid.avi/'
			-e 's/\.[Mm][Pp][Gg]/-xvid.avi/'
			-e 's/\.[Mm][Pp][Ee][Gg]/-xvid.avi/'
			-e 's/\.[Vv][Oo][Bb]/-xvid.avi/' )
if [ "$1" = "$2" ]; then
	echo "Refusing to overwrite ${INPUT}!"
	echo "Change it to a name like ${INPUT}.mp4 and try again."
	exit
fi

$ mencoder "${INPUT}" \
	-ovc lavc \
	-lavcopts vcodec=mpeg4:vbitrate=1000:mbd=2:v4mv:autoaspect \
	-vf pp=lb -oac mp3lame -lameopts fast:preset=standard \
	-o "${OUTPUT}"

Then just use those scripts as follows:

From csh or tcsh:

% foreach F ( *.mp4 *.mpg *.mpeg )
foreach? video-to-xvid $F
foreach? end


From bash:

$ for F in *.mp4 *.mpg *.mpeg
> do
>    video-to-xvid $F
> done

How long does that take? About two to four hours per gigabyte of video input, on a system with an AMD Athlon XP 2500+, 1.5 GB of RAM, and the latest Linux kernel.

Other pages

Video Conversion:

Other Technical Topics

Radio topics — Ham radio, construction and repair, propagation, frequencies, etc

Click here to inquire about advertising on this or any page on this site.
Home Unix/Linux Networking Cybersecurity Travel Technical Radio Site Map Contact


Use /bin/vi! Manipulate images with ImageMagick! Hosted on OpenBSD
Hosted on Apache This site is viewable with any browser Valid XHTML 1.0! Valid CSS!
© Bob Cromwell Feb 2012. Created with /bin/vi and ImageMagick, hosted on OpenBSD with Apache.    Root password available here, privacy policy here.