FFmpeg H264
Low latency streaming
For latency-sensitive outputs you can reduce the delay introduced by the encoder itself with ffmpegOptions:
ffmpegOptions: { 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 ffmpegOptions is applied on top of these defaults and overrides them.
libopenh264
Default options:
qmin=4 # minimum QPqmax=51 # maximum QP, increased vs the encoder default to allow # low bitrates without dropping framesrc_mode=0 # rate control mode: qualitythreads=0 # auto-detect thread countb=... # average bitrate, from "bitrate" or calculated # from resolution and frameratemaxrate=... # maximum bitrateg=... # GOP size in frames, from "keyframeIntervalMs"h264_videotoolbox (macOS only)
Default options:
qmin=4 # minimum QPqmax=51 # maximum QP, increased vs the encoder default to allow # low bitrates without dropping framesbf=0 # disable B-framesb=... # average bitrate, from "bitrate" or calculated # from resolution and frameratemaxrate=... # maximum bitrateg=... # GOP size in frames, from "keyframeIntervalMs"libx264
Default options:
preset=fast # value of the "preset" optionqcomp=0.6 # QP curve compressionme_range=16 # maximum motion vector search rangeqdiff=4 # maximum QP stepqmin=4 # minimum QPqmax=69 # maximum QPi_qfactor=1.4 # QP factor between I and P framesf_pb_factor=1.3 # QP factor between P and B framespartitions=... # macroblock partitions, depends on the presetsubq=... # subpixel motion estimation quality, depends on the presetthreads=0 # auto-detect thread countg=... # GOP size in frames, from "keyframeIntervalMs"crf=23 # ONLY if "bitrate" is not set, quality-based VBRb=... # ONLY if "bitrate" is set, average bitratemaxrate=... # ONLY if "bitrate" is set, maximum bitratebufsize=... # ONLY if "bitrate" is set, equal to the average bitrateReference
Type definitions
type FfmpegH264EncoderOptions = { type: "ffmpeg_h264"; bitrate?: | number | { averageBitrate: number; maxBitrate: number; }; keyframeIntervalMs?: number; preset?: | "ultrafast" | "superfast" | "veryfast" | "faster" | "fast" | "medium" | "slow" | "slower" | "veryslow" | "placebo"; pixelFormat?: "yuv420p" | "yuv422p" | "yuv444p"; ffmpegOptions?: 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 averageBitrate.
The maxBitrate is then set to 1.25x this value.
- Type:
number | { averageBitrate: number; maxBitrate: number; } - Default value: Dependent on the encoder used:
- libx264: Constant quality mode with the
crfequal to 23. Visit FFmpeg docs to learn more. - libopenh264, h264_videotoolbox: Calculated based on framerate and resolution. Eg. for 30 FPS in 1080p
the
averageBitratewould be 5000 kb/s andmaxBitrate6250 kb/s.
- libx264: Constant quality mode with the
Properties
averageBitrate
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
maxBitrate
Max bitrate measured in bits per second.
- Type:
number
keyframeIntervalMs
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:
ultrafastsuperfastveryfastfasterfastmediumslowslowerveryslowplacebo
pixelFormat
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
- libx264:
ffmpegOptions
Raw FFmpeg encoder options. Visit FFmpeg docs to learn more.
- Type:
Record<string, string>