3pass encoding in x264 broken

Bug report and feature request
Post Reply
kwark
Beginner
Beginner
Posts: 3
Joined: Fri Aug 18, 2006 1:28 am

3pass encoding in x264 broken

Post by kwark » Fri Aug 18, 2006 1:45 am

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.

kwark
Beginner
Beginner
Posts: 3
Joined: Fri Aug 18, 2006 1:28 am

Post by kwark » Fri Aug 18, 2006 4:59 am

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]

stanley
Site Admin
Site Admin
Posts: 4130
Joined: Mon May 15, 2006 7:43 pm
Location: Sydney

Post by stanley » Fri Aug 18, 2006 2:45 pm

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.
When things work together, things work.

kwark
Beginner
Beginner
Posts: 3
Joined: Fri Aug 18, 2006 1:28 am

Post by kwark » Sat Aug 19, 2006 12:15 am

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)

stanley
Site Admin
Site Admin
Posts: 4130
Joined: Mon May 15, 2006 7:43 pm
Location: Sydney

Post by stanley » Sat Aug 19, 2006 1:32 am

Here is the update.
When things work together, things work.

yoshaw
Amateur
Amateur
Posts: 10
Joined: Sat Jul 22, 2006 6:08 pm

Post by yoshaw » Sat Aug 19, 2006 12:18 pm

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!

stanley
Site Admin
Site Admin
Posts: 4130
Joined: Mon May 15, 2006 7:43 pm
Location: Sydney

Post by stanley » Sat Aug 19, 2006 12:21 pm

Please first confirm this happens even using the same versions of MEncoder (by substituting mencoder.exe and try).
When things work together, things work.

Post Reply