![light2xx]()
A guide for encoding through CLI (Command Line Interface)
(Update |12 July, 2013| : Dual Audio Commands)
GUI vs. Command Line (cmd)
The reason of using cmd is that it won’t restrict you. You can do everything that an encoder (x264.exe) can do. However, in a GUI you have to follow the GUI’s limitations. For instance you can’t use AQ-Method (3 and 4), as a GUI would not recognize / approve that command. As a result, you’ll either get an error or GUI will force the program to close.
And cmd is very easy to use and it’s very diverse. You just need to get used to it. (It gives a cool impression too xD. When you hear a hacker hacked an account, first thing you say is “awesome, he hacked it”, not why? or how? XD)
How to use Command Line
Things that you need to get before encoding via CLI.
1- ffmpeg.exe – Put the (.exe) file after Dling, no installation.
2- 10-bit, x264.exe (video and audio encoder) – Put the (.exe) file after Dling, no installation.
3- neroAacEnc.exe (only audio encoder) – Put the (.exe) file after Dling, no installation.
4- mkvmerge.exe (Optional) – DL it, Install it and get the (.exe) from there.
I recommed that you use 32-bit, or x86, versions.
Creating a Command (Line)
- Command Line Interface will do some work only when you give some valid command to the system.
- Commands can be written on notepad, any text editor, or CLI window.
- If you are writing the commands on any text editor, it will probably be saved in (.txt) format by default. That won’t activate CLI. You’ll have to save your written code in (.bat) format. To do that simply hit “Save as” and at the end of the filename add (.bat) extension.
- If you run (double click) any (.bat) file, the commands written inside the (.bat) files would be forwarded to system and if they are valid they’ll be processed, otherwise CLI window will be closed automatically without doing anything.
- It means that all you need to do for CLI-encoding is write valid commands, save it in (.bat) file and run it later on. Encoding will start as according to what’s written in the (.bat) file.
General Info of writing Commands
I won’t talk about heavy and complex commands, rather just skim over general idea of command formatting.
Executable_file(.exe) commands_specific_to_that_(.exe)_file
Executable file could be anyone like mkvmerge.exe -or- x264.exe
To know what kind of commands / features can be used for a mentioned (.exe) file you need to have some knowledge. Like:
neroAacEnc.exe -ignorelength -lc -q 0.5 -if - -of encoded_audio.aac
It can be gained via browsing internet, personal experience, and logfiles etc.
As this is a guide, I’ll make sure to let you know the requisite commands to encode a video file.
Settings from Logfiles
Well, every (.exe) file has a logfile which explains the settings, or features, that can be done. To get the logfile of any (.exe.) via CMD, you’ll have to make a short command. This will also serve as a practical of making a (.bat) file.
Make a new folder, somewhere nice. Place following files in it.
- ffmpeg.exe
- x264.exe
- neroAacEnc.exe
- mkvmerge.exe
Open a notepad, and write this:
x264.exe --fullhelp
@pause
Save this file by hitting “Save as”. Name it whatever you wanna name it, but select the extension (.bat); after that, save it in the same folder. It will be appeared as a “Windows Batch File (.bat)”. Run it by double-clicking. You’ll get something like this.
x264 --fullhelp
x264 core:120 r2120 0c7dab9
Syntax: x264 [options] -o outfile infile
Infile can be raw (in which case resolution is required),
or YUV4MPEG (*.y4m),
or Avisynth if compiled with support (yes).
or libav* formats if compiled with lavf support (yes) or ffms support (yes).
Outfile type is selected by filename:
.264 -> Raw bytestream
.mkv -> Matroska
.flv -> Flash Video
.mp4 -> MP4 if compiled with GPAC support (yes)
Output bit depth: 10 (configured at compile time)
Options:
-h, --help List basic options
--longhelp List more options
--fullhelp List all options
Example usage:
Constant quality mode:
x264 --crf 24 -o (output) (input)
Two-pass with a bitrate of 1000kbps:
x264 --pass 1 --bitrate 1000 -o (output) (input)
x264 --pass 2 --bitrate 1000 -o (output) (input)
Lossless:
x264 --qp 0 -o (output) (input)
Maximum PSNR at the cost of speed and visual quality:
x264 --preset placebo --tune psnr -o (output) (input)
Constant bitrate at 1000kbps with a 2 second-buffer:
x264 --vbv-bufsize 2000 --bitrate 1000 -o (output) (input)
Presets:
--profile Force the limits of an H.264 profile
Overrides all settings.
- high10:
No lossless.
Support for bit depth 8-10.
- high422:
No lossless.
Support for bit depth 8-10.
Support for 4:2:0/4:2:2 chroma subsampling.
- high444:
Support for bit depth 8-10.
Support for 4:2:0/4:2:2/4:4:4 chroma subsampling.
--preset Use a preset to select encoding settings [medium]
Overridden by user settings.
- ultrafast:
--no-8x8dct --aq-mode 0 --b-adapt 0
--bframes 0 --no-cabac --no-deblock
--no-mbtree --me dia --no-mixed-refs
--partitions none --rc-lookahead 0 --ref 1
--scenecut 0 --subme 0 --trellis 0
--no-weightb --weightp 0
- superfast:
--no-mbtree --me dia --no-mixed-refs
--partitions i8x8,i4x4 --rc-lookahead 0
--ref 1 --subme 1 --trellis 0 --weightp 1
- veryfast:
--no-mixed-refs --rc-lookahead 10
--ref 1 --subme 2 --trellis 0 --weightp 1
- faster:
--no-mixed-refs --rc-lookahead 20
--ref 2 --subme 4 --weightp 1
- fast:
--rc-lookahead 30 --ref 2 --subme 6
--weightp 1
- medium:
Default settings apply.
- slow:
--b-adapt 2 --direct auto --me umh
--rc-lookahead 50 --ref 5 --subme 8
- slower:
--b-adapt 2 --direct auto --me umh
--partitions all --rc-lookahead 60
--ref 8 --subme 9 --trellis 2
- veryslow:
--b-adapt 2 --bframes 8 --direct auto
--me umh --merange 24 --partitions all
--ref 16 --subme 10 --trellis 2
--rc-lookahead 60
- placebo:
--bframes 16 --b-adapt 2 --direct auto
--slow-firstpass --no-fast-pskip
--me tesa --merange 24 --partitions all
--rc-lookahead 60 --ref 16 --subme 11
--trellis 2
--tune Tune the settings for a particular type of source
or situation
Overridden by user settings.
Multiple tunings are separated by commas.
Only one psy tuning can be used at a time.
- film (psy tuning):
--deblock -1:-1 --psy-rd :0.15
- animation (psy tuning):
--bframes {+2} --deblock 1:1
--psy-rd 0.4: --aq-strength 0.6
--ref {Double if >1 else 1}
- grain (psy tuning):
--aq-strength 0.5 --no-dct-decimate
--deadzone-inter 6 --deadzone-intra 6
--deblock -2:-2 --ipratio 1.1
--pbratio 1.1 --psy-rd :0.25
--qcomp 0.8
- stillimage (psy tuning):
--aq-strength 1.2 --deblock -3:-3
--psy-rd 2.0:0.7
- psnr (psy tuning):
--aq-mode 0 --no-psy
- ssim (psy tuning):
--aq-mode 2 --no-psy
- fastdecode:
--no-cabac --no-deblock --no-weightb
--weightp 0
- zerolatency:
--bframes 0 --force-cfr --no-mbtree
--sync-lookahead 0 --sliced-threads
--rc-lookahead 0
--slow-firstpass Don't force these faster settings with --pass 1:
--no-8x8dct --me dia --partitions none
--ref 1 --subme {2 if >2 else unchanged}
--trellis 0 --fast-pskip
Frame-type options:
-I, --keyint Maximum GOP size [250]
-i, --min-keyint Minimum GOP size [auto]
--no-scenecut Disable adaptive I-frame decision
--scenecut How aggressively to insert extra I-frames [40]
--intra-refresh Use Periodic Intra Refresh instead of IDR frames
-b, --bframes Number of B-frames between I and P [3]
--b-adapt Adaptive B-frame decision method [1]
Higher values may lower threading efficiency.
- 0: Disabled
- 1: Fast
- 2: Optimal (slow with high --bframes)
--b-bias Influences how often B-frames are used [0]
--b-pyramid Keep some B-frames as references [normal]
- none: Disabled
- strict: Strictly hierarchical pyramid
- normal: Non-strict (not Blu-ray compatible)
--open-gop Use recovery points to close GOPs
Only available with b-frames
--no-cabac Disable CABAC
-r, --ref Number of reference frames [3]
--no-deblock Disable loop filter
-f, --deblock Loop filter parameters [0:0]
--slices Number of slices per frame; forces rectangular
slices and is overridden by other slicing options
--slice-max-size Limit the size of each slice in bytes
--slice-max-mbs Limit the size of each slice in macroblocks
--tff Enable interlaced mode (top field first)
--bff Enable interlaced mode (bottom field first)
--constrained-intra Enable constrained intra prediction.
--pulldown Use soft pulldown to change frame rate
- none, 22, 32, 64, double, triple, euro (requires cfr input)
--fake-interlaced Flag stream as interlaced but encode progressive.
Makes it possible to encode 25p and 30p Blu-Ray
streams. Ignored in interlaced mode.
--frame-packing For stereoscopic videos define frame arrangement
- 0: checkerboard - pixels are alternatively from L and R
- 1: column alternation - L and R are interlaced by column
- 2: row alternation - L and R are interlaced by row
- 3: side by side - L is on the left, R on the right
- 4: top bottom - L is on top, R on bottom
- 5: frame alternation - one view per frame
Ratecontrol:
-q, --qp Force constant QP (0-81, 0=lossless)
-B, --bitrate Set bitrate (kbit/s)
--crf Quality-based VBR (-12-51) [23.0]
--rc-lookahead Number of frames for frametype lookahead [40]
--vbv-maxrate Max local bitrate (kbit/s) [0]
--vbv-bufsize Set size of the VBV buffer (kbit) [0]
--vbv-init Initial VBV buffer occupancy [0.9]
--crf-max With CRF+VBV, limit RF to this value
May cause VBV underflows!
--qpmin Set min QP [0]
--qpmax Set max QP [81]
--qpstep Set max QP step [4]
--ratetol Tolerance of ABR ratecontrol and VBV [1.0]
--ipratio QP factor between I and P [1.40]
--pbratio QP factor between P and B [1.30]
--chroma-qp-offset QP difference between chroma and luma [0]
--aq-mode AQ method [1]
- 0: Disabled
- 1: Variance AQ (complexity mask)
- 2: Auto-variance AQ (experimental)
--aq-strength Reduces blocking and blurring in flat and
textured areas. [1.0]
-p, --pass Enable multipass ratecontrol
- 1: First pass, creates stats file
- 2: Last pass, does not overwrite stats file
- 3: Nth pass, overwrites stats file
--stats Filename for 2 pass stats ["x264_2pass.log"]
--no-mbtree Disable mb-tree ratecontrol.
--qcomp QP curve compression [0.60]
--cplxblur Reduce fluctuations in QP (before curve compression) [20.0]
--qblur Reduce fluctuations in QP (after curve compression) [0.5]
--zones //... Tweak the bitrate of regions of the video
Each zone is of the form
,,
where
is either
q= (force QP)
or b= (bitrate multiplier)
--qpfile Force frametypes and QPs for some or all frames
Format of each line: framenumber frametype QP
QP is optional (none lets x264 choose). Frametypes: I,i,K,P,B,b.
K= depending on open-gop setting
QPs are restricted by qpmin/qpmax.
Analysis:
-A, --partitions Partitions to consider ["p8x8,b8x8,i8x8,i4x4"]
- p8x8, p4x4, b8x8, i8x8, i4x4
- none, all
(p4x4 requires p8x8. i8x8 requires --8x8dct.)
--direct Direct MV prediction mode ["spatial"]
- none, spatial, temporal, auto
--no-weightb Disable weighted prediction for B-frames
--weightp Weighted prediction for P-frames [2]
- 0: Disabled
- 1: Weighted refs
- 2: Weighted refs + Duplicates
--me Integer pixel motion estimation method ["hex"]
- dia: diamond search, radius 1 (fast)
- hex: hexagonal search, radius 2
- umh: uneven multi-hexagon search
- esa: exhaustive search
- tesa: hadamard exhaustive search (slow)
--merange Maximum motion vector search range [16]
--mvrange Maximum motion vector length [-1 (auto)]
--mvrange-thread Minimum buffer between threads [-1 (auto)]
-m, --subme Subpixel motion estimation and mode decision [7]
- 0: fullpel only (not recommended)
- 1: SAD mode decision, one qpel iteration
- 2: SATD mode decision
- 3-5: Progressively more qpel
- 6: RD mode decision for I/P-frames
- 7: RD mode decision for all frames
- 8: RD refinement for I/P-frames
- 9: RD refinement for all frames
- 10: QP-RD - requires trellis=2, aq-mode>0
- 11: Full RD: disable all early terminations
--psy-rd Strength of psychovisual optimization ["1.0:0.0"]
#1: RD (requires subme>=6)
#2: Trellis (requires trellis, experimental)
--no-psy Disable all visual optimizations that worsen
both PSNR and SSIM.
--no-mixed-refs Don't decide references on a per partition basis
--no-chroma-me Ignore chroma in motion estimation
--no-8x8dct Disable adaptive spatial transform size
-t, --trellis Trellis RD quantization. [1]
- 0: disabled
- 1: enabled only on the final encode of a MB
- 2: enabled on all mode decisions
--no-fast-pskip Disables early SKIP detection on P-frames
--no-dct-decimate Disables coefficient thresholding on P-frames
--nr Noise reduction [0]
--deadzone-inter Set the size of the inter luma quantization deadzone [21]
--deadzone-intra Set the size of the intra luma quantization deadzone [11]
Deadzones should be in the range 0 - 32.
--cqm Preset quant matrices ["flat"]
- jvt, flat
--cqmfile Read custom quant matrices from a JM-compatible file
Overrides any other --cqm* options.
--cqm4 Set all 4x4 quant matrices
Takes a comma-separated list of 16 integers.
--cqm8 Set all 8x8 quant matrices
Takes a comma-separated list of 64 integers.
--cqm4i, --cqm4p, --cqm8i, --cqm8p
Set both luma and chroma quant matrices
--cqm4iy, --cqm4ic, --cqm4py, --cqm4pc
Set individual quant matrices
Video Usability Info (Annex E):
The VUI settings are not used by the encoder but are merely suggestions to
the playback equipment. See doc/vui.txt for details. Use at your own risk.
--overscan Specify crop overscan setting ["undef"]
- undef, show, crop
--videoformat Specify video format ["undef"]
- component, pal, ntsc, secam, mac, undef
--range Specify color range ["auto"]
- auto, tv, pc
--colorprim Specify color primaries ["undef"]
- undef, bt709, bt470m, bt470bg
smpte170m, smpte240m, film
--transfer Specify transfer characteristics ["undef"]
- undef, bt709, bt470m, bt470bg, linear,
log100, log316, smpte170m, smpte240m
--colormatrix Specify color matrix setting ["???"]
- undef, bt709, fcc, bt470bg
smpte170m, smpte240m, GBR, YCgCo
--chromaloc Specify chroma sample location (0 to 5) [0]
--nal-hrd Signal HRD information (requires vbv-bufsize)
- none, vbr, cbr (cbr not allowed in .mp4)
--pic-struct Force pic_struct in Picture Timing SEI
--crop-rect Add 'left,top,right,bottom' to the bitstream-level
cropping rectangle
Input/Output:
-o, --output Specify output file
--muxer Specify output container format ["auto"]
- auto, raw, mkv, flv, mp4
--demuxer Specify input container format ["auto"]
- auto, raw, y4m, avs, lavf, ffms
--input-fmt Specify input file format (requires lavf support)
--input-csp Specify input colorspace format for raw input
- valid csps for `raw' demuxer:
i420, yv12, nv12, i422, yv16, nv16, i444, yv24, bgr, bgra, rgb
- valid csps for `lavf' demuxer:
yuv420p, yuyv422, rgb24, bgr24, yuv422p,
yuv444p, yuv410p, yuv411p, gray, monow, monob,
pal8, yuvj420p, yuvj422p, yuvj444p, xvmcmc,
xvmcidct, uyvy422, uyyvyy411, bgr8, bgr4,
bgr4_byte, rgb8, rgb4, rgb4_byte, nv12, nv21,
argb, rgba, abgr, bgra, gray16be, gray16le,
yuv440p, yuvj440p, yuva420p, vdpau_h264,
vdpau_mpeg1, vdpau_mpeg2, vdpau_wmv3,
vdpau_vc1, rgb48be, rgb48le, rgb565be,
rgb565le, rgb555be, rgb555le, bgr565be,
bgr565le, bgr555be, bgr555le, vaapi_moco,
vaapi_idct, vaapi_vld, yuv420p16le,
yuv420p16be, yuv422p16le, yuv422p16be,
yuv444p16le, yuv444p16be, vdpau_mpeg4,
dxva2_vld, rgb444le, rgb444be, bgr444le,
bgr444be, y400a, bgr48be, bgr48le, yuv420p9be,
yuv420p9le, yuv420p10be, yuv420p10le,
yuv422p10be, yuv422p10le, yuv444p9be,
yuv444p9le, yuv444p10be, yuv444p10le,
yuv422p9be, yuv422p9le, vda_vld, gbrp, gbrp9be,
gbrp9le, gbrp10be, gbrp10le, gbrp16be,
gbrp16le
--output-csp Specify output colorspace ["i420"]
- i420, i422, i444, rgb
--input-depth Specify input bit depth for raw input
--input-range Specify input color range ["auto"]
- auto, tv, pc
--input-res Specify input resolution (width x height)
--index Filename for input index file
--sar width:height Specify Sample Aspect Ratio
--fps <float|rational> Specify framerate
--seek First frame to encode
--frames Maximum number of frames to encode
--level Specify level (as defined by Annex A)
--bluray-compat Enable compatibility hacks for Blu-ray support
-v, --verbose Print stats for each frame
--no-progress Don't show the progress indicator while encoding
--quiet Quiet Mode
--log-level Specify the maximum level of logging ["info"]
- none, error, warning, info, debug
--psnr Enable PSNR computation
--ssim Enable SSIM computation
--threads Force a specific number of threads
--sliced-threads Low-latency but lower-efficiency threading
--thread-input Run Avisynth in its own thread
--sync-lookahead Number of buffer frames for threaded lookahead
--non-deterministic Slightly improve quality of SMP, at the cost of repeatability
--cpu-independent Ensure exact reproducibility across different cpus,
as opposed to letting them select different algorithms
--asm Override CPU detection
--no-asm Disable all CPU optimizations
--visualize Show MB types overlayed on the encoded video
--dump-yuv Save reconstructed frames
--sps-id Set SPS and PPS id numbers [0]
--aud Use access unit delimiters
--force-cfr Force constant framerate timestamp generation
--tcfile-in Force timestamp generation with timecode file
--tcfile-out Output timecode v2 file from input timestamps
--timebase <int/int> Specify timebase numerator and denominator
Specify timebase numerator for input timecode file
or specify timebase denominator for other input
--dts-compress Eliminate initial delay with container DTS hack
Filtering:
--vf, --video-filter //... Apply video filtering to the input file
Filter options may be specified in :
= format.
Available filters:
crop:left,top,right,bottom
removes pixels from the edges of the frame
resize:[width,height][,sar][,fittobox][,csp][,method]
resizes frames based on the given criteria:
- resolution only: resizes and adapts sar to avoid stretching
- sar only: sets the sar and resizes to avoid stretching
- resolution and sar: resizes to given resolution and sets the sar
- fittobox: resizes the video based on the desired constraints
- width, height, both
- fittobox and sar: same as above except with specified sar
- csp: convert to the given csp. syntax: [name][:depth]
- valid csp names [keep current]: i420, yv12, nv12, i422, yv16, nv16, i444, yv24, bgr, bgra, rgb
- depth: 8 or 16 bits per pixel [keep current]
note: not all depths are supported by all csps.
- method: use resizer method ["bicubic"]
- fastbilinear, bilinear, bicubic, experimental, point,
- area, bicublin, gauss, sinc, lanczos, spline
select_every:step,offset1[,...]
apply a selection pattern to input frames
step: the number of frames in the pattern
offsets: the offset into the step to select a frame
see: http://avisynth.org/mediawiki/Select#SelectEvery
Press any key to continue . . .
This shows all the settings / presets / features that x264.exe can provide.
Similarly, you can get the same info for other (.exe) files.
Command for neroAacEnc.exe help:
neroAacEnc.exe -help
@pause
Command for ffmpeg.exe help:
ffmpeg.exe -h full
@pause
It will prove quite eye straining at first, as there are hell of settings etc. Once you get used to it, it’ll become a routine work.
Good news you don’t have to go through this necessarily, I’ll tell you what commands to use to encode a file. Rest is for your own interest.
Commands for Encoding a File
I’ll keep things focused to CLI so I’ll just tell what command to write rather than detailing about why using what features etc.
a) Video Encoding – Command
x264 --level 5.1 --preset veryslow --tune animation --crf 23.0 --min-keyint 12 --scenecut 45 --bframes 8 --b-adapt 2 --ref 10 --weightp 2 --qpmin 10 --qpmax 51 --qcomp 0.6 --rc-lookahead 40 --direct auto --aq-mode 1 --aq-strength 0.8 --merange 24 --me umh --subme 10 --trellis 2 --psy-rd 0.40:0.60 --acodec none --output "Output.mkv" "Input.mkv"
- Input.mkv will be the file you want to encode.
- Output.mkv will be the file (video only) you’ll get after encoding is done. Name it whatever you want, except that it shouldn’t be the same as Input.mkv name. If the output name is same it will replace the input.mkv immediately and you’ll lost your input file resulting in no encoding and lost of input file.
Usually, you can encode audio by x264.exe, but I have disabled it. I use neroAacEnc.exe to encode audio separately.
b) Audio Encoding – Command
ffmpeg -i Input.mkv -f wav -| neroAacEnc -ignorelength -lc -q 0.4 -if - -of Output_Audio.aac
- Input.mkv is the same file you used for Video Encoding.
- Output_Audio.aac will be the file (audio only) you’d get after audio encoding.
b-extra) Dual-Audio Encoding
Dual Audio contains two audios. (Can’t believe I’m explaining this XD) Anyhow, to encode both audios you’ll have to use a setting that will pick both audios one by one.
To get a hold of it, you need to know a bit about:
- Tracks IDs in a file.
- ffmpeg mapping.
- Commanding ffmpeg to map it.
a) Tracks and IDs
Each file has more than one tracks and each track has a respective ID. ID can be seen via MediaInfo or MkvHeaderEditor.
For example a usual episode from a decent fansubbed group has following things.
- Video Track – ID 1
- Japanese Audio Track – ID 2
- English Subtitle Track – ID 3
(Chapters and fonts are not tracks, but mere attachments.)
If the source is a Dual Audio, then usually it has following things.
- Video Track – ID 1
- Japanese Audio Track – ID 2
- English Audio Track – ID 3
- English Subtitle Track – ID 4
b) ffmpeg mapping
ffmpeg has a ability to take more than one inputs simultaneously. Usually that is helpful while merging different tracks from more than one files.
ffmpeg also has a feature -map, that picks the tracks of file specifically.
Syntax: -map<space><File Input order number>:<Track ID>
Example: A file with audio track ID 3 will be picked up with this value.
-map 0:2 (First file : Track with ID 3)
You must have noticed that for first file I have used 0 and for ID 3 I have used 2 in the map values. It’s because the indexing starts with 0, not 1. To explain it, see below samples.
-map 0:0 (First file : Track with ID 1)
-map 0:1 (First file : Track with ID 2)
-map 2:5 (3rd file : Track with ID 6)
-map x:y (x+1 file : Track with ID y+1), Generic form for understanding it.
c) Dual Audio – Commands
Let’s say I have a file with these details.
- Video Track – ID 1
- Jap Audio – ID 2 (-map 0:1)
- English Subtitles – ID 3
- English Signs – ID 4
- English Audio – ID 5 (-map 0:4)
To encode both audios I’ll use the following commands.
ffmpeg -i Input.mkv -map 0:1 -f wav -| neroAacEnc -ignorelength -lc -q 0.5 -if - -of Output_Audio_JAP.aac
ffmpeg -i Input.mkv -map 0:4 -f wav -| neroAacEnc -ignorelength -lc -q 0.5 -if - -of Output_Audio_ENG.aac
- The mapping will get the audio streams and will forward them to neroAacEnc.exe
- Keep in mind that if you map a wrong stream (like any video or subtitle) and forward it to nero, it’ll will give error as nero is for Audio only.
c) Merging files – Command
mkvmerge -o "Final_File.mkv" --language "0:jpn" --track-name "0:Hi10 Encode @ CRF 23" "Output.mkv" --no-chapters --language "0:jpn" --track-name "0:2.0 AAC-LC @ 0.4" "Output_Audio.aac" -A -D --language "2:eng" --track-name "2:Styled Subtitle (.ass)" "Input.mkv"
- Final_File.mkv will be file (including video, audio, subs, fonts, chapters) you’d get after merging.
- Output.mkv is the file you get from Video Encoding.
- Output_Audio.aac is the file you get from Audio Encoding.
- Input.mkv is the file you already have. (Source file you wanted to encode.)
Sample (.bat) file
This is the (.bat) file I used for Hataraku Maou-sama!
x264_32_tMod-10bit-all --level 5.1 --preset veryslow --tune animation --crf 23.0 --min-keyint 12 --scenecut 45 --bframes 8 --b-adapt 2 --ref 10 --weightp 2 --qpmin 10 --qpmax 51 --qcomp 0.6 --rc-lookahead 40 --direct auto --aq-mode 3 --aq-strength 0.8 --merange 24 --me umh --subme 10 --trellis 2 --psy-rd 0.40:0.60 --acodec none --stylish --output "Output.mkv" "Input.mkv"
ffmpeg -i Input.mkv -f wav -| neroAacEnc -ignorelength -lc -q 0.4 -if - -of Output_Audio.aac
mkvmerge -o "Final_File.mkv" --language "0:jpn" --track-name "0:Hi10 Encode @ CRF 23" "Output.mkv" --no-chapters --language "0:jpn" --track-name "0:2.0 AAC-LC @ 0.4" "Output_Audio.aac" -A -D --language "2:eng" --track-name "2:Styled Subtitle (.ass)" "Input.mkv"
@pause
- Note that I use x264_32_tMod-10bit-all (a better built), instead of regular x264.exe built. You don’t have to get it for now. Just play with regular built and when you get a hold of it, you can broaden your horizons.
- @pause avoids the CMD to close automatically after finishing. It also let us see if the process was successful or not. Otherwise the cmd closes so quickly that you don’t get to see if the command you ran was correct or not.
Batch Encoding
- No special trick, just copy paste the command of one encode for more than one files.
- But keep in mind that you’ll have to consider the naming. If you use Input.mkv for all input files and output.mkv for all output files, they’d replaced by latest files. That’s why I usually use numbering in files.
For example:
- Source of Hataraku Maou-sama Episode 10 = “HM-10.mkv”
- V.Encode of Hataraku Maou-sama Episode 10 = “HM-10_Enc.mkv”
- A.Encode of Hataraku Maou-sama Episode 10 = “HM-10_Aud.aac”
- For merging, “(Hi10)_Hataraku_Maou_-_sama!_-_xx_(720p)_(FFF).mkv”
You can choose your own naming technique whatsoever.
Tips
a) Keep Things Organized
- Make a Special folder for just encoding. -or- CLI-Encoding. Place all necessary (.exe) files there.
- I make (.bat) file for each Anime Series I encode.
- When a file is needed to be encoded, place that file in that special folder and run (.bat) file for that series.
- After encoding, get the final output file and place it wherever you like.
b) Never stick to being normal
- After getting the hold of CLI-encoding, try to experiment.
- My guide on encoding settings is the result of experimenting.
- If you are a CS or SE student, you’d surely find it interesting. But if you aren’t, well, it’s alway good to have a bit of a knowledge of computer.
- It’s a lot of fun. You can try any weird thing like putting your computer to sleep after encoding is done. (Nice trick for laptops, by the way.)
- In my opinion, if you are just encoding for sticking to some settings then there’s no fun in using CLI. Pro uses CLI because pro always seeks more and it’s easily achievable via CLI.
Off-topic
- There is a way to merge files with ffmpeg, but it seems to give stuttering error for EVR (custom) video renderer in MPC-HC.
- Cuticle Tantei Inaba
- Read the comments, and you’ll get the idea. As noobs don’t know how to change video renderer, they thing the file is corrupted / wrong. But it’s not.
- Side-Note: The cause of this stuttering is -lavf encoder. It’s a thing that really doesn’t need to be explained here. But if you are interested, let me know by commenting below. I’ll edit it by adding details.
_____________________________________________________
(Update |12 July, 2013| : Dual Audio Commands)