Log in

View Full Version : Constant Quality, 2 pass in MEGUI?


Dot50Cal
21st November 2007, 01:20
Hi guys, I come today looking for help in speeding up my encoding process. At the moment, I use Constant Quality to determine what bitrate I should be aiming for, and then I do a 2 pass encode at that bitrate. This isn't really ideal, as I have to be at the machine after the Constant Quality pass ends and then I have to add in the 2 pass bitrate. I've read that a 2 pass encode will be better quality than a 1 pass Constant Quality encode.

So my question is, is there a way to cut the Constant Quality encode out of the equation? Most video's I do right now take quite a while and I'd really like to speed this up.

Ideally, what I'd like is the ability to do a 2pass encode of Constant Quality (And I seen that this wasn't possible from a post in 2006), but I'm not entirely sure that would work properly. Can anyone chime in on their thoughts?

I should add that my Constant Quality and 2 Pass settings are exactly alike, barring the obvious differences.

Thanks in advance!

Unearthly
21st November 2007, 01:50
I wrote a python script to do this for me, but I'm not sure if it would be easy to do in MeGUI. If you are interested though, I can post an example of how to extract the bitrate from a log file.

Dot50Cal
21st November 2007, 02:27
To be honest, I'm not sure how to implement something like that. If you could get something like that working on Megui, I'd be eternally grateful though!

chros
25th November 2007, 20:27
Try this batch script:
- it requires 1 parameter, the avs file , eg: trailers-sthqs.cmd foo.avs
- it requires tee.exe , download from http://sourceforge.net/projects/unxutils

Features:
- easily configurable command lines
- support for custom matrix
- support for credits
- support for quiet mode in 1st and 2nd pass too (it's faster)
- support for skipping passes
- support for setting encoding priority

If you have any question, just shoot it !

trailers-sthqs.cmd

@ECHO off
REM Use CTRL+BREAK instead of CTRL+C to cancel the batch script
REM Requirements: tee.exe , http://sourceforge.net/projects/unxutils
TITLE encoding with ST v43 CQ and HQ-Slower profile

IF "%1"=="" GOTO ERRORPARAM

REM What is the fps of the video ?
SET mki=24
SET ki=240
SET x264file="C:\Program Files\megui\tools\x264\x264.exe"
SET teefile="C:\Program Files\megui\tools\tee\tee.exe"
::SET matrixfile=--cqmfile "C:\Program Files\megui\tools\x264\prestige.cfg"
SET matrixfile=
SET outfile=output.txt
SET tempfile=temp.mp4
SET logfile=log.txt

::SET credits=--zones 37910,38914,b=0.1
SET credits=
SET logonscreenpass1=--quiet
::SET logonscreenpass1=
::SET logonscreenpass2=--quiet
SET logonscreenpass2=

REM if you know the bitrate and want to skip the first pass, use it with skippass1=1
::SET bitrate=4529
REM whether to skip pass1 or pass2, values: [ 1 = true | 0 = false ]
SET skippass1=0
SET skippass2=0

REM priority of encoding, values: [ low | belownormal | normal | abovenormal | high | realtime ]
SET encpriority=low

REM The x264 command lines. Don't use the bitrate parameter in the pass2options !!!
SET cq18options=--pass 1 --crf 18 --stats .stats --keyint %ki% --min-keyint %mki% --ref 5 --mixed-refs --bframes 16 --b-pyramid --b-rdo --bime --weightb --direct auto --filter -2,-1 --subme 6 --trellis 1 --analyse p8x8,b8x8,i4x4,i8x8 --8x8dct --me umh --threads auto --thread-input %matrixfile% %credits% --progress --no-psnr --no-ssim %logonscreenpass1%
SET pass2options=--pass 2 --stats ".stats" --keyint %ki% --min-keyint %mki% --ref 5 --mixed-refs --no-fast-pskip --bframes 3 --b-pyramid --b-rdo --bime --weightb --direct auto --deblock -3:-3 --subme 7 --analyse p8x8,b8x8,i4x4,i8x8 --8x8dct --trellis 1 --aq-strength 0.3 --me umh --threads auto --thread-input --cqmfile %matrixfile% %credits% --progress --no-psnr --no-ssim %logonscreenpass2%

SET infile=%1
SET startdate=%Date: =%
SET starttime=%Time:~0,-3%

IF NOT "%skippass1%"=="1" CALL :PASS1
IF NOT "%skippass1%"=="1" CALL :GETBITRATE
IF NOT "%skippass2%"=="1" CALL :PASS2 %1
GOTO END

:PASS1
REM 1st CQ18 pass in 2pass encoding
ECHO %Time:~0,-3% - 1st CQ18 pass
start /%encpriority% /b /w "pass1" %x264file% %cq18options% --output NUL %infile% 2>&1 | %teefile% log.txt
GOTO :EOF

:GETBITRATE
FOR /f "delims=, tokens=3" %%X IN ('type log.txt ^|find "frames,"') DO SET bitrate=%%X
SET bitrate=%bitrate: =%
SET bitrate=%bitrate:~0,-7%
ECHO After CQ 18 pass: %bitrate% kbps
DEL log.txt
GOTO :EOF

:PASS2
REM 2nd pass in 2pass encoding
ECHO %Time:~0,-3% - 2st pass
start /%encpriority% /b /w "pass2" %x264file% %pass2options% --bitrate %bitrate% --output "%~n1.mp4" "%infile%"
::DEL .stats
GOTO :EOF

:ERRORPARAM
ECHO.
ECHO Missing parameter !
ECHO Usage: %0 avisynth-script
ECHO eg.: %0 foo.avs
ECHO Aborting ... !
ECHO.
GOTO END

:END
::DEL .stats
SET credits=
SET enddate=%Date: =%
SET endtime=%Time:~0,-3%
ECHO %starttime% - %endtime% : %bitrate% kbps


Hint: edit/view batch files with Notepad++ ...

Enjoy! :)