Difference between revisions of "Batch Encoding"

From SDA Knowledge Base

Jump to: navigation, search
(mp4box -new)
(Setup: nero)
 
(16 intermediate revisions by 2 users not shown)
Line 1: Line 1:
 
==Introduction==
 
==Introduction==
  
This guide assumes you are familiar with encoding through CLI or you are comfortable with Megui.
+
This guide assumes you are familiar with encoding through CLI or you are comfortable with MeGUI.
  
Why encode with batch files? This is a good question. When you are encoding many videos, you tend to use the same configuration settings for H.264 and AAC. You may have even created your own profiles already. Once you are comfortable with Megui and realize how easy it is to use, you start getting annoyed of repeatedly clicking the same options. You already know what you want from the start, so why not simplify the process? Actually, one thing that Megui can't do is queue multiplexing jobs before the video and audio files are finished and sitting on your hard drive. So that's a big plus for batch encoding.
+
Why encode with batch files? This is a good question. When you are encoding many videos, you tend to use the same configuration settings for H.264, AAC, Xvid and MP3. You may have even created your own profiles already. Once you are comfortable with MeGUI and realize how easy it is to use, you start getting annoyed of repeatedly clicking the same options. You already know what you want from the start, so why not simplify the process?
 +
 
 +
However, there are some disadvantages to batch file encoding that you should know. In MeGUI you are able to postpone/delete jobs without interrupting the current encoding job. You can even stop the current job and the program will continue on with the rest. With batch files you'll have to stop the whole process cold, edit encode.bat and then run it again.
  
 
<br>
 
<br>
Line 9: Line 11:
 
==Setup==
 
==Setup==
  
Choose a folder where you will do all your operations and place the following files inside. If you have Megui installed you probably already have the first three files; look in the Megui\Tools directory.
+
Choose a folder where you will do all your operations and place the following files inside.
* [http://www.megui.org/auto/ x264.exe]
+
* [http://www.x264.nl/ x264.exe]
* [http://www.nero.com/nerodigital/eng/Nero_Digital_Audio.html neroaacenc.exe]
+
* [[Media:NeroDigitalAudio.zip|neroaacenc.exe]]
* [http://www.megui.org/auto/ mp4box.exe]
+
* [http://www.videohelp.com/tools/mp4box mp4box.exe]
 
* [[Media:BePipe.zip|BePipe.exe]]
 
* [[Media:BePipe.zip|BePipe.exe]]
* [[Media:Batchfiles.zip|Batch files]]
+
* [[Media:xvid_encraw.zip|xvid_encraw.exe]]
 +
* [[Media:ffmpeg.zip|ffmpeg.exe]]
 
* Your avisynth scripts and source files (if your script uses relative paths)
 
* Your avisynth scripts and source files (if your script uses relative paths)
  
Line 21: Line 24:
 
==The batch files==
 
==The batch files==
  
Parameter list - 2pass.bat
+
Create a batch file by first creating a text document and changing the extension to bat.
 +
 
 +
Parameter list - 2pass
 
* %1 - avisynth script
 
* %1 - avisynth script
 
* %2 - output file name without mp4 extension
 
* %2 - output file name without mp4 extension
Line 30: Line 35:
 
* %7 - delete elementary streams after muxing, 0/blank=off, 1=on
 
* %7 - delete elementary streams after muxing, 0/blank=off, 1=on
  
Parameter list - 1pass.bat
+
Parameter list - 1pass
 
* %1 - avisynth script
 
* %1 - avisynth script
 
* %2 - output file name without mp4 extension
 
* %2 - output file name without mp4 extension
Line 36: Line 41:
 
* %4 - quantizer - 17 should be used for 320x240 resolution, 19 for 640x480 or higher.
 
* %4 - quantizer - 17 should be used for 320x240 resolution, 19 for 640x480 or higher.
 
* %5 - delete elementary streams after muxing, 0/blank=off, 1=on
 
* %5 - delete elementary streams after muxing, 0/blank=off, 1=on
 +
 +
Parameter list - xvid
 +
* %1 - avisynth script
 +
* %2 - output file name without avi extension
 +
* %3 - video bitrate
 +
* %4 - audio bitrate
 +
* %5 - delete stats file, 0=off, 1=on
 +
* %6 - delete elementary video stream, 0=off, 1=on
  
  
'''runatlow.bat''' - This will run encode.bat in low priority mode like Megui does. It will let you run other things while the encoding is taking place without computer lag, though I don't suggest playing cpu intensive games...
+
'''runatlow.bat''' - This will run encode.bat in low priority mode like MeGUI does. It will let you run other things while the encoding is taking place without computer lag, though doing other things will slow down the encoding.
  
 
<pre><nowiki>
 
<pre><nowiki>
Line 44: Line 57:
 
</nowiki></pre>
 
</nowiki></pre>
  
'''encode.bat''' - The main batch file where you do most of the editing. Look at the parameter list to see what the values correspond to. As you can see, starting from the left, %1 refers to Seg1_MQ.avs and you keep going to the right, ending with %7 referring to the value 1 which means the elementary streams will be deleted after being multiplexed.
+
'''encode.bat''' - The main batch file. The call lines are how you set up your jobs. Everything below that you'll change maybe once. Look at the parameter list to see what the values correspond to. As you can see, starting from the left, %1 refers to script_mq.avs and you keep going to the right, ending with %7 referring to the value 1 which means the elementary streams will be deleted after being multiplexed.
  
<pre><nowiki>
+
You need to configure the lines with x264 and xvid to your liking. If you are using MeGUI and already have your own profiles, you can look at the command line by clicking on config and looking at the bottom part of the window. Or don't change anything, the settings here are quite reasonable.
call 2pass.bat Seg1_MQ.avs GodOfWar_god_21623_LQ_part01 128 64000 17 1 1
+
  
call 2pass.bat Seg1_MQ.avs GodOfWar_god_21623_part01 512 64000 17 1 1
+
<font color="green"><b>Tip:</b> You can tell the encoder to skip a call line by typing REM before it.</font>
  
call 2pass.bat Seg1_HQ.avs GodOfWar_god_21623_HQ_part01 2048 128000 19 1 1
+
<pre style="white-space: pre-wrap; white-space: -moz-pre-wrap; white-space: -pre-wrap; white-space: -o-pre-wrap; word-wrap: break-word;"><nowiki>
 +
REM SDA batch encoder v1.1
 +
@echo off
  
call 2pass.bat Seg1_HQ.avs GodOfWar_god_21623_IQ_part01 5000 320000 19 1 1
+
call :2pass script_mq.avs script_lq 128 64000 17 1 1
 +
call :2pass script_mq.avs script_mq 512 64000 17 1 1
 +
call :2pass script_hq.avs script_hq 2048 128000 19 1 1
 +
call :2pass script_hq.avs script_iq 5000 320000 19 1 1
 +
call :1pass script_hq.avs script_qp19_iq 320000 19 1
  
call 1pass.bat Seg1_MQ.avs GodOfWar_god_21623_part01_test 64000 17 0
+
call :xvid script_mq.avs script_mq 512 64 1 1
</nowiki></pre>
+
call :xvid script_mq.avs script_lq 128 64 1 1
  
'''2pass.bat''' - This gets the parameters from encode.bat and does the actual encoding. You need to configure this to your liking. If you are using Megui and already have your own profiles, you can look at the command line by clicking on config and clicking the "show commandline" checkbox at the bottom left.
 
  
<font color="green">Note that line breaks should only occur in the actual batch file where two occur here (e.g. before every occurrence of "X.exe") - additional breaks have been added for formatting purposes here only and will cause the batch file not to work if duplicated.</font>
+
echo Finished!
 +
pause
 +
GOTO :EOF
 +
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
 +
:2pass
  
<pre><nowiki>
+
REM TURBO
x264.exe --pass 1 --bitrate %3 --stats "%2.stats" --ref 8 --mixed-refs --no-fast-pskip --bframes 3
+
x264.exe --pass 1 --bitrate %3 --stats "%~dp1%2.stats" --bframes 5 --direct auto --subme 1 --analyse none --qpmin %5 --me dia --threads auto --thread-input --progress --no-psnr --no-ssim --output NUL %1
--b-rdo --bime --weightb --subme 7 --trellis 1 --analyse p8x8,b8x8,i4x4,p4x4 --qpmin %5  
+
--me umh --progress --no-psnr --output NUL "%1"
+
  
x264.exe --pass 2 --bitrate %3 --stats "%2.stats" --ref 8 --mixed-refs --no-fast-pskip --bframes 3
+
x264.exe --pass 2 --bitrate %3 --stats "%~dp1%2.stats" --ref 8 --mixed-refs --no-fast-pskip --bframes 5 --b-rdo --bime --weightb --direct auto --subme 7 --trellis 1 --analyse p8x8,b8x8,i4x4,p4x4 --qpmin %5 --me umh --threads auto --thread-input --progress --no-psnr --no-ssim --output "%~dp1%2_video.mp4" %1
--b-rdo --bime --weightb --subme 7 --trellis 1 --analyse p8x8,b8x8,i4x4,p4x4 --qpmin %5  
+
--me umh --progress --no-psnr --output "%2_video.mp4" "%1"
+
  
bepipe.exe --script "DirectShowSource(^%1^).Normalize" | "neroAacEnc.exe" -br %4 -lc  
+
bepipe.exe --script "DirectShowSource(^%~f1^)" | "neroAacEnc.exe" -br %4 -lc -if - -of "%~dp1%2_audio.mp4"
-if - -of "%2_audio.mp4"
+
  
MP4Box.exe -new -add "%2_video.mp4" -add "%2_audio.mp4" "%2.mp4"
+
MP4Box.exe -new -add "%~dp1%2_video.mp4" -add "%~dp1%2_audio.mp4" "%~dp1%2.mp4"
  
if "%6" == "1" del %2.stats
+
if "%6" == "1" del "%~dp1%2.stats"
 +
if "%7" == "1" del "%~dp1%2_video.mp4" | del "%~dp1%2_audio.mp4"
  
if "%7" == "1" del %2_video.mp4 | del %2_audio.mp4
+
GOTO :EOF
</nowiki></pre>
+
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
 +
:1pass
  
 +
x264.exe --qp %4 --ref 8 --mixed-refs --no-fast-pskip --bframes 5 --b-rdo --bime --weightb --nf --direct auto --subme 7 --analyse p8x8,b8x8,i4x4,p4x4 --threads auto --thread-input --progress --no-psnr --no-ssim --output "%~dp1%2_video.mp4" %1
  
'''1pass.bat''' - Same as 2pass except the code has only one line to call x264.exe since it is doing a single-pass constant quantizer encoding.
+
bepipe.exe --script "DirectShowSource(^%~f1^)" | "neroAacEnc.exe" -br %3 -lc -if - -of "%~dp1%2_audio.mp4"
  
<pre><nowiki>
+
MP4Box.exe -new -add "%~dp1%2_video.mp4" -add "%~dp1%2_audio.mp4" "%~dp1%2.mp4"
x264.exe --qp %4 --ref 8 --mixed-refs --no-fast-pskip --bframes 3 --b-rdo --bime
+
--weightb --nf --subme 7 --analyse p8x8,b8x8,i4x4,p4x4 --me umh --progress
+
--no-psnr --output "%2_video.mp4" "%1"
+
  
bepipe.exe --script "DirectShowSource(^%1^).Normalize" | "neroAacEnc.exe" -br %3
+
if "%5" == "1" del "%~dp1%2_video.mp4" | del "%~dp1%2_audio.mp4"
-lc -if - -of "%2_audio.mp4"
+
  
MP4Box.exe -new -add "%2_video.mp4" -add "%2_audio.mp4" "%2.mp4"
+
GOTO :EOF
 +
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
 +
:xvid
  
if "%5" == "1" del %2_video.mp4 | del %2_audio.mp4
+
xvid_encraw.exe -i %1 -bitrate %3 -pass1 "%~dp1%2.stats" -kboost 100 -ostrength 15 -oimprove 15 -odegrade 15 -overhead 0 -vhqmode 3 -qpel -gmc -closed_gop -lumimasking -max_bframes 3 -bvhq -threads 1
 +
 
 +
xvid_encraw.exe -i %1 -bitrate %3 -pass2 "%~dp1%2.stats" -avi "%~dp1%2_video.avi" -kboost 100 -ostrength 15 -oimprove 15 -odegrade 15 -overhead 0 -vhqmode 3 -qpel -gmc -closed_gop -lumimasking -max_bframes 3 -bvhq -threads 1
 +
 
 +
bepipe.exe --script "DirectShowSource(^%~f1^)" | lame.exe -b 64 --cbr -h --silent - "%~dp1%2_audio.mp3"
 +
 
 +
ffmpeg.exe -i "%~dp1%2_audio.mp3" -acodec copy -i "%~dp1%2_video.avi" -vcodec copy -y "%~dp1%2.avi"
 +
 
 +
if "%5" == "1" del "%~dp1%2.stats"
 +
 
 +
if "%6" == "1" del "%~dp1%2_video.avi" | del "%~dp1%2_audio.mp3"
 +
 
 +
GOTO :EOF
 
</nowiki></pre>
 
</nowiki></pre>
  
 
<br>
 
<br>
  
==Encoding / disadvantages==
+
==Encoding==
 
+
Most of the work is in setting up encode.bat, starting the encoding is as simple as running runatlow.bat.
+
  
There are some disadvantages to batch file encoding that you should know. In Megui you are able to postpone/delete jobs without interrupting the current encoding job. You can even stop the current job and the program will continue on with the rest. With batch files you'll have to stop the whole process cold, edit encode.bat and then run it again.
+
Most of the work is in setting up encode.bat, starting the encoding is as simple as running runatlow.bat or encode.bat itself.
  
  
 
Return to the [[Main Page|front page]].
 
Return to the [[Main Page|front page]].

Latest revision as of 21:08, 27 October 2007

Introduction

This guide assumes you are familiar with encoding through CLI or you are comfortable with MeGUI.

Why encode with batch files? This is a good question. When you are encoding many videos, you tend to use the same configuration settings for H.264, AAC, Xvid and MP3. You may have even created your own profiles already. Once you are comfortable with MeGUI and realize how easy it is to use, you start getting annoyed of repeatedly clicking the same options. You already know what you want from the start, so why not simplify the process?

However, there are some disadvantages to batch file encoding that you should know. In MeGUI you are able to postpone/delete jobs without interrupting the current encoding job. You can even stop the current job and the program will continue on with the rest. With batch files you'll have to stop the whole process cold, edit encode.bat and then run it again.


Setup

Choose a folder where you will do all your operations and place the following files inside.


The batch files

Create a batch file by first creating a text document and changing the extension to bat.

Parameter list - 2pass

  •  %1 - avisynth script
  •  %2 - output file name without mp4 extension
  •  %3 - video bitrate
  •  %4 - audio bitrate
  •  %5 - minimum quantizer - 17 should be used for 320x240 resolution, 19 for 640x480 or higher.
  •  %6 - delete stats file after encoding, 0=off, 1=on
  •  %7 - delete elementary streams after muxing, 0/blank=off, 1=on

Parameter list - 1pass

  •  %1 - avisynth script
  •  %2 - output file name without mp4 extension
  •  %3 - audio bitrate
  •  %4 - quantizer - 17 should be used for 320x240 resolution, 19 for 640x480 or higher.
  •  %5 - delete elementary streams after muxing, 0/blank=off, 1=on

Parameter list - xvid

  •  %1 - avisynth script
  •  %2 - output file name without avi extension
  •  %3 - video bitrate
  •  %4 - audio bitrate
  •  %5 - delete stats file, 0=off, 1=on
  •  %6 - delete elementary video stream, 0=off, 1=on


runatlow.bat - This will run encode.bat in low priority mode like MeGUI does. It will let you run other things while the encoding is taking place without computer lag, though doing other things will slow down the encoding.

start /LOW /B encode.bat

encode.bat - The main batch file. The call lines are how you set up your jobs. Everything below that you'll change maybe once. Look at the parameter list to see what the values correspond to. As you can see, starting from the left, %1 refers to script_mq.avs and you keep going to the right, ending with %7 referring to the value 1 which means the elementary streams will be deleted after being multiplexed.

You need to configure the lines with x264 and xvid to your liking. If you are using MeGUI and already have your own profiles, you can look at the command line by clicking on config and looking at the bottom part of the window. Or don't change anything, the settings here are quite reasonable.

Tip: You can tell the encoder to skip a call line by typing REM before it.

REM SDA batch encoder v1.1
@echo off

call :2pass script_mq.avs script_lq 128 64000 17 1 1
call :2pass script_mq.avs script_mq 512 64000 17 1 1
call :2pass script_hq.avs script_hq 2048 128000 19 1 1
call :2pass script_hq.avs script_iq 5000 320000 19 1 1
call :1pass script_hq.avs script_qp19_iq 320000 19 1

call :xvid script_mq.avs script_mq 512 64 1 1
call :xvid script_mq.avs script_lq 128 64 1 1


echo Finished!
pause
GOTO :EOF
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:2pass

REM TURBO
x264.exe --pass 1 --bitrate %3 --stats "%~dp1%2.stats" --bframes 5 --direct auto --subme 1 --analyse none --qpmin %5 --me dia --threads auto --thread-input --progress --no-psnr --no-ssim --output NUL %1

x264.exe --pass 2 --bitrate %3 --stats "%~dp1%2.stats" --ref 8 --mixed-refs --no-fast-pskip --bframes 5 --b-rdo --bime --weightb --direct auto --subme 7 --trellis 1 --analyse p8x8,b8x8,i4x4,p4x4 --qpmin %5 --me umh --threads auto --thread-input --progress --no-psnr --no-ssim --output "%~dp1%2_video.mp4" %1

bepipe.exe --script "DirectShowSource(^%~f1^)" | "neroAacEnc.exe" -br %4 -lc -if - -of "%~dp1%2_audio.mp4"

MP4Box.exe -new -add "%~dp1%2_video.mp4" -add "%~dp1%2_audio.mp4" "%~dp1%2.mp4"

if "%6" == "1" del "%~dp1%2.stats"
if "%7" == "1" del "%~dp1%2_video.mp4" | del "%~dp1%2_audio.mp4"

GOTO :EOF
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:1pass

x264.exe --qp %4 --ref 8 --mixed-refs --no-fast-pskip --bframes 5 --b-rdo --bime --weightb --nf --direct auto --subme 7 --analyse p8x8,b8x8,i4x4,p4x4 --threads auto --thread-input --progress --no-psnr --no-ssim --output "%~dp1%2_video.mp4" %1

bepipe.exe --script "DirectShowSource(^%~f1^)" | "neroAacEnc.exe" -br %3 -lc -if - -of "%~dp1%2_audio.mp4"

MP4Box.exe -new -add "%~dp1%2_video.mp4" -add "%~dp1%2_audio.mp4" "%~dp1%2.mp4"

if "%5" == "1" del "%~dp1%2_video.mp4" | del "%~dp1%2_audio.mp4"

GOTO :EOF
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:xvid

xvid_encraw.exe -i %1 -bitrate %3 -pass1 "%~dp1%2.stats" -kboost 100 -ostrength 15 -oimprove 15 -odegrade 15 -overhead 0 -vhqmode 3 -qpel -gmc -closed_gop -lumimasking -max_bframes 3 -bvhq -threads 1

xvid_encraw.exe -i %1 -bitrate %3 -pass2 "%~dp1%2.stats" -avi "%~dp1%2_video.avi" -kboost 100 -ostrength 15 -oimprove 15 -odegrade 15 -overhead 0 -vhqmode 3 -qpel -gmc -closed_gop -lumimasking -max_bframes 3 -bvhq -threads 1

bepipe.exe --script "DirectShowSource(^%~f1^)" | lame.exe -b 64 --cbr -h --silent - "%~dp1%2_audio.mp3"

ffmpeg.exe -i "%~dp1%2_audio.mp3" -acodec copy -i "%~dp1%2_video.avi" -vcodec copy -y "%~dp1%2.avi"

if "%5" == "1" del "%~dp1%2.stats"

if "%6" == "1" del "%~dp1%2_video.avi" | del "%~dp1%2_audio.mp3"

GOTO :EOF


Encoding

Most of the work is in setting up encode.bat, starting the encoding is as simple as running runatlow.bat or encode.bat itself.


Return to the front page.

Personal tools