Skip to content

Video Options

patrickenfuego edited this page Aug 19, 2022 · 10 revisions

Two Pass Encoding 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

Rescaling Videos

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.

Example

PS > .\FFEncoder.ps1 input.mkv -CRF 17 -Scale spline36 -Resolution 1080p -o out.mkv

Using the Unsharp Filter

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, and both support tab expansion.

Options for -Unsharp

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>

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'

Options for -UnsharpStrength

NOTE: If a custom filter string is passed to -Unsharp, -UnsharpStrength is ignored.

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'

Using the Extra Parameter Options

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

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 with the form <setting_name = value>. 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

Overriding Crop Arguments

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

EncoderExtra accepts a hashtable of values as input, in the form of <setting_name = value>. For example:

PS > .\FFEncoder.ps1 $InputPath -Encoder x265 -CRF 18 -EncoderExtra @{ 'max-merge' = 1; 'max-tu-size' = 16 } `
>>    -o $OutputPath

Quoting the key (or setting name) is only required when it includes special characters, like a -.