Skip to content

Video Options

patrickenfuego edited this page Jun 14, 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 in 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 all of the code is written to use the Main 10 profile; however, I do plan on adding it in a future release

You can rescale (upscale/downscale) a video with FFEncoder using the three scaling-related parameters:

  • -Scale (required for rescaling)
  • -ScaleFilter
  • -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). The available options for -ScaleFilter 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

Scaling parameters support tab expansion if you want to view potential options in the CLI. If you attempt to use a filter that is incompatible with the chosen library, FFEncoder will prompt you to re-select a new filter (unless ExitOnError is used).

Example

PS > .\FFEncoder.ps1 input.mkv -CRF 17 -Scale zscale -ScaleFilter spline36 -Resolution 1080p -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. 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 <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 -.


Hard-Coded Parameters

Video encoding is a subjective process, and I have my own personal preferences. The following parameters are hardcoded:

  • no-sao - I really hate the way sao looks, so it's disabled along with selective-sao. There's a reason it's earned the moniker "smooth all objects", and it makes everything look too waxy in my opinion
  • 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

Overriding Parameters

If you dislike my choices, they can be overridden using the -EncoderExtra parameter:

PS > .\FFEncoder.ps1 $InputPath -CRF 18 -EncoderExtra @{ 'sao' = 1 } -o $OutputPath
Clone this wiki locally