Skip to content

FFmpeg H264

Low latency streaming

For latency-sensitive outputs you can reduce the delay introduced by the encoder itself with ffmpeg_options:

"ffmpeg_options": {
"tune": "zerolatency",
"thread_type": "slice"
}
  • tune: "zerolatency" (libx264) — disables frame lookahead, B-frames and other internal buffering, so every frame is emitted as soon as it is encoded instead of being held back by several frames. Costs some compression efficiency.
  • thread_type: "slice" — by default FFmpeg parallelizes encoding across frames, which delays output by roughly one frame per thread. Slice-based threading splits each frame into slices encoded in parallel, so multithreading adds no extra frame delay, at a small quality cost.

Encoder selection

FFmpeg picks whichever H.264 encoder is available in the build it was compiled with. Smelter passes a different set of default options depending on which encoder was picked. Anything you set in ffmpeg_options is applied on top of these defaults and overrides them.

libopenh264

Default options:

qmin=4 # minimum QP
qmax=51 # maximum QP, increased vs the encoder default to allow
# low bitrates without dropping frames
rc_mode=0 # rate control mode: quality
threads=0 # auto-detect thread count
b=... # average bitrate, from "bitrate" or calculated
# from resolution and framerate
maxrate=... # maximum bitrate
g=... # GOP size in frames, from "keyframe_interval_ms"

h264_videotoolbox (macOS only)

Default options:

Terminal window
qmin=4 # minimum QP
qmax=51 # maximum QP, increased vs the encoder default to allow
# low bitrates without dropping frames
bf=0 # disable B-frames
b=... # average bitrate, from "bitrate" or calculated
# from resolution and framerate
maxrate=... # maximum bitrate
g=... # GOP size in frames, from "keyframe_interval_ms"

libx264

Default options:

preset=fast # value of the "preset" option
qcomp=0.6 # QP curve compression
me_range=16 # maximum motion vector search range
qdiff=4 # maximum QP step
qmin=4 # minimum QP
qmax=69 # maximum QP
i_qfactor=1.4 # QP factor between I and P frames
f_pb_factor=1.3 # QP factor between P and B frames
partitions=... # macroblock partitions, depends on the preset
subq=... # subpixel motion estimation quality, depends on the preset
threads=0 # auto-detect thread count
g=... # GOP size in frames, from "keyframe_interval_ms"
crf=23 # ONLY if "bitrate" is not set, quality-based VBR
b=... # ONLY if "bitrate" is set, average bitrate
maxrate=... # ONLY if "bitrate" is set, maximum bitrate
bufsize=... # ONLY if "bitrate" is set, equal to the average bitrate

Reference

Type definitions

type FfmpegH264EncoderOptions = {
type: "ffmpeg_h264";
bitrate?:
| number
| {
average_bitrate: number;
max_bitrate: number;
};
keyframe_interval_ms?: number;
preset?:
| "ultrafast"
| "superfast"
| "veryfast"
| "faster"
| "fast"
| "medium"
| "slow"
| "slower"
| "veryslow"
| "placebo";
pixel_format?: "yuv420p" | "yuv422p" | "yuv444p";
ffmpeg_options?: Record<string, string>;
};

Properties

bitrate

Desired bitrate of the output stream, in bits per second. If only a number is specified then it defines the average_bitrate. The max_bitrate is then set to 1.25x this value.

  • Type: number | { average_bitrate: number; max_bitrate: number; }
  • Default value: Dependent on the encoder used:
    • libx264: Constant quality mode with the crf equal to 23. Visit FFmpeg docs to learn more.
    • libopenh264, h264_videotoolbox: Calculated based on framerate and resolution. Eg. for 30 FPS in 1080p the averageBitrate would be 5000 kb/s and maxBitrate 6250 kb/s.

Properties

average_bitrate

Average bitrate measured in bits per second. Encoder will try to keep the bitrate around the provided average, but may temporarily increase it to the provided max bitrate.

  • Type: number

max_bitrate

Max bitrate measured in bits per second.

  • Type: number

keyframe_interval_ms

Maximal interval between 2 consecutive keyframes, in milliseconds.

  • Type: number
  • Default value: 5000

preset

Video output encoder preset. Visit FFmpeg docs to learn more.

  • Type: "ultrafast" | "superfast" | "veryfast" | "faster" | "fast" | "medium" | "slow" | "slower" | "veryslow" | "placebo"
  • Default value: fast
  • Supported values:
    • ultrafast
    • superfast
    • veryfast
    • faster
    • fast
    • medium
    • slow
    • slower
    • veryslow
    • placebo

pixel_format

Encoder pixel format.

  • Type: "yuv420p" | "yuv422p" | "yuv444p";
  • Default value: yuv420p
  • Supported values: Dependent on the encoder used:
    • libx264: yuv420p, yuv422p, yuv444p
    • libopenh264: yuv420p
    • h264_videotoolbox: yuv420p

ffmpeg_options

Raw FFmpeg encoder options. Visit FFmpeg docs to learn more.

  • Type: Record<string, string>