Welcome to Doom9's Forum, THE in-place to be for everyone interested in DVD conversion.

Before you start posting please read the forum rules. By posting to this forum you agree to abide by the rules.

 

Go Back   Doom9's Forum > Video Encoding > MPEG-4 AVC / H.264

Reply
 
Thread Tools Search this Thread Display Modes
Old 11th November 2005, 01:16   #1  |  Link
Randall
Registered User
 
Randall's Avatar
 
Join Date: Sep 2005
Location: Norwood, MA
Posts: 175
REAL Ultimate Guide to x264 and QuickTime!!!

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 (get .VOB files from DVD)
DGIndex (for .d2v project file and .AC3 dolby audio de-muxer)
BeSweet (audio encoding)
Nero 7 (Aac.dll and aacenc32.dll) or faac for ACC audio encoding
AVIsynth (frame server for almost unlimited ways of editing and processing your video)
x264 Full package (for encoding H.264/AVC video) Sharktooth's latest build also comes with the x264 stripped down version of the MeGUI front end
MeGUI (Encoding front end that will help you automate the encoding process and edit Command Line parameters. Full Version)
MP4Box (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:
Code:
# 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):
Code:
# 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.:
Code:
# 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:
Code:
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 .

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 ) 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.
Code:
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!
Code:
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.


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.

Last edited by Randall; 4th December 2006 at 19:19.
Randall is offline   Reply With Quote
Old 11th November 2005, 01:52   #2  |  Link
ChronoCross
Does it really matter?
 
ChronoCross's Avatar
 
Join Date: Jun 2004
Location: Chicago, IL
Posts: 1,542
# 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.
ChronoCross is offline   Reply With Quote
Old 11th November 2005, 04:08   #3  |  Link
Randall
Registered User
 
Randall's Avatar
 
Join Date: Sep 2005
Location: Norwood, MA
Posts: 175
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.

Last edited by Randall; 11th November 2005 at 04:24.
Randall is offline   Reply With Quote
Old 11th November 2005, 04:26   #4  |  Link
Sirber
retired developer
 
Sirber's Avatar
 
Join Date: Oct 2002
Location: Canada
Posts: 8,978
I had some problem with YUV2 sources... best keep it. If the source doesn't need convertion Avisynth will not do it.
__________________
Detritus Software
Sirber is offline   Reply With Quote
Old 11th November 2005, 04:41   #5  |  Link
Randall
Registered User
 
Randall's Avatar
 
Join Date: Sep 2005
Location: Norwood, MA
Posts: 175
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.
Randall is offline   Reply With Quote
Old 11th November 2005, 05:02   #6  |  Link
foxyshadis
ангел смерти
 
foxyshadis's Avatar
 
Join Date: Nov 2004
Location: Lost
Posts: 9,175
A conversion to the same colorspace is a nop, according to ian; the only slowdown is a function call or two.
foxyshadis is offline   Reply With Quote
Old 11th November 2005, 05:18   #7  |  Link
Randall
Registered User
 
Randall's Avatar
 
Join Date: Sep 2005
Location: Norwood, MA
Posts: 175
foxyshadis: sweet Avatar. what show/OVA is that?
Randall is offline   Reply With Quote
Old 11th November 2005, 05:44   #8  |  Link
ChronoCross
Does it really matter?
 
ChronoCross's Avatar
 
Join Date: Jun 2004
Location: Chicago, IL
Posts: 1,542
Quote:
Originally Posted by foxyshadis
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.
ChronoCross is offline   Reply With Quote
Old 11th November 2005, 05:47   #9  |  Link
Randall
Registered User
 
Randall's Avatar
 
Join Date: Sep 2005
Location: Norwood, MA
Posts: 175
lol alright I'll take them out again. speed is pretty valuable.
Randall is offline   Reply With Quote
Old 11th November 2005, 06:38   #10  |  Link
foxyshadis
ангел смерти
 
foxyshadis's Avatar
 
Join Date: Nov 2004
Location: Lost
Posts: 9,175
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.

Last edited by foxyshadis; 11th November 2005 at 06:41.
foxyshadis is offline   Reply With Quote
Old 11th November 2005, 06:43   #11  |  Link
berrinam
Registered User
 
berrinam's Avatar
 
Join Date: Apr 2005
Posts: 1,740
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.
berrinam is offline   Reply With Quote
Old 11th November 2005, 07:56   #12  |  Link
Kurtnoise
Swallowed in the Sea
 
Kurtnoise's Avatar
 
Join Date: Oct 2002
Location: Aix-en-Provence, France
Posts: 5,182
And why not using BeLight for audio transcoding and Yamb for muxing ?


Kurtnoise is offline   Reply With Quote
Old 11th November 2005, 11:47   #13  |  Link
bond
Registered User
 
Join Date: Nov 2001
Posts: 9,779
Quote:
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

Quote:
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
__________________
Between the weak and the strong one it is the freedom which oppresses and the law that liberates (Jean Jacques Rousseau)
I know, that I know nothing (Socrates)

MPEG-4 ASP FAQ | AVC/H.264 FAQ | AAC FAQ | MP4 FAQ | MP4Menu stores DVD Menus in MP4 (guide)
Ogg Theora | Ogg Vorbis
use WM9 today and get Micro$oft controlling the A/V market tomorrow for free
bond is offline   Reply With Quote
Old 11th November 2005, 12:07   #14  |  Link
stephanV
gone
 
Join Date: Apr 2004
Posts: 1,709
Quote:
Originally Posted by Randall
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.

Quote:
Originally Posted by Bond
audio has no framerate!
Technically speaking it does (most compressed formats anyway), but it doesn't hold any relation to the video framerate.
stephanV is offline   Reply With Quote
Old 11th November 2005, 12:16   #15  |  Link
bond
Registered User
 
Join Date: Nov 2001
Posts: 9,779
Quote:
Originally Posted by stephanV
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)
__________________
Between the weak and the strong one it is the freedom which oppresses and the law that liberates (Jean Jacques Rousseau)
I know, that I know nothing (Socrates)

MPEG-4 ASP FAQ | AVC/H.264 FAQ | AAC FAQ | MP4 FAQ | MP4Menu stores DVD Menus in MP4 (guide)
Ogg Theora | Ogg Vorbis
use WM9 today and get Micro$oft controlling the A/V market tomorrow for free
bond is offline   Reply With Quote
Old 11th November 2005, 13:53   #16  |  Link
Doom9
clueless n00b
 
Join Date: Oct 2001
Location: somewhere over the rainbow
Posts: 10,570
Quote:
And why not using BeLight for audio transcoding and Yamb for muxing ?
Well, with MeGUI you can have everything automated..
__________________
For the web's most comprehensive collection of DVD backup guides go to www.doom9.org
Doom9 is offline   Reply With Quote
Old 11th November 2005, 14:11   #17  |  Link
Sirber
retired developer
 
Sirber's Avatar
 
Join Date: Oct 2002
Location: Canada
Posts: 8,978
Quote:
Originally Posted by Doom9
Well, with MeGUI you can have everything automated..
Quote:
Originally Posted by Kurtnoise13
And why not using BeLight for audio transcoding and Yamb for muxing ?


You guys remember me my old days when I was trying to push my RealAnime
__________________
Detritus Software
Sirber is offline   Reply With Quote
Old 11th November 2005, 15:56   #18  |  Link
Randall
Registered User
 
Randall's Avatar
 
Join Date: Sep 2005
Location: Norwood, MA
Posts: 175
Quote:
Originally Posted by bond
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??
Randall is offline   Reply With Quote
Old 11th November 2005, 16:03   #19  |  Link
Randall
Registered User
 
Randall's Avatar
 
Join Date: Sep 2005
Location: Norwood, MA
Posts: 175
Quote:
Originally Posted by stephanV
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.

Quote:
Originally Posted by Kurtnoise13
And why not using BeLight for audio transcoding and Yamb for muxing ?
Those are sweet front-ends. I should have pumped them in my tutorial.

Quote:
Originally Posted by berrinam
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?

Last edited by Randall; 11th November 2005 at 16:08.
Randall is offline   Reply With Quote
Old 11th November 2005, 16:03   #20  |  Link
stephanV
gone
 
Join Date: Apr 2004
Posts: 1,709
Quote:
Originally Posted by Randall
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.
stephanV is offline   Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 06:52.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2017, vBulletin Solutions Inc.