Page 1 of 1

3pass encoding in x264 broken

Posted: Fri Aug 18, 2006 1:45 am
by kwark
Seen in 0.50 and in the 0.51 build 2390 under video options:
1st pass: .... :pass=1:turbo=2 -nosound -o NUL
2nd pass: ....:pass=2:turbo=2:bitrate=$(VideoBitrate) -nosound -o
NUL
3rd pass: ....:pass=3:bitrate=$(VideoBitrate) -nosound -o "$(DestFile)"

So there are 3 errors (IMHO):

1- bitrate missing in first pass
2- turbo option enabled in second pass
3- wrong pass option in second pass

The mencoder man for x264enc clearly mentions:

Code: Select all

The  first  pass  (pass=1)  collects statistics on the video and
writes them to a file.  You might want to deactivate  some  CPU-
hungry options, apart from the ones that are on by default.

In  two pass mode, the second pass (pass=2) reads the statistics
file and bases ratecontrol decisions on it.

In three pass mode, the second pass (pass=3, that is not a typo)
does  both: It first reads the statistics, then overwrites them.
You can use all encoding options,  except  very  CPU-hungry  options.

The  third  pass (pass=3) is the same as the second pass, except 
that it has the second pass' statistics to work from.   You  can use all encoding options, including CPU-hungry ones.

The  first pass may use either average bitrate or constant quantizer.  ABR is recommended, since it does not require guessing a quantizer.  Subsequent passes are ABR, and must specify bitrate.
If pass=2 NO new information will be written to the passlog, so in effect the 3rd pass has the same rate estimation information as the 3nd pass. So changing the pass=2 to pass=3 in the 2nd pass will provide this information to the 3rd pass.

Posted: Fri Aug 18, 2006 4:59 am
by kwark
A simple (untested) patch for this bug:

http://onsnetis.boldlygoingnowhere.org/ ... .patch.txt

Code: Select all

--- videoencoders.cpp.old  2006-08-03 21:06:48.000000000 +0200
+++ videoencoders.cpp   2006-08-17 20:51:36.758768945 +0200
@@ -389,16 +389,16 @@
         break;
      case 2:  // 2-pass
         cmds[0] = mecmd;
-        cmds[0].AppendFormat(":pass=1:turbo=%d", pref.GetValueStr(".turbo"));
+        cmds[0].AppendFormat(":pass=1:turbo=%d:bitrate=$(VideoBitrate)", pref.GetValueStr(".turbo"));
         cmds[1] = mecmd + ":bitrate=$(VideoBitrate):pass=2";
         pref.GenOptions(cmds[1], fullopts, ':');
         break;
      case 3:
-        cmds[0] = mecmd + ":pass=1:turbo=2";
+        cmds[0] = mecmd;
+        cmds[0].AppendFormat(":pass=1:turbo=%d:bitrate=$(VideoBitrate)", pref.GetValueStr(".turbo"));
         pref.GenOptions(mecmd, fullopts, ':');
-        cmds[1] = mecmd;
-        cmds[1].AppendFormat(":pass=2:turbo=%d:bitrate=$(VideoBitrate)", pref.GetValueInt(".turbo"));
-        cmds[2] = mecmd + ":pass=3:bitrate=$(VideoBitrate)";
+        cmds[1] = mecmd + ":pass=3:bitrate=$(VideoBitrate)";
+        cmds[2] = mecmd + ":pass=2:bitrate=$(VideoBitrate)";
         break;
      }
      } break;
@@ -464,13 +464,13 @@
         cmds[0] = mecmd + ":vbitrate=$(VideoBitrate)";
         break;
      case 2:
-        cmds[0] = mecmd + ":vpass=1:turbo";
+        cmds[0] = mecmd + ":vbitrate=$(VideoBitrate):vpass=1:turbo";
         cmds[1] = mecmd + ":vbitrate=$(VideoBitrate):vpass=2";
         break;
      case 3:
-        cmds[0] = mecmd + ":vpass=1:turbo";
-        cmds[1] = mecmd + ":vbitrate=$(VideoBitrate):vpass=2";
-        cmds[2] = mecmd + ":vbitrate=$(VideoBitrate):vpass=3";
+        cmds[0] = mecmd + ":vbitrate=$(VideoBitrate):vpass=1:turbo";
+        cmds[1] = mecmd + ":vbitrate=$(VideoBitrate):vpass=3";
+        cmds[2] = mecmd + ":vbitrate=$(VideoBitrate):vpass=2";
         break;
      }
      } break;
[/url]

Posted: Fri Aug 18, 2006 2:45 pm
by stanley
Thank you very much! I'll test it.
However, I think bitrate settting doesn't have any effect on 1st pass.

EDIT: I've applied it and commited to SVN. I will release an update soon.

Posted: Sat Aug 19, 2006 12:15 am
by kwark
For atleast x264 the first pass may contain the bitrate to make a more accurate guestimation of the compression quantitizer.

I can't imagine that it will decrease quality, most likely it will improve it (time to do some extensive testing myself)

Posted: Sat Aug 19, 2006 1:32 am
by stanley
Here is the update.

Posted: Sat Aug 19, 2006 12:18 pm
by yoshaw
Before updating to 5.1 latest I could encode HD WMV's to PSP's PMPAVC format. Now that I have the latest and greatest. It slows to a crawl and not bother encoding a single frame.

So I uninstall this new thing and try going back to 5.0r1 with updated to 2338 which was my intial version before updating to 5.1 and encoding HD vids fine.

I'm quite upset over losing this feature with the newest version. WHich incidentally also crippled something, I don't know where, rendering old versions just as useless.

Used to encode vids perfectly just an hour ago and now nothing seems to be working. I tried the mencoder 1.0pre8 too , didn't work. Stanley Please help!

Posted: Sat Aug 19, 2006 12:21 pm
by stanley
Please first confirm this happens even using the same versions of MEncoder (by substituting mencoder.exe and try).