Log in

View Full Version : Problem with ffmpeg 2-pass mode


MaeWanto
16th March 2005, 08:14
I'm getting a rate control issue when I'm using ffmpeg to encode in 2-pass with XviD : the resulting bitrate is far higher than the target I'm indicating.
Here are the 2 command lines I'm using :

ffmpeg -i input_file.avi -vcodec xvid -b 1000 -g 125 -vtag xvid -pass 1 -passlogfile log_file output_file.avi

ffmpeg -i input_file.avi -vcodec xvid -b 1000 -g 125 -vtag xvid -pass 2 -passlogfile log_file output_file.avi

The log file is well produced and seems to be valid, but the resulting "output_file.avi" has an average bitrate of 3655 kbps !!??

When I try the same process with mpeg4 codec ( just replacing "-vcodec xvid" by "-vcodec mpeg4" ), the encoded file then has an average bitrate of 1005 kbps as expected.

BTW, when I'm encoding in 1 pass only with Xvid, I don't have this rate control issue anymore. The following command line produces a resulting file with an average bitrate of 1018 kbps :

ffmpeg -i input_file.avi -vcodec xvid -b 1000 -g 125 -vtag xvid output_file.avi

Would somebody know how to solve this rate control issue in 2-pass mode with XviD ?

jon.schaffer
16th March 2005, 09:51
Hi,

this issue have been discussed a lot here. so... use search ("oversized") and you'll learnt much.

MaeWanto
17th March 2005, 08:01
Ok, thanks a lot for your help, I'll search in the forum with the keyword you gave.

MaeWanto
17th March 2005, 20:03
I've read in the forum about the quant 2-31 issue and I tried to set qmin to 1 in the command line, but it didn't helped :

ffmpeg -i input_file.avi -vcodec xvid -b 1000 -g 125 -qmin 1 -qmax 31 -pass 1 -passlogfile log_file output_file.avi

ffmpeg -i input_file.avi -vcodec xvid -b 1000 -g 125 -qmin 1 -qmax 31 -pass 2 -passlogfile log_file output_file.avi

So, I'm still looking for a solution ( with a command line example if possible ... ). Thanks in advance.

jon.schaffer
17th March 2005, 21:50
It's the opposite: you must set 2 as min value for each frame type, since it's the use of quantizer-1-frames that disturbs the codec.

But be aware that you'll get an undersized file. It's normal. It's because THIS movie is very compressible.

So, you can take advantage of this situation by improving the image or sound quality... (eg: bigger frame size, use custom matrices that retain more details, compress less the audio).
But, remember: this "too small" file will be already at maximum quality...

MaeWanto
18th March 2005, 07:54
Hi,

I've tried several values for qmin, but the resulting files are approximately the same size ( 3 times bigger than the target size ... ). BTW, I don't think this particular movie is very compressible, it's a 384 x288 CSI trailer ( with a lot of cuts and movement ) I generally use to test codecs' performance ...

jon.schaffer
18th March 2005, 21:50
Could you open the 1st pass log file with XviD statReader (in the XviD package) and tell us the First Pass Size ("Size (MB)")?

EDIT: I just realize that, knowing nothing about FFMPEG, I don't know if setting -qmin=2 involve a minimum quantizer of 2 for every frame type.
So? ... So, we have to wait for an FFMPEG expert here.

oystercatcher
19th March 2005, 00:09
When I saw this thread and saw that ffmpeg could be used to encode with xvid via a command line, I was very interested. It took some work but I finally got most everything compiled using mingw/msys and these sources
nasm, lame, xvid latest snapshot, and FFMpeg lastest snapshot.
in case anyone decides to try this there is a fix required in ffmpeg
in libavcodec/xvidff.c and is documented here
http://soenkerohde.com/tutorials/ffmpeg/

My question is about the output file having the same name on both the pass1 and pass2 command lines. Additionally the input file is the same on both passes. Is the logfile the intermediate file?

Thanks for starting this thread, I prefer command line also.

MaeWanto
19th March 2005, 10:49
@jon.schaffer: I've attached the log file ( I just added .txt extension in order to be able to send it through the forum, because my first attempt failed ... ). I prefer letting an XviD expert examine it, because I've never used XviD statReader before.

@oystercatcher: Would you get a Windows build of this fixed ffmpeg version in order for me to try it with the same input file and command lines.
I don't think you have to set the same output file names for both passes, but I'm pretty sure you have to do it for input and log file names.

BTW, I tried to encode the same input file with the same command lines on a Linux version of ffmpeg and it worked perfectly ... So, the problem comes maybe from the Windows build I'm using ( http://www.aziendeassociate.it/./cd//ffmpeg/ffmpeg.2005.03.11.7z ), but I didn't find a good one so far ...

jon.schaffer
19th March 2005, 13:50
Originally posted by MaeWanto
I prefer letting an XviD expert examine it, because I've never used XviD statReader before.
Ooh... no need to be a real expert :D
It just requires an "official" XviD binaries package. This installs the StatReader, a program which allow to know the first pass size (ie: the size of the movie when encoded at quantizer 2, which is the reference in the 2-pass encoding routine)

I did never use the attachement. Must we wait for a moderator validation before see it appear somewhere in the post?
Well... waiting :)

oystercatcher
19th March 2005, 15:49
Greetings Mae Wanto,

I checked my system and ffmpeg.exe is
3 134 464 bytes. To actually use the exe
I had to copy xvidcore.dll from the xvid
build into the same folder as ffmpeg or it
could have gone into %windir%\system32

Re: sending out the exe, not sure you
would have much luck with it as it is
my first attempt at ffmpeg. It is
encoding with xvid. Bit rate seemingly
having the greatest affect on the size of
the output file. I am barely familiar
with xvid, which is one of the reasons I
wanted to try commandline so I could easily
document any changes. I used nasm in the
build of lame, possible also xvid. I dont
know whether the build is specific to my
system or not. In any case if you like
I could attach ffmpeg.exe to an email.

MaeWanto
19th March 2005, 20:07
I don't see the attachement appearing if my previous mail, so here is a link where you'll be able to get the log file :
http://perso.wanadoo.fr/maewanto/ffmpeg2pass-0.log

jon.schaffer
20th March 2005, 01:00
I looked at the log file.
StatReader says:

1) number of frames: 582
So (I suppose your clip has 25 fps), it is 23 sec long.

2) First pass size: 13 MB
So 13 MB for 23 sec -> bitrate of first pass = about 4500 kbps !!!

Since you aim a lower bitrate, I do not understand the issue here. This seems not to be the "higly compressable" movie problem...
For the second time, I must give up... Sorry:confused:

MaeWanto
20th March 2005, 09:55
At the moment, I guess the issue comes from the XviD implementation in the ffmpeg builds for Windows I've used so far, but I'm not sure. I can't find an ffmpeg expert who could tell me clearly where the problem comes from ( I've tried the ffmpeg user mailing-list without any feedback ... ) :-(