-
Notifications
You must be signed in to change notification settings - Fork 1
Video Options
FFEncoder supports three options for tuning the first pass of a two pass encode. This setting is only available with x265, as x264 already performs certain optimizations during the first pass unless the slow-firstpass
parameter is used:
Arguments | Affected Parameters | Description |
---|---|---|
Default /d
|
None | Uses the same settings for both passes, and is the slowest option. This is the default setting |
Fast /f
|
rect=0 amp=0 max-merge=1 fast-intra=1 fast-intra=1 early-skip=1 rd=2 subme=2 me=0 ref=1
|
This is essentially equivalent to using the --no-slow-firstpass in x265 |
Custom /c
|
rect=0 amp=0 max-merge=2 subme=2
|
My own custom settings, meant to strike a compromise between the speed of Fast and quality of Default
|
NOTE: Dithering is currently not supported with scaling, as most of the code is written to use the
Main 10
profile; however, I do plan on adding it very soon.
You can rescale (upscale/downscale) a video with FFEncoder using the two scaling-related parameters:
-Scale
-Resolution
The script currently supports three resolutions to which you can scale between: 2160p, 1080p, and 720p. Rescaling retains SAR (source aspect ratio) and will use the input cropping width to determine the aspect ratio (it will also work with overridden crop values passed via -FFMpegExtra
- see below). The available options for -Scale
depend on the scaling library used:
Library | Available Options |
---|---|
scale (ffmpeg default) |
fast_bilinear, bilinear, bicubic, neighbor, area, bicublin, gauss, sinc, lanczos, spline |
zscale |
point, bilinear, bicubic, spline16, spline36, lanczos |
If you choose an option common to both libraries, FFEncoder will automatically use zscale
if available as it is the superior option, although this requires that the --enable-libzimg
flag be present during ffmpeg compilation.
Scaling parameters support tab expansion if you want to view potential options in the CLI. FFEncoder will implicitly check that you have selected a scaling option available in your ffmpeg compilation, and if not, it will prompt you to re-select a new option with a timed input prompt; if you don't enter a valid argument within the timeout period, the script will warn you but continue without scaling.
PS > .\FFEncoder.ps1 input.mkv -CRF 17 -Scale spline36 -Resolution 1080p -o out.mkv
You can sharpen or blur a video using the -Unsharp
/ -UnsharpStrength
parameters. These options are especially useful when rescaling a video, as it can introduce some aliasing or unwanted sharpening. -Unsharp
is required to enable this feature, while -UnsharpStrength
is optional.
Several presets are available for each parameter to make things easier:
This parameter controls the search area of the filter, with larger presets covering more area.
luma_small
luma_medium
luma_large
chroma_small
chroma_medium
chroma_large
yuv_small
yuv_medium
yuv_large
custom=<custom_filter_string>
This parameter controls the strength and type of the filter (blur or sharpen), and is optional. the default value is sharpen_mild
if unspecified.
sharpen_mild
sharpen_medium
sharpen_strong
blur_mild
blur_medium
blur_strong
A basic example:
PS > FFEncoder.ps1 'in.mkv' -CRF 18 -Unsharp luma_medium -UnsharpStrength sharpen_mild -o 'out.mkv'
If you don't wish to use a preset, you can pass a custom filter argument, too:
PS > FFEncoder.ps1 'in.mkv' -CRF 18 -Unsharp 'custom=lx=13:ly=13:la=2.5' -o 'out.mkv'
If a custom filter string is passed, -UnsharpStrength
is ignored.
WARNING: The script does not check syntax, and assumes you know what you're doing. Be sure to test!
You can pass additional arguments not provided by the script to both ffmpeg and x265 using the -FFMpegExtra
and -x265Extra
parameters, respectively.
FFMpegExtra
accepts a generic array that can receive single and multi-valued arguments. For options that receive no argument, i.e. stats/nostats
, pass it as a single element; otherwise, use a hashtable. For example:
#Pass additional arguments to ffmpeg using an array with a hashtable and a single value
PS > .\FFEncoder.ps1 $InputPath -CRF 18 -FFMpegExtra @{ '-t' = 20; '-stats_period' = 5 }, '-shortest' `
>> -o $OutputPath
If you don't want the script to automatically crop the encode for you (for example, if there are dirty lines the function isn't detecting), you can pass custom crop values using -FFMpegExtra
:
PS > .\FFEncoder.ps1 $InputPath -CRF 18 -FFMpegExtra @{ '-vf' = 'crop=w=1920:h=792' } -o $OutputPath
EncoderExtra
accepts a hashtable of values as input, in the form of <key = value>
. For example:
PS > .\FFEncoder.ps1 $InputPath -CRF 18 -EncoderExtra @{ 'max-merge' = 1; 'max-tu-size' = 16 } -o $OutputPath
Quotes are only required if the parameter name includes special characters, like a -
.
Video encoding is a subjective process, and I have my own personal preferences. The following parameters are hardcoded:
-
no-open-gop
- The UHD BD specification recommends that closed GOPs be used. in general, closed GOPs are preferred for streaming content. x264 uses closed GOPs by default -
keyint
/min-keyint
- These are hardcoded at 192/24 to shorten the GOP lengths, thus improving seeking speeds. It has a trivial effect on bitrate
If you dislike my choices, they can be overridden using the -EncoderExtra
parameter:
PS > .\FFEncoder.ps1 $InputPath -CRF 18 -EncoderExtra @{ keyint = 240; 'min-keyint' = 23 } -o $OutputPath