Linux.com

Feature

How to convert YouTube videos to DivX or XviD

By Manolis Tzanidakis on August 30, 2006 (8:00:00 AM)

Share    Print    Comments   

YouTube clips are everywhere these days, and I must admit I'm addicted to the site. Nevertheless, I've had a couple of small annoyances with YouTube videos. I wanted to be able to play my favorite ones on standalone DVD/DivX players. I also found I couldn't go backwards or forwards when playing the site's Flash videos with MPlayer. For those reasons, I decided to convert my favorite YouTube videos to DivX or XviD formats. Here's how you can do the same.

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/sh

if [ -z "$1" ]; then
  echo "Usage: $0 {-divx|-xvid} list_of_flv_files"
  exit 1
fi

# video encoding bit rate
V_BITRATE=1000

while [ "$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
  shift
done

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.

Share    Print    Comments   

Comments

on How to convert YouTube videos to DivX or XviD

Note: Comments are owned by the poster. We are not responsible for their content.

Bash Script alternative

Posted by: Anonymous Coward on September 10, 2006 11:22 PM
Bash Script alternative
<a href="http://bashscripts.org/viewtopic.php?t=210" title="bashscripts.org">http://bashscripts.org/viewtopic.php?t=210</a bashscripts.org>

#

ffmpeg also works

Posted by: Anonymous Coward on August 30, 2006 05:26 PM
you could also use ffmpeg

ffmpeg -i video.flv -ab 56 -ar 22050 -b 500 -s 320x240 test.mpg

#

Re: ffmpeg also works

Posted by: Anonymous [ip: 24.220.195.69] on September 03, 2007 03:17 PM
You realize that list of commands you gave in ffmpeg is without SOUND and your VIDEO OUTPUT is TERRIBLE by any standards this one on the page doesn't have that problem and his doesn't need 30 slash commands to make a worse video with no sound.

#

Re: ffmpeg also works

Posted by: Anonymous [ip: 76.103.194.0] on November 06, 2007 04:54 AM
OK, I'm trying this ffmpeg code (and others in the replies) and still not getting satisfactory output. I either get no sound, no picture or error on my dvd player. Most all files work with Win Media Player before burning to a disc.

I've got a Philips DVD player DVP3140 (DivX decoder) and I'm ripping the youtube vids with keepvid.com. Anyone else using a similar dvd player/software and having problems or can give me some help?

n00b

#

ffmpeg

Posted by: Anonymous Coward on August 30, 2006 07:44 PM
ffmpeg -i youtube.flv -ar 48000 -ac 2 youtube.avi

#

Re:ffmpeg

Posted by: Administrator on August 30, 2006 10:56 PM
very useful, thanks

#

Re: ffmpeg

Posted by: Anonymous [ip: 87.185.251.181] on November 04, 2007 05:28 PM
yeah, thanks a lot. this is the first commmand that worked with me so far. although i got better results with changing the channels (that is, the -ac parameter) to 1.

#

DivX YouTube alternative

Posted by: Anonymous Coward on August 30, 2006 11:33 PM
DivX has their own YouTube alternative. <a href="http://stage6.divx.com/" title="divx.com">http://stage6.divx.com/</a divx.com> If you're looking for higher (video) quality videos, you may want to take a look at it. They're also natively DivX.

#

Why bother?

Posted by: Anonymous Coward on August 31, 2006 01:22 AM
changing the media format doesn't improve the quality of the content. It still (generally) sux.<nobr> <wbr></nobr>:)

#

Re: Why bother?

Posted by: Anonymous [ip: 99.229.38.252] on October 03, 2007 01:03 AM
think outside the box, how about playing those files on your xvid dvd player..

#

Re: Why bother?

Posted by: Anonymous [ip: 24.93.250.235] on October 11, 2007 05:51 AM
true I used to us veoh until they changed over to sucky low flv files

#

or use theora instead

Posted by: Anonymous Coward on August 31, 2006 03:29 AM
ffmpeg2theora is a simple app that works well for most files

#

The format is MPEG-4, not DivX

Posted by: Anonymous Coward on August 31, 2006 04:01 AM
Please don't spread this DivX nonsense on a public website. You obviously either don't understand basic terms (the difference between software and specification, or codec and format), or you're intentionally lying because of the massive ubiquity of the "DivX myth", which is irresponsible.

The compression you're using is called MPEG-4 ASP (MPEG-4 is a standard developed by MPEG) and the codec (i.e. software) you're using for converting it to this format is FFmpeg (libavcodec) MPEG-4. It has absolutely nothing to do with DivX, which is nothing else than a brand name of a commercial closed-source MPEG-4 codec (a piece of software, not a format) that you don't use.

XviD is not a format either, XviD is a name of yet another MPEG-4 codec, which is open-source (FFmpeg/libavcodec is open-source, too). XviD is a piece of software, it also encodes and decodes MPEG-4 ASP video, just like all other MPEG-4 ASP codecs.

#

Re:The format is MPEG-4, not DivX

Posted by: Anonymous Coward on December 23, 2006 02:54 AM
They have different FourCC values. So while you're right, when you tell Mplayer to write to Xvid or DivX (there's a -xvid option for Mplayer. For Divx you are basically telling it to use mp4 directly), you ARE specifying a different mpeg4 fourcc

#

Compile the worlds best DVD/Movie/Video/MP3 Player

Posted by: Anonymous Coward on August 31, 2006 08:48 AM
HOWTO: Compile the worlds best DVD/Movie/Video/MP3 Player and Encoder (MPlayer and MEncoder).

Interested? Then click here:

<a href="http://linux.coconia.net/" title="coconia.net">http://linux.coconia.net/</a coconia.net>

There are also HOWTOs on:

1) cloning your windows XP/2000 installations using Linux (back-ups).
2) installing windows XP/2000 on a spare partition with Linux.
3) accessing and writing to Windows XP (formatted with the NTFS) from Linux.
4) a script to walk you through a Gentoo Linux installation.
5) Remix those 14 Debian CDs as 2 DVDs.

#

Re:Compile the worlds best DVD/Movie/Video/MP3 Pla

Posted by: Anonymous Coward on September 05, 2006 09:16 PM
Dude (or dudet as it may be), word of friendly advice? Stop yourself!

There are some interesting articles on your sight (I read the Window's boot one and the WTC discussion), but after seeing you spam your sight in the comment section on every open source article I've read in the last little bit, I don't care anymore.

Frankly, I'm starting to hope a blackhole pops into existence in close proximity to your harddisk spindle.

PS: And what's with the bolding? You've got me worried, are we only days away now from being ALL CAPITALS?!?

#

Forgot a couple:

Posted by: Anonymous Coward on August 31, 2006 09:42 AM
6) the entire book "Linux Device Drivers 3" in HTML format.
7) 3D acceleration for ATI cards (simple procedure, works for SuSE and Mandriva).


All at <a href="http://linux.coconia.net/" title="coconia.net">http://linux.coconia.net/</a coconia.net>

#

Re:Forgot a couple:

Posted by: Anonymous Coward on September 02, 2006 05:47 PM
Why do you continually persist in spamming about your site?

#

For players that don't recognize "XVID", etc...

Posted by: Anonymous Coward on August 31, 2006 09:59 PM
The Philips DVP642 doesn't seem to recognize the fourcc codes that mencoder puts in for xvid or ffmpeg-mp4, even though the codecs should be decodable.

adding "-ffourcc=divx" to the options seems to take care of the problem. I've converted xvid and ffmpeg-mpeg4 videos with a simple "mencoder -ovc copy -oac copy -ffourcc=divx" and they play fine, so, like "IE only" websites that actually look fine when you spoof the user agent, spoofing the "fourcc" code appears to work for some players.

#

spaces in filenames

Posted by: Anonymous Coward on November 02, 2006 11:47 AM
Hi, made some little changes to get the script working with filnames containing spaces.



(The original code works as well but saves files containing spaces in name as ".avi" so the file will be overwritten when using a list of filenames to convert and in the end just you'll just get the last file)



May I'll also make an -dir option wich allows to convert all files in a specified directory.



So here the changed version:
<tt>#!/bin/sh

if [ -z "$1" ]; then
  echo "Usage: $0 {-divx|-xvid} list_of_flv_files"
  exit 1
fi

# video encoding bit rate
V_BITRATE=1000

while [ "$1" ]; do
  case "$1" in
    -divx)
      MENC_OPTS="-ovc lavc -lavcopts \
        vcodec=mpeg4:vbitrate=$V_BITRATE:mbd=2:v4mv:autoa<nobr>s<wbr></nobr> pect"
     <nobr> <wbr></nobr>;;
    -xvid)
      MENC_OPTS="-ovc xvid -xvidencopts bitrate=$V_BITRATE:autoaspect"
     <nobr> <wbr></nobr>;;
    *)
      if file "$1" | grep -q "Macromedia Flash Video"; then
           BasName=`basename "$1"<nobr> <wbr></nobr>.flv`
           NewName=`echo "$BasName" | tr ' ' '_'`
           mencoder "$1" $MENC_OPTS -vf pp=lb -oac mp3lame \
             -lameopts fast:preset=standard -o \
             "${NewName}.avi"
           mv ${NewName}.avi "${BasName}.avi"
      else
        echo "$1 is not Flash Video. Skipping"
      fi
     <nobr> <wbr></nobr>;;
  esac
  shift
done</tt>

#

Re:spaces in filenames

Posted by: Anonymous Coward on December 28, 2006 01:55 AM
So how would you change the aspect ratio? When I was using a Windows converter I would change it to 640x480 so that I would work on my Archos player. I think i know where to modify it, but I don't Know what I'm supposed to type.

#

Re:Why recompress that mp3 stream?

Posted by: Anonymous Coward on December 23, 2006 04:43 AM
I munged in -o copy instead of the lame code and it ended up having sync drift. Maybe it's a local problem, but specifying lame seems to avoid this problem.

#

script not working

Posted by: Anonymous Coward on February 02, 2007 11:55 PM
thanks for the tip, but it didn't work out so well for me. after converting, seek now works but the audio goes out of sync if you use seek.

#

Converting flash to mpg, mp3 and dvd

Posted by: Anonymous Coward on March 04, 2007 03:11 AM
Nice post. If you want to convert to mpg, mp3 and dvd there are details here <a href="http://zztools.blogspot.com/" title="blogspot.com">http://zztools.blogspot.com</a blogspot.com>

#

YouTube to DivX Converter

Posted by: Anonymous Coward on April 09, 2007 10:49 PM
Naevius YouTube Converter is a convenient tool to download and convert your favorite videos from YouTube website into the standard AVI DivX video format. To download a video to your computer, enter the YouTube URL for the video, click Start button. It will be downloaded and converted in AVI format - use Windows Media Player or another compatible player to view it.

<a href="http://www.naevius.com/youtube_converter.htm" title="naevius.com">http://www.naevius.com/youtube_converter.htm</a naevius.com>

#

Re: YouTube to DivX Converter

Posted by: Anonymous [ip: 69.157.0.170] on December 07, 2007 09:38 AM
alright, spamming for a windows program on a linux website. great idea. furthermore, you want us to pay for that when quite obviously this article is talking about how to do that without paying a cent, and using a much more powerful/flexible method.

#

Repeatedly compressing and decompressing

Posted by: Administrator on August 30, 2006 07:30 PM
Correct me if I'm wrong, but you are re-enconding an already high compressed video in lossy data compression <a href="http://en.wikipedia.org/wiki/Lossy_data_compression" title="wikipedia.org">http://en.wikipedia.org/wiki/Lossy_data_compressi<nobr>o<wbr></nobr> n</a wikipedia.org>, thus loosing quality even further, right?

#

Why recompress that mp3 stream?

Posted by: Administrator on August 31, 2006 05:39 AM
In the<nobr> <wbr></nobr>.flv container the audio stream is usually mp3 already and is usually encoded with a low bitrate such as 96 or 64.

So why bloat it by recompressing it, when you can simply use MEncoder's stream copy:

<tt>-oac copy</tt>

Cheers,

SoRX

#

How to convert YouTube videos to DivX or XviD

Posted by: Anonymous [ip: 89.130.54.218] on August 20, 2007 05:09 PM
Hi there!
it didn't work with that options in nokias phones. I get an error with my s60 in smartmovie complaining about 'bad AVI'. It worked out with this script. In case someone find this useful:


#!/bin/sh
#mencoder -of avi -ovc xvid -xvidencopts bitrate=500:interlacing -afm ffmpeg -af resample=16000,channels=1 -oac mp3lame -lameopts cbr:br=64:mode=3 -noskip -vop scale=208:176 flv/tAsOfqCy4A0.flv -o prueba.avi

if [ -z "$1" ]; then
echo "Usage: $0 list_of_flv_files"
exit 1
fi

# video encoding bit rate
V_BITRATE=50
while [ "$1" ]; do
mencoder -of avi -ovc xvid -xvidencopts bitrate=$V_BITRATE:interlacing -afm ffmpeg -af resample=16000,channels=1 -oac mp3lame -lameopts cbr:br=64:mode=3 -noskip -vop scale=208:176 "$1" -o "`basename $1 .flv`.avi"
shift
done


Save it as flv2avi.sh and
$chmod 755 flv2avi.sh

#

How to convert YouTube videos to DivX or XviD

Posted by: Anonymous [ip: 76.200.101.205] on September 12, 2007 10:12 AM
I'm using this script as is provided on this page, and I'm getting some serious sync drift between audio and video. Are there options to correct for this ? When mencoder is doing it's business some skipped frame messages appear, by the way. This occurs even without seeking through the file.

#

Re: How to convert YouTube videos to DivX or XviD

Posted by: Anonymous [ip: 203.124.22.247] on November 13, 2007 07:29 AM
How to convert YouTube videos to DivX or XviD

#

How to convert YouTube videos to DivX or XviD

Posted by: Anonymous [ip: 72.229.185.237] on November 10, 2007 07:51 AM
Great article!
This is what I love about open source, with a little information and initiative
[Modified by: Anonymous on November 20, 2007 02:12 AM]

#

How to convert YouTube videos to DivX or XviD

Posted by: Anonymous [ip: 81.102.15.200] on November 22, 2007 12:42 PM
Have tried using the Mencoder script for conversion of Youtube vids, but unfortunately, despite having everything correctly installed, from ffmpeg to lame, and using a prebuilt version of Mencoder (note I have also tried this with a home compiled version of Mencoder as well), it causes Mencoder to do one of 2 things:

It either generates a file which has a file size of absolutely sod all, or
It causes Mencoder to Segfault (SIGSEGV / Signal 11).

I am running Mandriva 2007.0 on a custom system (i686/libc6)

Any more suggestions: Can't dl them straight from net as no access in home. Need to convert what I already have so I can watch them.

#

How to convert YouTube videos to DivX or XviD

Posted by: Anonymous [ip: 118.90.101.187] on December 11, 2007 01:59 AM
This is what happened when i tried to convert using the command flv2avi -divx <filename>.flv

MPlayer was compiled without libmp3lame support.
-lameopts is not an MEncoder option

Im a noob and i dont know what that means.

does anyone know?

#

How to convert YouTube videos to DivX or XviD

Posted by: Anonymous [ip: 65.28.7.68] on December 16, 2007 05:22 PM
MEncoder 1.0rc2-4.1.2 (C) 2000-2007 MPlayer Team
CPU: Intel(R) Pentium(R) 4 CPU 1300MHz (Family: 15, Model: 0, Stepping: 7)
CPUflags: Type: 15 MMX: 1 MMX2: 1 3DNow: 0 3DNow2: 0 SSE: 1 SSE2: 1
Compiled with runtime CPU detection.
success: format: 0 data: 0x0 - 0xceeb3b
libavformat file format detected.
[lavf] Video stream found, -vid 0
[lavf] Audio stream found, -aid 1
VIDEO: [FLV1] 320x240 0bpp 30.000 fps 0.0 kbps ( 0.0 kbyte/s)
[V] filefmt:44 fourcc:0x31564C46 size:320x240 fps:30.00 ftime:=0.0333

No video encoder (-ovc) selected. Select one (see -ovc help).

Exiting...

#

Re: How to convert YouTube videos to DivX or XviD

Posted by: Anonymous [ip: 65.28.7.68] on December 16, 2007 05:37 PM
duh, i forgot to use ./flv2avi.sh -divx *.flv

#

How to convert YouTube videos to DivX or XviD

Posted by: Anonymous [ip: 203.124.58.42] on December 19, 2007 09:50 AM
I need a php script that convert .mov, .avi, .dat, .mp3 video to flv format. Please help me.

Regards!
John
marketing@seomaterial.com
http://www.seomaterial.com

#

How to convert YouTube videos to DivX or XviD

Posted by: Anonymous [ip: 58.33.187.18] on March 05, 2008 07:54 AM
How to convert flv file to mobile phone, iPod,iPhone, Pocket PC, PSP, or Zune

YouTubeRobot.com today announces YouTube Robot 2.0, a tool that enables you to download video from YouTube.com onto your PC, convert flv files to various video formats to watch it when you are on the road on mobile devices like mobile phone, iPod, iPhone, Pocket PC, PSP, or Zune.

YouTube Robot allows you to search for videos using keywords or browse video by category, author, channel, language, tags, etc. When you find something noteworthy, you can preview the video right in YouTube Robot and then download it onto the hard disk drive. The speed, at which you will be downloading, is very high: up to 5 times faster than other software when you download a single file and up to 4 times faster when you download multiple files at a time.

Manual download is not the only option with YouTube Robot. You may as well schedule the download and conversion tasks to be executed automatically, even when you are not around. Downloading is followed by conversion to the format of your choice and uploading videos to a mobile device (if needed). For example, you can plug in iPod, select the video, go to bed, and when you wake up next morning, your iPod will be ready to play new YouTube videos.

Product page: http://www.youtuberobot.com
Direct download link: http://www.youtuberobot.com/download/utuberobot.exe
Company web-site: http://www.youtuberobot.com
E-mail: support@youtuberobot.com

#

This story has been archived. Comments can no longer be posted.



 
Tableless layout Validate XHTML 1.0 Strict Validate CSS Powered by Xaraya