View Full Version : Xvid encoding with ffmpeg
drunken_clam
11th January 2008, 18:31
Hi everybody,
i'm using ffmpeg for encoding video with xvid. My problem is that i can't get out which options from ffmpeg i can use for xvid, because in the documentation the options are mostly not codec related.
So perhaps i can find any experienced ffmpeg+xvid users here who can tell me some good options for xvid encoding. My current commandline looks like this:
ffmpeg -y -i IN.avi -aspect 4:3 -vcodec libxvid -s 640x480 -r 25 -b 1000k -flags +trell -g 250 -me_method epzs -qmin 2 -qmax 15 -acodec libmp3lame -ac 2 -ar 44100 -ab 80k -benchmark OUT.avi
Can somebody tell me what the option "-coder XX" do?
Is the "flag +aic" an option which is supported by standalone players?
Things if already tried are "gmc, qpel,4mv"...
20-40
17th January 2008, 11:14
Try for example (change in/out files):
ffmpeg -i "sara.mpg" -vcodec libxvid -trell -max_bframes=2 -s 576x432 -b 800k -r 23.976 -acodec libmp3lame -ac 2 -ar 48000 -ab 128k -y -f avi my_dog.avi
for single pass.
For two pass encoding try for example
ffmpeg -i "sara.mpg" -vcodec libxvid -trell -max_bframes=2 -s 576x432 -b 800k -r 23.976 -acodec libmp3lame -ac 2 -ar 48000 -ab 128k -y -pass1 "xvid.stats" -f avi my_dog.avi
ffmpeg -i "sara.mpg" -vcodec libxvid -trell -max_bframes=2 -s 576x432 -b 800k -r 23.976 -acodec libmp3lame -ac 2 -ar 48000 -ab 128k -y -pass2 "xvid.stats" -f avi my_dog.avi
Ffmpeg prefer libavcodec, and for xvid is better to use mencoder, avisynth/encraw_xvid or avisynth/avs2avi for much faster and better results.
FYI, qpel (and GMC partially) is incompatible with almost all standalone players.
ffmpeg -h > ffmpeg_help.txt will dump help into file
ffmpeg -formats help > formats.txt will dump info on formats into file, etc…
Ffmpeg is constanly developed, so - ALL options vary from one revision/version to another.
For instance, above examples works for ffmpeg.exe I've compiled for myself:
FFmpeg version SVN-r10822, Copyright (c) 2000-2007 Fabrice Bellard, et al.
configuration: --prefix=/mingw --enable-static --disable-shared --
enable-pp --enable-swscaler --enable-libmp3lame --enable-libfaac --e
nable-libfaad --enable-libx264 --enable-libxvid --enable-libogg --en
able-libvorbis --enable-liba52 --enable-gpl --enable-libamr-nb --ena
ble-libamr-wb --enable-avisynth --extra-cflags=-g0 -O2 -D_GNU_SOURCE
-ffast-math --enable-memalign-hack --disable-debug --enable-w32thre
ads --extra-libs=-lwinmm -lavisynth --arch=prescott --cpu=prescott -
-extra-ldflags=-static
libavutil version: 49.5.0
libavcodec version: 51.46.0
libavformat version: 51.16.0
built on Oct 23 2007 23:57:14, gcc: 4.3.0 20070831CYBORG (experimental) (by_20-40)
In any case, happy encoding.
LigH
28th August 2010, 00:29
I have a similar issue ... http://ffmpeg.arrozcru.org/autobuilds/ offers a quite versatile and current build; unfortunately there are so many options that I am hardly able to filter which of them are relevant for Xvid encoding with ffmpeg at all.
Let's imagine I'd like to encode "anything" to MP4 with Xvid MPEG4-ASP video and LAME MP3 audio because that's quite the best size/quality ratio my mobile media player supports. To get rather optimal results, I'd try to have the video encoded with fixed quantizer (because Xvid does not really support a good "constant quality" algorithm like x264's CRF ... yet?) and the audio with a constant quality as offered by LAME's VBR mode. Which command line options of ffmpeg can I use / should I use for rather optimal results?
It seems to me that ffmpeg does not support codec specific options (like "-xvidencopts" in mencoder) but offers a lot of generic options instead, which may be supported by a specific codec or not. So e.g. there is the command line option "-trellis #", and because Xvid supports trellis quantization, encoding to MPEG4-ASP using libxvid probably uses Trellis if I add this option -- but which (integer) parameter for this option would make sense? In case of Xvid possibly 0 and 1; in case of x264 possibly 0, 1 and 2. And in case of a constant quantization possibly not at all.
There are just too many options and provided by ffmpeg (with too briefly documented value ranges), I am losing track of which have any relation to Xvid at all, and which range of values is useful in case of Xvid as video encoder. The same applies to LAME as MP3 encoder - although I try to use parameters which should create a quality based VBR MP3 audio stream, I am not certain if the result is as desired until I demultiplex the result and check it (and may the reason just be that ffmpeg writes a constant bitrate into its console output).
So - which options would you recommend to get a quality based but small sized VBR result for a mobile media player (like a cell phone) in addition to my first try?
ffmpeg.exe -y -i %1 -vcodec libxvid -bf 1 -qscale 4 -s 320x240 -acodec libmp3lame -aq 2 -ar 22050 -ac 2 -f mp4 "%~n1.mp4"
LigH
28th August 2010, 21:29
I found a solution: There are ffmpeg GUIs (like FFCoder) which know more about command line options than me. They helped me building useful parameter sets.
So I found that B frames can confuse players and make MediaInfo report movies as "variable frame rate" even though they have constant frame rates. Probably only with certain containers (MP4, 3GPP) written by ffmpeg.
Interesting that the latest ffmpeg builds contain an AAC encoder too. I thought the author of FAAC got nearly sued if he didn't stop his project ... even if the LAVC AAC encoder has low quality and needs to be enabled with "-strict experimental" -- be careful with license lawyers. ;)
henryho_hk
9th September 2010, 11:51
mencoder's muxer has bugs producing mpeg4 asp or avc with b-frames. I'm not sure if it applies to ffmpeg too.
MOS-Marauder
12th September 2010, 03:41
mencoder's muxer has bugs producing mpeg4 asp or avc with b-frames. I'm not sure if it applies to ffmpeg too.
Yep it does... I wanted to usse mencoder or ffmpeg to cut samples out of a video...with mencoder it makes out of a 1bframe encoded vid an 2bframes one...
If i use ffmpeg to cut it does the same but u can add "-bf 1" or howmany bframes u want......BUT it crashes my vbr mp3 and writes CBR in the header witch leads to play errors.
Suggestions?
Chris
GMJCZP
2nd November 2010, 15:32
Yep it does... I wanted to usse mencoder or ffmpeg to cut samples out of a video...with mencoder it makes out of a 1bframe encoded vid an 2bframes one...
If i use ffmpeg to cut it does the same but u can add "-bf 1" or howmany bframes u want......BUT it crashes my vbr mp3 and writes CBR in the header witch leads to play errors.
Suggestions?
Chris
If you use VBR MP3 in an avi you will have problems. It is better to use MP3 CBR, in fact, VirtualDubMod recommended to save the audio to WAV and then encode to MP3 CBR. Greetings.
LigH
2nd November 2010, 16:36
No panic. VBR audio is no problem for the AVI container. Alexander Noé proved it. AviMux-GUI and Avidemux can handle it. Even VirtualDubMod only warns if you don't disable the warning - a relic from Avery Lee's original VirtualDub.
GMJCZP
5th November 2010, 04:51
The subject matter is to be cut a video with audio variable, a way to avoid trouble would pass the audio to CBR. Once I had problems joining two pieces of a avi with VBR audio, Not only the audio was not synchronized but also part of the sound at the beginning of the second piece was cut. I took to get a WAV and synchronized. In short, this proposal is just one solution, so that there may be others. :D
raymng
23rd February 2012, 19:06
Hi everybody,
i'm using ffmpeg for encoding video with xvid. My problem is that i can't get out which options from ffmpeg i can use for xvid, because in the documentation the options are mostly not codec related.
So perhaps i can find any experienced ffmpeg+xvid users here who can tell me some good options for xvid encoding. My current commandline looks like this:
ffmpeg -y -i IN.avi -aspect 4:3 -vcodec libxvid -s 640x480 -r 25 -b 1000k -flags +trell -g 250 -me_method epzs -qmin 2 -qmax 15 -acodec libmp3lame -ac 2 -ar 44100 -ab 80k -benchmark OUT.avi
Can somebody tell me what the option "-coder XX" do?
Is the "flag +aic" an option which is supported by standalone players?
Things if already tried are "gmc, qpel,4mv"...
I have exactly the same question.
Where can I check the available options for libxvid on FFmpeg?
Thanks.
JeanMarc
9th March 2012, 04:19
I am also using ffmpeg a lot for encoding xvid (except when I have a 5.1 channel audio that I want to keep, in which case I have to use virtualdub).
I have been using 'libxvid' most of the time, and 'mpeg4' when I wanted to use b-frames -- I haven't been able to get a good result with b-frames and libxvid, for whatever reason.
Here is a good site that offers a useful discussion of a number of xvid options for ffmpeg: http://helpful.knobs-dials.com/index.php/Notes_on_encoding_video#for%20divx/xvid.
Naturally, the complete list that you get when you do 'ffmpeg -h' is not self-explanatory, but is helpful to verify syntax and spelling. Some commands have evolved with newer versions of ffmpeg, and the console gives all the information pertaining to your version of ffmpeg.
There is also the Unofficial XVID FAQ: http://kaitsuburi.tripod.com/crusty_xvid_faq_v20040406.pdf (http://kaitsuburi.tripod.com/crusty_xvid_faq_v20040406.pdf), somewhat dated, but Xvid is not that new. It doesn't provide the ffmpeg commands, but, with a little guesswork, it is almost always possible to find out what is the command corresponding to the feature described.
Hope that helps.
smok3
9th March 2012, 09:05
and the console gives all the information pertaining to your version of ffmpeg
an example of all the information?
say i'd like to convert "vpxenc -v --rt -p 2 --pass=1 --bias-pct=100 --fpf="$tmp.log" --threads=8 --target-bitrate=55000 --end-usage=cq --cq-level=20 --kf-min-dist=0 --kf-max-dist=100 --auto-alt-ref=1 --lag-in-frames=16 --drop-frame=0 --min-q=0 --max-q=60" to ffmpeg with some slightish guesswork?
JeanMarc
9th March 2012, 14:24
and the console gives all the information pertaining to your version of ffmpeg
Allright, 'all' the information is overstated, although I did mention it was not self-explanatory. May be the right phrase should have been: 'a list of the commands accepted by your version of ffmpeg'.
Now, my post was intended to help people like raymng understand the XVID options when encoding with ffmpeg.
I wouldn't say anything about translating a webm command into ffmpeg, especially since I have never used vpxenc. Do you imply that ffmpeg can do the same encoding as your vpxenc command ?
smok3
9th March 2012, 14:26
well it should, since it is compiled with the same version of libvpx..., but i'am not really implying anything.
unknownsoldierX
16th May 2012, 05:31
I've just started trying to use ffmpeg (via MCEBuddy). Is there a way to set a target size for the final AVI? I'm used to using MeGUI, which automatically does it for you. I'd like to use MCEBuddy to automate my encoding, but I need to my files to be a set size. Can ffmpeg do this while taking the audio size into account, so I can get a final product that is, for example 700MB?
Gew
14th January 2013, 17:44
Guys, I think that the "default" preset in xvidcore.dll (or xvidvfw.dll, for that matter) is pretty darn okey, just to fulfill in produce a descent video with desired bitrate/quantizer, which is still playble with most stand-alones.
However, running an ffmpeg encode with '-c:v libxvid' and switch(es) '-q:v' or '-b:v' does indeed produce an output with desired bitrate or quantizer, but it seems to disregard some of the settings from the "default" preset from the XviD library. For instance, it disables all B-frames, so I need to add '-bf 2' to make it fit my bill. Also, trellis is checked, and I'm not sure if it should be '-trellis 1' or '-trellis 2' to make the encode fit what Xvid library would have done per default. Also, in some ffmpeg command line examples I've seen even more switches being add, like '-subcmp' for instance. I'm not even sure what this does, or if the default (when not specified) encode from ffmpeg differs from how Xvid would do.
Hey, here comes the short [TLDR] version.
Could anyone who's skilled about this video stuff write a xvid_defaults.preset and upload it someplace, with settings that would match the actual Xvid encoding library in every aspect? Would be awesome.
Cheers!
cord-factor
10th April 2013, 11:34
Hi all,
I have just tried to encode video with libxvid (using ffmpeg)... So, comparing to embedded ffmpeg's 'mpeg4' codec the quality has been significantly decreased.
LigH
10th April 2013, 13:40
Bold statement without proof; at least both your CLI parameters would be interesting, just to see if their purpose is comparable.
mousemurder
10th April 2013, 16:05
have you thought about looking into xvidenc ?; although it is based on mencoder instead of ffmpeg.
cord-factor
10th April 2013, 16:56
Bold statement without proof; at least both your CLI parameters would be interesting, just to see if their purpose is comparable.
$ ffmpeg -i input.avi -an -c:v libxvid -qscale 1.4 out.avi
$ ffmpeg -i input.avi -an -c:v mpeg4 -qscale 1.4 out.avi
have you thought about looking into xvidenc ?; although it is based on mencoder instead of ffmpeg.This topic is about ffmpeg and it doesn't recognize 'xvidenc' option.
LigH
11th April 2013, 08:00
Please use -q:a or -q:v, -qscale is ambiguous
So I tried the following, exchanging -qscale with -q:v, and converting the Sintel trailer in FullHD (from a HQ conversion as AVC with CRF 6, because ImageSource with PNGs is too slow to be useful):
ffmpeg -i sintel_trailer_1080_crf06.mkv -an -c:v libxvid -q:v 1.4 sintel_trailer_1080_libxvid.avi
ffmpeg version N-51683-g9dc88ac Copyright (c) 2000-2013 the FFmpeg developers
built on Apr 8 2013 21:19:21 with gcc 4.8.0 (GCC)
configuration: (omitted for readability)
libavutil 52. 25.100 / 52. 25.100
libavcodec 55. 2.100 / 55. 2.100
libavformat 55. 1.100 / 55. 1.100
libavdevice 55. 0.100 / 55. 0.100
libavfilter 3. 49.101 / 3. 49.101
libswscale 2. 2.100 / 2. 2.100
libswresample 0. 17.102 / 0. 17.102
libpostproc 52. 2.100 / 52. 2.100
Input #0, matroska,webm, from 'sintel_trailer_1080_crf06.mkv':
Metadata:
creation_time : 2010-12-04 21:57:38
Duration: 00:00:52.21, start: 0.000000, bitrate: 26971 kb/s
Stream #0:0: Video: h264 (High), yuv420p, 1920x1080, SAR 1:1 DAR 16:9, 24 fps, 24 tbr, 1k tbn, 48 tbc (default)
Stream #0:1: Audio: flac, 48000 Hz, stereo, s16 (default)
Output #0, avi, to 'sintel_trailer_1080_libxvid.avi':
Metadata:
ISFT : Lavf55.1.100
Stream #0:0: Video: mpeg4 (xvid / 0x64697678), yuv420p, 1920x1080 [SAR 1:1 DAR 16:9], q=2-31, 200 kb/s, 24 tbn, 24 tbc (default)
Stream mapping:
Stream #0:0 -> #0:0 (h264 -> libxvid)
Press [q] to stop, [?] for help
frame= 1253 fps=5.7 q=1.0 Lsize= 154345kB time=00:00:52.20 bitrate=24218.3kbits/s
video:154310kB audio:0kB subtitle:0 global headers:0kB muxing overhead 0.023093%
ffmpeg -i sintel_trailer_1080_crf06.mkv -an -c:v mpeg4 -q:v 1.4 sintel_trailer_1080_mpeg4.avi
ffmpeg version N-51683-g9dc88ac Copyright (c) 2000-2013 the FFmpeg developers
built on Apr 8 2013 21:19:21 with gcc 4.8.0 (GCC)
configuration: (omitted for readability)
libavutil 52. 25.100 / 52. 25.100
libavcodec 55. 2.100 / 55. 2.100
libavformat 55. 1.100 / 55. 1.100
libavdevice 55. 0.100 / 55. 0.100
libavfilter 3. 49.101 / 3. 49.101
libswscale 2. 2.100 / 2. 2.100
libswresample 0. 17.102 / 0. 17.102
libpostproc 52. 2.100 / 52. 2.100
Input #0, matroska,webm, from 'sintel_trailer_1080_crf06.mkv':
Metadata:
creation_time : 2010-12-04 21:57:38
Duration: 00:00:52.21, start: 0.000000, bitrate: 26971 kb/s
Stream #0:0: Video: h264 (High), yuv420p, 1920x1080, SAR 1:1 DAR 16:9, 24 fps, 24 tbr, 1k tbn, 48 tbc (default)
Stream #0:1: Audio: flac, 48000 Hz, stereo, s16 (default)
Output #0, avi, to 'sintel_trailer_1080_mpeg4.avi':
Metadata:
ISFT : Lavf55.1.100
Stream #0:0: Video: mpeg4 (FMP4 / 0x34504D46), yuv420p, 1920x1080 [SAR 1:1 DAR 16:9], q=2-31, 200 kb/s, 24 tbn, 24 tbc (default)
Stream mapping:
Stream #0:0 -> #0:0 (h264 -> mpeg4)
Press [q] to stop, [?] for help
frame= 1253 fps= 58 q=1.4 Lsize= 49078kB time=00:00:52.20 bitrate=7700.9kbits/s
video:49043kB audio:0kB subtitle:0 global headers:0kB muxing overhead 0.072788%
What a difference.
Xvid: encoding speed = 5.7 fps, resulting bitrate = 24.2 Mbps
MPEG4: encoding speed = 58 fps, resulting bitrate = 7.7 Mbps
So which results do you expect from comparing apples with oranges?
cord-factor
11th April 2013, 14:54
>>> What a difference.
I my case the bitrate was approximately same (both codecs). So, default settings seems to be different (your and mine). How to change them in ffmpeg?
LigH
12th April 2013, 07:18
I believe that your chosen quality/bitrate parameter is not used in the same way by both codecs. -q[scale] is a "fixed quality scale", but the different codecs may interpret it differently. Xvid does not have something similar to CRF in x264, because MPEG4-ASP and MPEG4-AVC differ a lot in interna.
To compare two codecs, I was repetitively told that you must use an encoding mode which creates the same bitrate as good as it gets, and preferably options with the same purpose. Comparing "default for codec A" with "default for codec B" appears to be quite meaningless, already due to very different defaults.
If you wanted to change the defaults, you would probably have to edit the source before compiling your personal binaries.
cord-factor
12th April 2013, 15:12
All right, defaults are not critical. But there's another point.
I observed, that using libxvid makes scanty info.
For example, this command:
ffmpeg -y -i video.avi -an -q:v 3 -t 20 mpeg4.avi
makes video with characteristics (MediaInfo):
General
Complete name : mpeg4.avi
Format : AVI
Format/Info : Audio Video Interleave
File size : 2.24 MiB
Duration : 20s 20ms
Overall bit rate : 940 Kbps
Writing application : Lavf53.32.100
Video
ID : 0
Format : MPEG-4 Visual
Format profile : Simple@L1
Format settings, BVOP : No
Format settings, QPel : No
Format settings, GMC : No warppoints
Format settings, Matrix : Default (H.263)
Codec ID : FMP4
Duration : 20s 20ms
Bit rate : 933 Kbps
Width : 720 pixels
Height : 384 pixels
Display aspect ratio : 1.85:1
Frame rate : 23.976 fps
Color space : YUV
Chroma subsampling : 4:2:0
Bit depth : 8 bits
Scan type : Progressive
Compression mode : Lossy
Bits/(Pixel*Frame) : 0.141
Stream size : 2.23 MiB (99%)
Writing library : Lavc53.61.100
That's ok.
And the one below
ffmpeg -y -i video.avi -an -c:v libxvid -qscale 3 -t 20 xvid.avi
makes appropriate:
General
Complete name : xvid.avi
Format : AVI
Format/Info : Audio Video Interleave
File size : 2.51 MiB
Duration : 20s 20ms
Overall bit rate : 1 052 Kbps
Writing application : Lavf53.32.100
Video
ID : 0
Format : xvid
Codec ID : xvid
Duration : 20s 20ms
Bit rate : 1 045 Kbps
Width : 720 pixels
Height : 384 pixels
Display aspect ratio : 1.85:1
Frame rate : 23.976 fps
Bits/(Pixel*Frame) : 0.158
Stream size : 2.49 MiB (99%)
The same is when using '-vtag xvid' option with default mpeg4 codec.
I want to understand why there's so little information in these ('xvid') cases.
LoRd_MuldeR
14th April 2013, 22:15
$ ffmpeg -i input.avi -an -c:v libxvid -qscale 1.4 out.avi
$ ffmpeg -i input.avi -an -c:v mpeg4 -qscale 1.4 out.avi
You are encoding with constant quantizer.
This is not a "constant quality" mode, as you might think. It's only the closest to a "constant quality" mode that Xvid has, due to the lack of an equivalent to CRF mode (which still wouldn't be a "constant quality" mode, but MUCH closer to that).
Anyway, did the two files, the one encoded with "libxvid" and the one encoded with "mpeg4" even come out at the same file size? If not, any quality comparison between those files obviously doesn't make much sense.
So, what you should be doing is using 2-Pass encoding mode. And with the same target bitrate for both encoders. Then you will get two files of identical size (same average bitrate). And only then you can compare the quality of these files...
cord-factor
20th April 2013, 18:47
The same is when using '-vtag xvid' option with default mpeg4 codec.
I want to understand why there's so little information in these ('xvid') cases.
So, I asked myself, I'll answer :)
The option must be '-vtag XVID' (yes, uppercased) to have the detailed info in file.
How to disable libxvid's 'Packed Bitstream' option, which is enabled by default when using B-frames?
cord-factor
29th July 2013, 21:38
How to disable libxvid's 'Packed Bitstream' option, which is enabled by default when using B-frames?
I still don't know how, but I found another way - UnpackMP4 (http://www.xmixdrix.com/tools/unpackmp4.html). Maybe it will help to someone.
Best Regards.
vBulletin® v3.8.11, Copyright ©2000-2026, vBulletin Solutions Inc.