Log in

View Full Version : REAL Ultimate Guide to x264 and QuickTime!!!


Pages : [1] 2 3

Randall
11th November 2005, 01:16
Here is a guide I have compiled for a successful encodes of x264 that will work on QuickTime 7. A lot of people on these boards don't (and shouldn't if they don't need to) care about QuickTime functionality for their H.264/AVC encodes. But if you do care, here is a detailed step-by-step guide for a successful H.264 encode for QT. This guide is for Windows, but the x264 command lines can be used with Mac OS X just as well.

Before we get started, you should know that QuickTime is fussy when it comes to x264 playback. First of all QT doesn't support anything above Main Profile, meaning that it's built in decoder WILL support multipass, max 2 B-Frames, B-References, Adaptive Quant, multiple slices, CABAC, etc. Essentially everything in the Main Profile settings with some exceptions.

QuickTime WILL NOT support 8x8 dct and intra prediction, b-pyramids, lossless encoding, etc. As well as anything from the High Profile.

That said, you can still get an excellent looking encode if you follow this guide. This guide is assuming that you have a Full Screen (4:3) DVD vob file that is formatted in NTSC (29.970 FPS) and is fully Progressive Scan.

Weapons and Gear:
DVD Decrypter (http://www.doom9.org/Soft21/Rippers/SetupDVDDecrypter_3.5.4.0.exe) (get .VOB files from DVD)
DGIndex (http://neuron2.net/dgmpgdec/dgmpgdec.html) (for .d2v project file and .AC3 dolby audio de-muxer)
BeSweet (http://www.doom9.org/Soft21/Audio/BeSweetv1.5b31.zip) (audio encoding)
Nero 7 (http://www.nero.com/nero7/eng/) (Aac.dll and aacenc32.dll) or faac for ACC audio encoding
AVIsynth (http://www.doom9.org/Soft21/SupportUtils/Avisynth_256.exe) (frame server for almost unlimited ways of editing and processing your video)
x264 Full package (http://forum.doom9.org/showthread.php?t=89979) (for encoding H.264/AVC video) Sharktooth's latest build also comes with the x264 stripped down version of the MeGUI front end
MeGUI (http://forum.doom9.org/showthread.php?t=96032) (Encoding front end that will help you automate the encoding process and edit Command Line parameters. Full Version)
MP4Box (http://www.aziendeassociate.it/cd//gpac/dev/MP4Box.7z) (tool for muxing audio and video with MPEG-4 compliant container)

Now let's begin the 7 (6) simple steps to making a sweet encode that will be playable in QuickTime 7.0.3.

1) Rip the .vob(s) to your hard drive with DVD Decrypter

2) Use DGIndex to make a .d2v project file. Select your .vob file(s) you have, open with DGIndex, press F4, save your .d2v file and you will also get a de-muxed AC3 audio file.

3) Create an AVIsynth script to serve up to x264. if you have some of the extra plugins for AVIsynth, you can certainly use those as well. Here is my example for a NTSC 29.97 FPS Progressive Scan Video this format is ideal, we don't need to do anything except resize and clean:
# LOAD THE PLUGINS
LoadPlugin("C:\Program Files\AviSynth 2.5\plugins\DGDecode.dll")
LoadPlugin("C:\Program Files\AviSynth 2.5\plugins\RemoveGrainSSE3.dll")

# VIDEO SOURCE
mpeg2source("C:\VIDEO_TS\test.d2v")

# CROP THE IMAGE
crop(42,0,636,480)

# RESIZE (SHARP) FULLSCREEN SOURCE
LanczosResize(512,384)

# CLEAN THE PICTURE
RemoveGrain(mode=1) Here is my example for a NTSC 29.97 FPS Teleclined Video (we use Telecide filter to pull down the frame rate to 23.976 FPS, so be aware of the frame rate change) This will remove the Teleclined mice teeth artifacts that were left behind (common on The Simpson’s as well as the Seinfeld DVDs, and many many other 'made for TV' programs):# LOAD THE PLUGINS
LoadPlugin("C:\Program Files\AviSynth 2.5\plugins\DGDecode.dll")
LoadPlugin("C:\Program Files\AviSynth 2.5\plugins\decomb.dll")
LoadPlugin("C:\Program Files\AviSynth 2.5\plugins\RemoveGrainSSE3.dll")

# VIDEO SOURCE
mpeg2source("C:\VIDEO_TS\test.d2v")

# INVERSE TELECLINE OPTIONS
Telecide(guide=1).Decimate()

# CROP THE IMAGE
crop(42,0,636,480)

# RESIZE (SHARP) FULLSCREEN SOURCE
LanczosResize(512,384)

# CLEAN THE PICTURE
RemoveGrain(mode=1) Here is my example for a NTSC 29.97 FPS Interlaced Video Some DVDs never even bother to deinterlace the source, relying on your Progressive Scan DVD players to do the dirty work for you. Unfortunately we can't use a hardware deinterlacer, but TDeint and BlendBob are some fine filters that will do it for us.:# LOAD THE PLUGINS
LoadPlugin("C:\Program Files\AviSynth 2.5\plugins\DGDecode.dll")
LoadPlugin("C:\Program Files\AviSynth 2.5\plugins\TDeint.dll")
LoadPlugin("C:\Program Files\AviSynth 2.5\plugins\BlendBob.dll")
LoadPlugin("C:\Program Files\AviSynth 2.5\plugins\RemoveGrainSSE3.dll")

# VIDEO SOURCE
mpeg2source("C:\VIDEO_TS\test.d2v")

# DEINTERLACE OPTIONS
TDeint(mode=1,order=1,mtnmode=1)
BlendBob()

# CROP THE IMAGE
crop(42,0,636,480)

# RESIZE TO FULLSCREEN 4:3 ASPECT RATIO
LanczosResize(512,384)

# CLEAN THE PICTURE
RemoveGrain(mode=1)All of these avisynth filters can be downloaded at http://www.avisynth.org/warpenterprises/ if you don't have them. Make sure you give them the proper path when you LoadPlugin("Path to your plug-in here"). Now we save one of these three options as an avisynth filter file named template.avs or whatever you would like. Make sure that you change the filenames and paths used to the correct ones, or avisynth will b0rk when you try to start encoding.


4) Go back and encode the audio now. take the .AC3 dolby de-muxed audio file that was created back in step 2, and transcode it using BeSweet. In my example I use the Nero HE-AAC profile, so you will need to copy Aac.dll and aacenc32.dll from the C:\Program Files\Common Files\Ahead\AudioPlugins\ directory into your BeSweet directory. If you would like to use the Nero AAC Encoder completely independent of Nero 7, then you will also need to add the NeroIPP.dll to your BeSweet directory. That file should be located in the C:\Program Files\Common Files\Ahead\Lib\ directory. The command line that I use for AAC encoding is:
BeSweet.exe -core( -input "test 2_0ch 192Kbps DELAY 0ms.ac3" -output "test T01 2_0ch 192Kbps.m4a" -logfile "test T01 2_0ch 192Kbps DELAY 0ms.log" ) -azid( -n1 -s stereo -c normal -L -3db ) -bsn( -2ch -vbr_streaming -codecquality_high -aacprofile_he ) -ota( -d 0 -g max )
You can also use the full version of MeGUI as a front end to this BeSweet command line. I recommend using MeGUI, as it's a bit easier to achieve the same results. You can download the latest version on this thread MeGUI (http://forum.doom9.org/showthread.php?t=96032) .

5) Here is where we set up MeGUI to give ourselves a nice looking x264 video encode in an mp4 container. This part is key, as I have had some problems with certain settings for x264 (as far as QuickTime playback is concerned). I like to use 3-pass encoding, using slow RDO (level 6) to give the best possible looking rip we can make that is still playable in QT. I would post the exact settings that you should use here, but it is up to you on what settings you prefer. Remember that QuickTime is extremely picky on which x264 commands you can actually use out of the Main Profile. You cannot use b-pyramid in QuickTime! Here are my x264 command lines, so that you can make a batch file out of them if you wish. These settings are tested and proven to be 100% QuickTime compatible. About these settings: (pass 1 writes a stats file, pass 3 is also known as Nth pass, which will read the current stats file, and re-write the stats file upon completion of the pass, as well as output to the video file. The pass-2, also known as FINAL pass, will read the stats file and output to your final video .mp4 file. Pass-2 will not update the stats file, so make sure that pass-2 is only used on a final pass!) This is confusing, as the actual order of the passes will go as 1, 3, 2. (First, Nth, Final). To avoid confusion (too late :p) you could use the "--pass 3" option for your Nth and your final passes (1, 3, 3). This practice is used in MeGUI under 'Automated 3-Pass' settings. So don't panic if you never see "--pass 2" in your command line when using MeGUI's Automated 3-Pass.
x264.exe --pass 1 --bitrate 839 --stats "test.stats" --bframes 2 --subme 6 --analyse p8x8,b8x8,i4x4,p4x4 --me esa --progress --no-psnr --output NUL "template.avs"

x264.exe --pass 3 --bitrate 839 --stats "test.stats" --bframes 2 --subme 6 --analyse p8x8,b8x8,i4x4,p4x4 --me esa --progress --no-psnr --output "test.mp4" "template.avs"

x264.exe --pass 2 --bitrate 839 --stats "test.stats" --bframes 2 --subme 6 --analyse p8x8,b8x8,i4x4,p4x4 --me esa --progress --no-psnr --output "test.mp4" "template.avs"

6) *NOTE* I have given you an example of 3-pass encoding, which takes a very long time, and some people may not have the patience to wait for it. In my opinion, waiting once for a quality video encode that you can enjoy again and again is always worth it. That said, you can do 2-pass encoding if you wish, simply by removing the second line in my x264 command file. 3-pass encoding is going to take a long time to complete, but it will definitely be worth the wait. Crack open a beer and watch the game, then come back when encoding is complete.

7) Finally! the last step is multiplexing the audio and video feeds together. MP4Box by default likes to mux at an assumed frame rate of 25 fps. We're gonna have to tell it otherwise in our case (NTSC 29.970 FPS). If you used a Teleclined or an Interlaced source that has been decimated, then your source is now 23.97 FPS, so make the appropriate changes to this next command. Here is the command line for muxing the audio and video feeds together on a Progressive source!
MP4Box.exe -fps 29.970 -add "test.mp4" -add "test.m4a" "final_video.mp4"
Congratulations, if all went well you should have a usable video encode playable in QuickTime 7. Now that's what I call REAL Ultimate Power!!!! I hope that this guide has helped you make QuickTime compatible H.264/AVC MPEG-4 files. I wish that the steps to take will be more automated in the future (less command line stuff). MeGUI is shaping up to be a solid front end to encoding that will help to do just that. Thanks to everyone who worked on these excellent encoding tools, and thanks to the help of all the other people on this forum who helped me with this. And thanks to Doom9.net - The definitive DVD backup resource. *NOTE* I have tested up to 2 B-Frames successfully in QuickTime 7.0.3, I am not certain if you can do more B-Frames then that, but I know that you can do at least that many. Also, for some reason, the mp4 output from x264 won't play (nothing displayed on screen) until you mux it with the audio using MP4Box. I would guess that this is yet another QT bug.

*UPDATE* Despite Sharktooth's strong dislike for QuickTime, he was kind enough to supply us with some useful presets that can be used in MeGUI for full QuickTime compatibility. While the preset settings are 100% compatible with QuickTime, you are not limited to using just those. Remember that you can use up to 2 b-frames, multipass and exhaustive searches in QuickTime too, like my command line examples above. You can find Sharktooth's x264 MeGUI presets available for download here (http://forum.doom9.org/showthread.php?t=101813).


Q and A:.

Q: Why is everyone so obsessed about getting their video to work in QuickTime?

A: QuickTime is the ultimate paradox. On the one hand QuickTime doesn't give a crap, but on the other hand, QuickTime can be very careful and precise.

Q: I heard that QuickTime totally sucks. What's Apple's problem?

A: Whoever told you that is a total liar. Just like other media players, QuickTime can suck OR be totally awesome.

ChronoCross
11th November 2005, 01:52
# Video source project file
mpeg2source("C:\VIDEO_TS\test.d2v")

# Convert the colorspace from RGB to YV12
ConvertToYV12()

umm it already comes out of DGdecode in YV12 so the conversion is not needed. it'll just be a slowdown to the script.

Randall
11th November 2005, 04:08
Ah thanks. I had never used that step before, but somebody recommended it to me, as the x264 encoder works with YV12 internally.

Also a note to everyone interrested: The problem I was having with inconsistant successful encoding using x264 for QT would only show up when I used RAW format for the video. Since I have switched to using MP4 container as the standard output for the video, I have had 100% success with all of my encodings. As long as you use Main Profile, your encode should work with QuickTime after muxing your MPEG-4 video and AAC audio together with MP4Box.

Sirber
11th November 2005, 04:26
I had some problem with YUV2 sources... best keep it. If the source doesn't need convertion Avisynth will not do it.

Randall
11th November 2005, 04:41
Ok then back in it goes. Better safe then sorry I guess. This is the script that I have had success with, so we'll stick with it.

foxyshadis
11th November 2005, 05:02
A conversion to the same colorspace is a nop, according to ian; the only slowdown is a function call or two. ;)

Randall
11th November 2005, 05:18
foxyshadis: sweet Avatar. what show/OVA is that?

ChronoCross
11th November 2005, 05:44
A conversion to the same colorspace is a nop, according to ian; the only slowdown is a function call or two. ;)

when encoding with x264 every little bit of speed loss is devistating. lol.

Randall
11th November 2005, 05:47
lol alright I'll take them out again. speed is pretty valuable.

foxyshadis
11th November 2005, 06:38
We're talking on the order of less than .0000001 fps drop, especially since it will be required for any sources (via avi or ds) not in YV12...

(It's belldandy from OMG, from an artbook. =D)

I almost forgot, the other thing it probably needs is a quick ivtc/deinterlacer, commented out by default, if it's going to be a reference for newbies. (Telecide and KernelDeint are good for a basic script like this.) Thanks for figuring out all the options quicktime can decode.

berrinam
11th November 2005, 06:43
Wouldn't it be a fair bit easier to use MeGUI full version? It will manage steps 2-7 for you, and even add some level of automation if desired.

Kurtnoise
11th November 2005, 07:56
And why not using BeLight for audio transcoding and Yamb for muxing ?


:D

bond
11th November 2005, 11:47
x264.exe --pass 1 --bitrate 839 --stats "test.stats" --bframes 2 --subme 1 --analyse none --me dia --progress --no-psnr --output NUL "template.avs"

x264.exe --pass 2 --bitrate 839 --stats "test.stats" --bframes 2 --subme 6 --analyse p8x8,b8x8,i4x4,p4x4 --me esa --progress --no-psnr --output "test.mp4" "template.avs"

x264.exe --pass 3 --bitrate 839 --stats "test.stats" --bframes 2 --subme 6 --analyse p8x8,b8x8,i4x4,p4x4 --me esa --progress --no-psnr --output "test.mp4" "template.avs"
you are handling the 3 pass commands wrongly! what you are doing here is a 2pass with one pass done for nothing

the failure here is that --pass 2 doesnt stand for "2nd pass", but for "last pass", which means it doesnt update the .log file (x264 uses by default the .log extension for the stats and not .stats)
--pass 3 updates the .log file tough

so the order has to be that way:
--pass 1
--pass 3
--pass 2

MP4Box.exe -fps 29.970 -add "test.mp4" -fps 29.970 -add "test.m4a" "final_video.mp4"audio has no framerate! you dont need to set -fps 29.97 twice, only once for the video

stephanV
11th November 2005, 12:07
4) Go back and encode the audio now. take the .AC3 dolby de-muxed audio file that was created back in step 2, and transcode it useing BeSweet. In my example I use the Nero HE-AAC profile, so you will need to copy Aac.dll and aacenc32.dll from the C:\Program Files\Common Files\Ahead\AudioPlugins\ directory into your BeSweet directory.
I thought QuickTime didn't support HE-AAC (?), so using it would be pretty pointless then.


audio has no framerate!
Technically speaking it does (most compressed formats anyway), but it doesn't hold any relation to the video framerate.

bond
11th November 2005, 12:16
Technically speaking it does (most compressed formats anyway), but it doesn't hold any relation to the video framerate.well the thing is you cant influence audio playback speed in mp4box (by -fps)

Doom9
11th November 2005, 13:53
And why not using BeLight for audio transcoding and Yamb for muxing ?Well, with MeGUI you can have everything automated..

Sirber
11th November 2005, 14:11
Well, with MeGUI you can have everything automated..
And why not using BeLight for audio transcoding and Yamb for muxing ?


:DYou guys remember me my old days when I was trying to push my RealAnime :D

Randall
11th November 2005, 15:56
you are handling the 3 pass commands wrongly! what you are doing here is a 2pass with one pass done for nothing

the failure here is that --pass 2 doesnt stand for "2nd pass", but for "last pass", which means it doesnt update the .log file (x264 uses by default the .log extension for the stats and not .stats)
--pass 3 updates the .log file tough

so the order has to be that way:
--pass 1
--pass 3
--pass 2

audio has no framerate! you dont need to set -fps 29.97 twice, only once for the video

Are you sure? On automated 3 pass it gave it to me in that order, (the 1-2-3 order that makes sense) so I set it up manually because Sharktooth said there was a problem with the "turbo" option on 3-pass etc. etc. So you're saying to me that the third pass should go second, and again output to NUL and only write to (the same) logfile?? :confused:

Randall
11th November 2005, 16:03
I thought QuickTime didn't support HE-AAC (?), so using it would be pretty pointless then.


Technically speaking it does (most compressed formats anyway), but it doesn't hold any relation to the video framerate.

The audio in HE-AAC plays back in QuickTime, although it doesn't recognise it as HE. It thinks that it's LC. So you're losing quality in that sense (no SBR) but I can't tell the difference. It's not like it was dolby 5.1 digital surround sound to begin with. (it was just a 2.1 stereo cartoon). That said, full support for SBR is coming soon. :)

And why not using BeLight for audio transcoding and Yamb for muxing ?
:DThose are sweet front-ends. I should have pumped them in my tutorial.

Wouldn't it be a fair bit easier to use MeGUI full version? It will manage steps 2-7 for you, and even add some level of automation if desired.I didn't realize that the full version of MeGUI gives you all that functionallity. Can it transcode the AC3 track to Nero Digital AAC, and mux the Audio and Video via MP4Box?

stephanV
11th November 2005, 16:03
Are you sure? On automated 3 pass it gave it to me in that order, (the 1-2-3 order that makes sense) so I set it up manually because Sharktooth said there was a problem with the "turbo" option on 3-pass etc. etc. So you're saying to me that the third pass should go second, and again output to NUL and only write to (the same) logfile??
Yes, you can check x264 command line options as reference. --pass 2 is last pass, and --pass 3 is nth pass.

bond
11th November 2005, 16:06
lemme quote myself again

the failure here is that --pass 2 doesnt stand for "2nd pass", but for "last pass", which means it doesnt update the .log file (x264 uses by default the .log extension for the stats and not .stats)
--pass 3 updates the .log file toughand the x264 help:
-p, --pass <1|2|3> Enable multipass ratecontrol:
- 1: First pass, creates stats file
- 2: Last pass, does not overwrite stats file
- 3: Nth pass, overwrites stats fileand the x264 mencoder help:
Three pass encoding
x264 offers the ability to make an arbitrary number of consecutive passes. If you specify pass=1 on the first pass, then use pass=3 on a subsequent pass, the subsequent pass will both read the statistics from the previous pass, and write its own statistics.

Randall
11th November 2005, 16:12
Yes, you can check x264 command line options as reference. --pass 2 is last pass, and --pass 3 is nth pass.
D'oh!! that is confusing as hell. so I shouldn't be outputting to the actual video stream until pass-2, that being the final pass. My encode should look like (correct me if i'm wrong please):

x264.exe --pass 1 --bitrate 839 --stats "test.stats" --bframes 2 --subme 1 --analyse none --me dia --progress --no-psnr --output NUL "template.avs"

x264.exe --pass 3 --bitrate 839 --stats "test.stats" --bframes 2 --subme 6 --analyse p8x8,b8x8,i4x4,p4x4 --me esa --progress --no-psnr --output NUL "template.avs"

x264.exe --pass 2 --bitrate 839 --stats "test.stats" --bframes 2 --subme 6 --analyse p8x8,b8x8,i4x4,p4x4 --me esa --progress --no-psnr --output "test.mp4" "template.avs"
I am a little confused with this, as --subme 6 and --analyse p8x8,b8x8,i4x4,p4x4 may not be entirely useful unless I am writing to the actual video output. :confused:

Randall
11th November 2005, 16:21
I think I get what you're saying. 3 comes before 2, but pass-3 can still write to the video output, becaue it doesn't matter, it will be overwritten anyway. The logfile that gets updated is the key. So i reads the video.stats file, then writes it's own video.stats.temp file, then upon completion of the pass, it overwrites the old video.stats with the newer video.stats.temp file it created.

MeGUI implements automated 3-pass in an incorrect way if this is the case!! A VERY incorrect way. That is a major bug that should be mentioned upon release.

bond
11th November 2005, 16:24
D'oh!! that is confusing as hell. so I shouldn't be outputting to the actual video stream until pass-2, that being the final pass. My encode should look like (correct me if i'm wrong please):yep
you can actually also output a .mp4 already in --pass 3 (which would be the same .mp4 you would get with a 2pass encode)

I am a little confused with this, as --subme 6 and --analyse p8x8,b8x8,i4x4,p4x4 may not be entirely useful unless I am writing to the actual video output. :confused: i cant help you with this fastfirstpass thingie as i never tested it and i dunno what you can disable without loosing too much quality and what not and when

as a rule of thumb you should have the same settings in all passes, the rest needs to be tested

Randall
11th November 2005, 16:27
Thank you so much for your help bond. I will update my tutorial immeadately to avoid further confusion on the subject. After all, the x264 settings were the most important part of my tutorial. Thanks agian.

bond
11th November 2005, 16:34
no problem, apart from that i would not recommend using 3pass, because
1) two passes should be enough for getting a good bitrate distribution
2) x264's quality is already very good on 2 passes
3) x264 is already slow enough on 2 passes, no need for another third imho

Randall
11th November 2005, 16:50
Just To add to that, I just checked my logfile for MeGUI. Apparently MeGUI makes both pass-2 and pass-3 register in the command line as pass #3. Meaning that pass = 2 never comes up. Does this also defeat the purpose of the three pass, becuase it is re-writing the stats file? (Or maybe it doesn't matter, because pass N is still reading from the stats file before it writes to it)

bond
11th November 2005, 16:55
--pass 1
--pass 3
--pass 3

is also ok

the difference between --pass 3 and --pass 2 is only that one updates the log file and the other doesnt

hpn
11th November 2005, 22:29
--pass 1
--pass 3
--pass 3

is also ok
Very useful thread indead. Actually we don't need "--pass 2" even if we run a 2pass encode only, so IMHO the best choice for a 2pass encode is

--pass 1
--pass 3

and not

--pass 1
--pass 2

because if we decide that we want another pass (to maximize quality or get closer to the target bitrate) we just run --pass 3 again. The only 2 good things about --pass 2 are that (1) it doesn't generate and write another log file to the disk, so it saves some CPU cycles and the encoding will be 0.1% faster or so, which is absolutely negligible, and (2) because it keeps the log file for analysis (only makes sense if you are either a developer or some very curious user). Remind me if you know another reason for using --pass 2 at all.

Also it would be nice if instead of

--pass <1 | 2 | 3>

we had

--pass <first | last | next> (or --pass <first | next | last> )

which is more user friendly and unambiguous. But such a change although I guess easy to implement in x264 CLI, would also require changes in all related tools (mencoder, MeGUI, RealAnime etc).

berrinam
11th November 2005, 22:43
I didn't realize that the full version of MeGUI gives you all that functionallity. Can it transcode the AC3 track to Nero Digital AAC, and mux the Audio and Video via MP4Box?
Yes, it can.

Randall
11th November 2005, 22:54
Thanks for the tips guys.
@berrinam: I will try the full version of MeGUI next :)

I will update this guide with using MeGUI full version after I use it successfully. The main goal was to supply people with encoding options that will work without a doubt in the fussy QT, and I think I achieved that. I have also learned some very important lessons about multipass encoding with x264 thanks to bond and others on this thread :)

foxyshadis
12th November 2005, 11:47
But such a change although I guess easy to implement in x264 CLI, would also require changes in all related tools (mencoder, MeGUI, RealAnime etc).
x264 can accept the old values (maybe with a "depreciated" warning) and translate them to the new on the fly, so old tools can catch up.

Both sound sensible to me, although I will admit that using 2/3 to mean something other than 2nd/3rd pass is just asking for confusion. Hmm.

smok3
14th November 2005, 09:55
The problem I was having with inconsistant successful encoding using x264 for QT would only show up when I used RAW format for the video.
damn, that was the problem? i kinda suspected it is something 'trivial' thought...


--analyse p8x8,b8x8,i4x4,p4x4 isnt that the same as --analyze all ?

btw, my bat file was updated according to this thread and it seems pretty 'stable' at the moment.

Randall
14th November 2005, 19:33
The problem I was having with inconsistant successful encoding using x264 for QT would only show up when I used RAW format for the video.
damn, that was the problem? i kinda suspected it is something 'trivial' thought...


--analyse p8x8,b8x8,i4x4,p4x4 isnt that the same as --analyze all ?

btw, my bat file was updated according to this thread and it seems pretty 'stable' at the moment.

Umm I could be wrong, but if you have it set for main profile then that might be fine, but I assume 'all' to include 8x8 Intra Search (i8x8) and that is bad!! That will kill your QT compatibility in a big way. Somebody could correct me here if I'm wrong, because I am not positive if --analyse all specifies everything like it would imply. I specified exactly the options that we wanted, just to avoid any possibility of that confusion.

BTW I would love to recommend your bat file to everyone here if you could post an updated version on this thread that would be sweet. Thanks for your help with QT compatibility smok3! :)

smok3
14th November 2005, 22:42
hehe, well it is not recommended for everybody, it is targeted for avi -> x264/faac in mp4
(there is now an easy option to patch it to a button in total commander as well, also i did quite a lot of testing and it appears to work well.)

link to a post which links to a guide which links to that bat file:
http://forum.doom9.org/showthread.php?t=102186

short guide for x264_.bat would be:
-------------------------------------------
- edit template.avs to your liking
- edit x264_.bat (x264 & faac command lines) to your liking
run with two parameters, like:
x264_ c:\path\to\input.avi d:\path\to\template.avs
- optional edit x264_tcm.bat and apply to total commander via button or menu.

sunilraman
15th November 2005, 06:09
hmm. some challenges with latest MeGUI x264 build from the forums. perhaps it is because i fiddled with Qmin settings? :( nice playback in VLC though and thanks for this guide.

Randall
15th November 2005, 22:37
No problem sunilraman. I'm glad the guide was able to help you. I am not sure what Qmin settings can work in QT, as I didn't test a full range of those. I would keep it at 10 or whatever the default setting is. Perhaps higher settings are ok, because I read a review somewhere on how to encode for the iPod with baseline, and saw that they used a Qmin value of 20 or so.

Also, I will post some template.avs files later on that work with interlaced material, and teleclined material... because my template.avs only showed what to do with progressive source (the easiest kind to work with).

sunilraman
16th November 2005, 13:01
heh. cool. i figured out my problem is using iTunesEncoder to do the AAC encoding. i will post my workaround here later tonight. yup and i figured out telecide(1) and assume frames thingy :o :cool:

edit:
i find that if i extract out the video track using
mp4box -single "1" index001.mp4

(extracting out of the video only mp4 output of x264)
quicktime then likes the mp4. then i can use qt7pro (ouch) to mux in the audio ("add to movie") command

sunilraman
17th November 2005, 09:11
sweet. i am getting the hang of x264 now, it really is excellent and delivers quality which can be fine-tuned quite well. high profile custom quant matrices would be the icing on the cake :D especially if it cleans up the shadow detail issues. but as we are dealing with qt7 here, i think using apple-style "multipass honing"* technique may deliver what i need.

*i believe apple qt7pro h.264 multipass encoding uses recursive passes which progressively reduce the bitrate target or somethin. i believe this is why the apple qt7pro encoder is so slow on multipass encoding, why it never tells you exactly how many passes it does, and how qt7pro encoder is able to avoid too much blockiness ocurring in shadow detail areas (or areas where the hues are near each other on the color wheel).... hmmm of course, i could be off base here, so feel free if you know anything 'bout this.

i'm trying a 4-pass batch encode as follows, just to play with a "multipass recursive honing style". i can't use custom quant matrices because i am aiming for qt7 playback compatibility at this stage... here it is below... (in each pass i increase the subme level and qpmax, and decrease the target bitrate)

"c:\program files\x264\x264.exe" --pass 1 --bitrate 3800 --stats "index000.stats" --subme 3 --bframes 2 --weightb --trellis 2 --analyse p8x8,b8x8,i4x4,p4x4 --qpmin 22 --qpmax 28 --qpstep 1 --me umh --progress --no-psnr --output NUL "C:\Temp\index000.avs"
"c:\program files\x264\x264.exe" --pass 3 --bitrate 3200 --stats "index000.stats" --subme 4 --bframes 2 --weightb --trellis 2 --analyse p8x8,b8x8,i4x4,p4x4 --qpmin 22 --qpmax 32 --qpstep 1 --me umh --progress --no-psnr --output "C:\Temp\index000.mp4" "C:\Temp\index000.avs"
"c:\program files\x264\x264.exe" --pass 3 --bitrate 2800 --stats "index000.stats" --subme 5 --bframes 2 --weightb --trellis 2 --analyse p8x8,b8x8,i4x4,p4x4 --qpmin 22 --qpmax 36 --qpstep 1 --me umh --progress --no-psnr --output "C:\Temp\index000.mp4" "C:\Temp\index000.avs"
"c:\program files\x264\x264.exe" --pass 2 --bitrate 2200 --stats "index000.stats" --subme 6 --bframes 2 --weightb --trellis 2 --analyse p8x8,b8x8,i4x4,p4x4 --qpmin 22 --qpmax 38 --qpstep 1 --me umh --progress --no-psnr --output "C:\Temp\index000.mp4" "C:\Temp\index000.avs"

edit: here's a multipass batch that results in a nice 2200kbps file of 640x256 which scales really well when playing back on 1280x1024 monitors, also nice film grain, grit and organic feel. average of 2-4fps in total with all 5 passes taken into account:

"c:\program files\x264\x264.exe" --pass 1 --bitrate 3800 --stats "index000.stats" --subme 2 --bframes 2 --weightb --trellis 2 --analyse p8x8,b8x8,i4x4,p4x4 --qpmin 5 --qpmax 28 --qpstep 1 --me umh --progress --no-psnr --output NUL "C:\Temp\index000.avs"
"c:\program files\x264\x264.exe" --pass 3 --bitrate 3600 --stats "index000.stats" --subme 3 --bframes 2 --weightb --trellis 2 --analyse p8x8,b8x8,i4x4,p4x4 --qpmin 6 --qpmax 32 --qpstep 1 --me umh --progress --no-psnr --output "C:\Temp\index000.mp4" "C:\Temp\index000.avs"
"c:\program files\x264\x264.exe" --pass 3 --bitrate 3200 --stats "index000.stats" --subme 4 --bframes 2 --weightb --trellis 2 --analyse p8x8,b8x8,i4x4,p4x4 --qpmin 7 --qpmax 34 --qpstep 1 --me umh --progress --no-psnr --output "C:\Temp\index000.mp4" "C:\Temp\index000.avs"
"c:\program files\x264\x264.exe" --pass 3 --bitrate 2800 --stats "index000.stats" --subme 5 --bframes 2 --weightb --trellis 2 --analyse p8x8,b8x8,i4x4,p4x4 --qpmin 9 --qpmax 36 --qpstep 1 --me umh --progress --no-psnr --output "C:\Temp\index000.mp4" "C:\Temp\index000.avs"
"c:\program files\x264\x264.exe" --pass 2 --bitrate 2200 --stats "index000.stats" --subme 6 --bframes 2 --weightb --trellis 2 --analyse p8x8,b8x8,i4x4,p4x4 --qpmin 12 --qpmax 42 --qpstep 1 --me umh --progress --no-psnr --output "C:\Temp\index000.mp4" "C:\Temp\index000.avs"

leban
17th November 2005, 10:38
Thanks for this guide. I could not get it to work anyway. This is the errors I get:

x264 --pass 2 --bitrate 839 --bframes 2 --subme 6 --analyse p8x8,b8x8,i4x4,p4x4 --me esa --progress --no-psnr --output test-1711.mp4 klo5-6-f25-Ip.yuv 720x480
x264 [info]: using cpu capabilities MMX MMXEXT SSE SSE2
mp4 [info]: initial delay 1 (scale 25)
x264 [error]: More input frames than in the 1st pass
x264 [error]: More input frames than in the 1st pass
x264 [error]: More input frames than in the 1st pass
x264 [error]: More input frames than in the 1st pass
x264 [error]: More input frames than in the 1st pass
x264 [error]: More input frames than in the 1st pass
x264: encoder/ratecontrol.c:467: x264_ratecontrol_start: Assertion `frame >= 0 && frame < rc->num_entries' failed.
Aborted

I am running this on a Linux box with x264 core:37 svn-336. Should I try to upgrade the version from svn?
With --pass 1 I am able to proceed but the result is still without an image.
My input is raw yuv made from jpg-images with jpeg2yuv and I am trying to figure out if this is yuv2 or something else.

Sharktooth
17th November 2005, 11:24
check the stats file.

cast42
18th November 2005, 14:01
Hi,
I used this guide with succes to encode for Quicktime 7. Because I'm started from PAL video I used -fps 25 for the MP4box.exe command. The result is looking awesome in the quicktime and mpc players. Thanks for this great guide. However, my 60GB video Ipod is refusing to play it. Videos encoded using Quictime 7 Pro do work fine. Has anybody an idea how to change/adapt this guide for video on the iPod ? On the Apple pages, following information is stated:
H.264 video: up to 768 Kbps, 320 x 240, 30 frames per sec., Baseline Profile up to Level 1.3 with AAC-LC up to 160 Kbps, 48 Khz, stereo audio in .m4v, .mp4 and .mov file formats

The audio I've muxed in was compressed with Nero 7 (not the BeSweet procedure). and is MPEG-4 Main@L2 (AAC LC) at 96Kbps.

This is the info of the x264 generated video using MP4Box 0.4.0:
[prompt$ D:/bin/MP4Box.exe -info video.mp4
* Movie Info *
Timescale 600 - Duration 00:02:44.880
Fragmented File no - 1 track(s)
File Brand avc1 - version 0

File has root IOD
Scene PL 0xff - Graphics PL 0xff - OD PL 0xff
Visual PL: AVC/H264 Profile (0x15)
Audio PL: No audio capability required (0xff)
No streams included in root OD

Track # 1 Info - TrackID 1 - TimeScale 25 - Duration 00:02:44.880
Media Info: Language "und" - Type "vide" - Sub Type "avc1" - 4122 samples
MPEG-4 Config: Visual Stream - ObjectTypeIndication 0x21
AVC/H264 Video - Visual Size 320 x 240
Self-synchronized

After muxing using:
mp4box.exe -fps 25 -add "video.mp4" -add "audio.mp4" result.mp4
I get:
[prompt]$ D:/bin/MP4Box.exe -info result.mp4
* Movie Info *
Timescale 600 - Duration 00:02:44.895
Fragmented File no - 4 track(s)
File Brand isom - version 1

File has root IOD
Scene PL 0xff - Graphics PL 0xff - OD PL 0xff
Visual PL: Advanced Simple Profile @ Level 3 (0xf3)
Audio PL: AAC Profile @ Level 2 (0x29)

Track # 1 Info - TrackID 2 - TimeScale 32000 - Duration 00:02:44.896
Media Info: Language "und" - Type "soun" - Sub Type "mp4a" - 5153 samples
MPEG-4 Config: Audio Stream - ObjectTypeIndication 0x40
MPEG-4 Audio AAC LC - 2 Channel(s) - SampleRate 32000
Synchronized on stream 4

Track # 2 Info - TrackID 3 - TimeScale 24000 - Duration 00:02:44.880
Media Info: Language "und" - Type "soun" - Sub Type "mp4a" - 6870 samples
MPEG-4 Config: Audio Stream - ObjectTypeIndication 0x69
MPEG-2.5 Audio - 2 Channel(s) - SampleRate 0 - Layer 2
Synchronized on stream 4

Track # 3 Info - TrackID 4 - TimeScale 1000 - Duration 00:02:44.895
Track is present in Root OD
Media Info: Language "und" - Type "odsm" - Sub Type "mp4s" - 1 samples
MPEG-4 Config: ObjectDescriptor Stream - ObjectTypeIndication 0x01
Self-synchronized

Track # 4 Info - TrackID 5 - TimeScale 1000 - Duration 00:02:44.895
Track is present in Root OD
Media Info: Language "und" - Type "sdsm" - Sub Type "mp4s" - 1 samples
MPEG-4 Config: SceneDescription Stream - ObjectTypeIndication 0x02
Synchronized on stream 4

Is Advanced Simple Profile @ Level 3 (0xf3) as reported by MP4box covered by the "Baseline Profile up to Level 1.3" spec from Apple ??

A movide generated by Quicktime 7 Pro export to ipod reports this:
[prompt]$ D:/bin/MP4Box.exe -info withQT7ExportToIpod.m4v
* Movie Info *
Timescale 600 - Duration 00:05:02.246
Fragmented File no - 2 track(s)
File Brand M4V - version 1

File has no MPEG4 IOD/OD

Track # 1 Info - TrackID 1 - TimeScale 44100 - Duration 00:05:02.254
Media Info: Language "eng" - Type "soun" - Sub Type "mp4a" - 13017 samples
MPEG-4 Config: Audio Stream - ObjectTypeIndication 0x40
MPEG-4 Audio AAC LC - 2 Channel(s) - SampleRate 44100
Self-synchronized

Track # 2 Info - TrackID 2 - TimeScale 600 - Duration 00:05:02.246
Media Info: Language "eng" - Type "vide" - Sub Type "avc1" - 7093 samples
MPEG-4 Config: Visual Stream - ObjectTypeIndication 0x21
AVC/H264 Video - Visual Size 320 x 200
Synchronized on stream 1


Help me getting video on the Ipod!

Thx

Sharktooth
18th November 2005, 14:08
iPod and quicktime are different. donwload x264-psp from x264.nl and follow the instructions.

Randall
20th November 2005, 23:51
hi cast42. Definately go with Sharktooth's recomendation, the x264-psp profile is excatly what you need for iPod compatible encoding. This guide was for QT compatibility, and iPod is a little different. For starters, the video size must be no bigger then 320 x 240 30 frames per sec. etc. And I believe that only the baseline profile will work with it. Also, my audio encoding profile won't work on iPod either. You'll need to use AAC LC encoding instead of the AAC HE. Finally, you must keep the bitrate down to 768 Kbps or lower. if you're doing ABR or VBR it's a good idea to keep it around 700 Kbps, because if I understand correctly, for iPod encoding you cannot be above 768 Kbps at any given moment.

smok3
21st November 2005, 12:09
framerate for ipod must be always 30fps?

Randall
22nd November 2005, 04:29
framerate for ipod must be always 30fps?
No, that's just the maximum framerate that you can use. Sorry for the confusion. ;)

cast42
22nd November 2005, 11:13
Hi,
Randall is right. 30fps is the maximum. Video generated from 25fps PAL play on Ipod:
Here an example of mp4info dump:
Track Type Info
1 audio MPEG-4 AAC LC, 47.693 secs, 128 kbps, 44100 Hz
2 video H264 Baseline@1.3, 48.360 secs, 579 kbps, 320x240 @ 25.000000 fp
s

To be more precise here an excerpt from an QT Pro generated .m4v with mp4dump:
The majorbrand is M4V
De video is:
type avc1
reserved1 = <6 bytes> 00 00 00 00 00 00
dataReferenceIndex = 1 (0x0001)
reserved2 = <16 bytes> 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
width = 320 (0x0140)
height = 240 (0x00f0)
reserved3 = <14 bytes> 00 48 00 00 00 48 00 00 00 00 00 00 00 01
compressorName =
reserved4 = <4 bytes> 00 18 ff ff
type avcC
configurationVersion = 1 (0x01)
AVCProfileIndication = 66 (0x42)
profile_compatibility = 224 (0xe0)
AVCLevelIndication = 13 (0x0d)
reserved = 63 (0x3f) <6 bits>
lengthSizeMinusOne = 3 (0x3) <2 bits>
reserved1 = 7 (0x7) <3 bits>
numOfSequenceParameterSets = 1 (0x01) <5 bits>
<table entries suppressed>
numOfPictureParameterSets = 1 (0x01)
<table entries suppressed>

leban
23rd November 2005, 09:51
No success here. Still the same results, Quicktime plays the file but does not show picture. There is no sound track.

If some one wants to check this out, the stats files, the source and result are here: http://gandalf.lasipalatsi.net/testit/kimmotesti/

the command I am using is:
x264 --pass 1 --bitrate 839 --bframes 2 --subme 6 --analyse p8x8,b8x8,i4x4,p4x4 --me esa --progress --stats 1711.stats --no-psnr --output test-1711.mp4 klo5-6-f25-Ip.yuv 720x480


And this looks ok:
x264 [info]: using cpu capabilities MMX MMXEXT SSE SSE2
mp4 [info]: initial delay 1 (scale 25)
x264 [info]: slice I:86 Avg QP:50.47 size: 12103
x264 [info]: slice P:234 Avg QP:50.74 size: 7480
x264 [info]: mb I I16..4: 85.8% 0.0% 14.2%
x264 [info]: mb P I16..4: 78.5% 0.0% 4.4% P16..4: 15.1% 0.7% 0.2% 0.0% 0.0% skip: 1.0%
x264 [info]: kb/s:1744.6

encoded 320 frames, 1.06 fps, 1744.97 kb/s


Should I run the .mp4 thru mp4box even though I don't have sound?

smok3
23rd November 2005, 11:03
leban,
1. deleted, nm.
2. yes, you have to remux the file using mp4box.

here is my lil guide if it is of some use:
http://somestuff.org/x264_qt/h264_in_quicktime7.html
(including the very sexy win bat file)

akupenguin
23rd November 2005, 17:51
If some one wants to check this out, the stats files, the source and result are here: http://gandalf.lasipalatsi.net/testit/kimmotesti/
Those results do not look ok. 78% intra in P-frames? QP50 and still twice the requested bitrate?
Cause: your source is 640x480, not 720x480. And it's yuv4mpeg, not raw yuv.
mencoder -ovc copy -of rawvideo klo5-6-f25-Ip.y4m -o klo5-6-f25-Ip.yuv