How to convert a video to make it work on your old DivX device using the excellent cross-platform tool ffmpeg.
DivX Profiles
There are different classes of DivX support, called “profiles”. Your DivX compliant device normally belongs to one of these profiles. Check them out:
and
If your device (TV, maybe?) happens to be many years old, chances are that it’s a DivX Home Theater. This means that it:
- supports only to MPEG-4 part 2 codec (AKA DivX or Xvid). It doesn’t support H.264 or H.265.
- has a maximum resolution of 720×480 (@30 fps) or 720×576 (@25 fps).
So, lots of downloadable videos won’t run on your device out of the box. That’s where ffmpeg comes into play.
Conversion
ffmpeg -i <input file> -vf scale=720:480:decrease -c:v mpeg4 -vtag xvid -qscale:v 5 -c:a libmp3lame -qscale:a 5 <output file>
This should create a new video compatible with your device. Lets take a look at the options,
-i <input file>
A source file (there could be multiple of them, ffmpeg is pretty powerful). DON’T include the <
and >
characters, they are used in this article as mere placeholders.
-vf scale=720:480:decrease
Video filter of type scale
. It scales to 720x480
, and if the original aspect ratio is different, it forces keeping the aspect ratio by decreasing
the dimensions until they fit in the 720×480 box.
-c:v mpeg4
Sets the encoder of the video to mpeg4
.
-vtag xvid
Sets the video tag to xvid
. This is necessary to allow some video players to identify the format correctly.
-qscale:v 5
Quality scale (?). Its meaning differs depending on the encoder used. In this case, it’s roughly equivalent to Quantization Parameter in x264 (an open source H.264 encoder). It ranges from 1 to 31 with 1 being the highest quality and largest file size.
-c:a libmp3lame
Sets the encoder of the audio to libmp3lame
(to produce mp3 audio).
-qscale:a 5
Quality scale, but for audio this time.
<output file>
The name of the output file.
This should satisfy your needs. I usually use this line without modification (only substitute the file names) and get very acceptable results. However, there are a number of other ways to do it.
Other Methods
ffmpeg -i <input file> -vf scale=720:480:decrease -c:v libxvid -qscale:v 5 -c:a libmp3lame -qscale:a 5 <output file>
It’s the same command, but:
- we used another encoder –
libxvid
– instead ofmpeg4
. This is much slower than the nativempeg4
encoder, but should produce better results at lower bit-rates per quality (for example, 1Mbit/s for 720p). - we removed the explicitly specified
xvid
tag. It was required only when using thempeg4
encoder, because it’s default tag isFMP4
, which gets rejected by lots of players.
You can also scratch ffmpeg
altogether and use mencoder
:
mencoder -mc 0 -noskip -vf expand=:::::16/9,scale=720:480,hqdn3d,harddup -ovc xvid -oac mp3lame -xvidencopts fixed_quant=3.8:me_quality=6:noqpel:nogmc:trellis:chroma_me:chroma_opt:hq_ac:vhq=4:lumi_mask:max_key_interval=300:quant_type=mpeg:max_bframes=2:closed_gop:nopacked:profile=asp5:autoaspect:bvhq=1 -lameopts vbr=2:q=6:aq=2 -o <output file> <input file>
I’ve copied this line from somewhere :D. This provides good quality (maybe a little better?) but is very slow. I decided to stick to ffmpeg
instead.
More ffmpeg Options
If you have different tracks, you can manually select the ones you want to end up in your output file using the map
option:
ffmpeg -i <input file> \ -vf scale=720:480:decrease \ -map 0:0 -map 0:1 \ -c:v mpeg4 -vtag xvid -qscale:v 5 \ -c:a libmp3lame -qscale:a 5 \ <output file>
Yes, you can split your command using the \
escape character. Beware though, having any whitespaces after the \
will turn it into a regular escape-sequence instead of line-continuation. Anyway, this has nothing to do with ffmpeg, it’s a shell thing.
Notice the map
options,
-map 0:0 -map 0:1
Without specifying mapping options, the default behavior is to discover the “highest quality” single video input stream and “highest quality” single audio input stream from all inputs, and “send” them to the output. All other input streams are discarded. Here, we explicitly select the streams 0
and 1
from the input file 0
. We can choose to have more streams by adding more map
options. We can even choose different options for each of these streams, but that’s enough for today already!
To get information about the streams present in a file, use:
ffmpeg -i <input file>
This should print out some nice information about the version of ffmpeg you are using and the streams present within the file.
Thanks for reading. I’ll probably be posting more about the fantastic ffmpeg library later, so stay tuned! Till then:
- make sure to check out its inspiring original author Fabrice Bellard.
- you may want to read the story of DivX and how it all started when a French hacker (Jerome Rota) decided to reverse-engineer a codec instead of re-encoding his video portfolio and resume!