Codecs
Video and audio codec configuration
The library supports multiple video and audio codecs with configurable presets and profiles.
Video Codecs
x264 (H.264)
The default and most widely compatible codec:
builder.withVideoCodec({
kind: "x264",
preset: "medium", // Encoding speed/quality tradeoff
profile: "high", // H.264 profile
tune: "film", // Optional tuning
});Presets (fastest to slowest):
ultrafast, superfast, veryfast, faster, fast, medium, slow, slower, veryslow
Profiles:
baseline, main, high, high10, high422, high444
Use medium preset for a good balance of speed and quality. Use slow or slower
for final production encodes when time isn't critical.
x265 (H.265/HEVC)
Better compression than H.264 at the cost of encoding speed:
builder.withVideoCodec({
kind: "x265",
preset: "medium",
profile: "main", // main or main10
});Presets: Same as x264
Profiles: main, main10 (10-bit color)
HEVC playback requires browser/device support. Consider providing H.264 fallback for maximum compatibility.
aom-av1 (AV1)
Next-generation codec with excellent compression:
builder.withVideoCodec({
kind: "aom-av1",
preset: "6", // 0-13 (lower = slower, better quality)
});Presets: 0 to 13 (lower is slower but higher quality)
AV1 encoding is significantly slower than H.264/H.265. Best suited for pre-encoded content where encoding time isn't critical.
copy (Stream Copy)
Copy video stream without re-encoding:
builder.withVideoCodec({ kind: "copy" });Use stream copy when:
- Source is already in the desired format
- You only need to repackage into CMAF segments
- Maximum quality preservation is required
Stream copy preserves the original codec and quality but may not produce optimal segment boundaries. Use with pre-encoded content only.
Audio Codecs
aac
The default audio codec with wide compatibility:
builder.withAudioCodec({
kind: "aac",
sampleRate: 48000, // 44100 or 48000
channels: 2, // 1 (mono) or 2 (stereo)
});Sample Rates: 44100, 48000
Channels: 1 (mono), 2 (stereo)
copy (Stream Copy)
Copy audio stream without re-encoding:
builder.withAudioCodec({ kind: "copy" });Codec Comparison
| Codec | Compression | Speed | Compatibility |
|---|---|---|---|
| x264 (H.264) | Good | Fast | Excellent |
| x265 (HEVC) | Better | Slow | Good |
| aom-av1 | Best | Very Slow | Limited |
Recommended Settings
Web Streaming
For broad compatibility:
builder
.withVideoCodec({ kind: "x264", preset: "medium", profile: "high" })
.withAudioCodec({ kind: "aac", sampleRate: 48000, channels: 2 });High Quality Archive
For maximum compression:
builder
.withVideoCodec({ kind: "x265", preset: "slow", profile: "main10" })
.withAudioCodec({ kind: "aac", sampleRate: 48000, channels: 2 });Quick Preview
For fast encoding during development:
builder
.withVideoCodec({ kind: "x264", preset: "ultrafast" })
.withAudioCodec({ kind: "aac" });