Docs

MP4

Encode an MP4 file with H.264, H.265, or AV1 and configure its video settings.

MP4 outputs use H.264, H.265, or AV1 video with AAC audio when the Source has audio. Choose the codec your target players support, then set the dimensions and quality you need.

Codec defaults

Format ID Default CRF Default preset
mp4_h264 21 faster
mp4_h265 24 veryfast
mp4_av1 35 8

These CRF defaults apply when you omit both per-title optimization and target bitrate. MP4 outputs use movflags: faststart and pixfmt: yuv420p by default.

Create an H.264 transcode

The example sets a height of 720 pixels and CRF 21. Width follows the Source aspect ratio.

Run these examples on your server after setting up your SDK and Source. Replace the token and Source ID.

These examples save the file in your Project's output storage. Set storage.path to the filename you want to use.

import Chunkify from '@chunkify/chunkify';

async function main() {
    const client = new Chunkify({
        projectAccessToken: 'My Project Access Token',
    });

    const transcoding = await client.transcodings.create({
        source_id: 'src_2G6MJiNz71bHQGNzGwKx5cJwPFS',
        format: {
            id: "mp4_h264",
            height: 720,
            crf: 21,
        },
        storage: {
            path: 'exports/video-720p.mp4',
        },
    });

    console.log(transcoding.id, transcoding.status);
}

main().catch((error) => {
    console.error(error);
    process.exitCode = 1;
});

Rate control and compatibility

Set per_title: true for automatic, content-based bitrate selection instead of specifying a CRF or target bitrate. See Per-title optimization.

For H.264 and H.265, maxrate and bufsize must be supplied together. AV1 permits a maximum rate with CRF encoding, but does not accept minrate or a maximum rate combined with video_bitrate.

A chosen profilev must support the requested pixel format. An explicit codec level must fit the dimensions, frame rate, bitrate, and buffer settings. Use the request schemas below to check valid combinations.

Encoding parameters

mp4_h264 standalone file encoding settings.

id
"mp4_h264"
string
required

Id specifies the output format.

audio_bitrate
default: 128000
integer

AudioBitrate specifies the output audio bitrate in bits per second. Defaults to 128000.

Required range: 32000 <= x <= 512000
audio_samplerate
default: 48000
integer

AudioSamplerate specifies the output sample rate in Hz. Defaults to 48000. WebM Opus audio uses 48000.

Available options:
80001102512000160002205024000320004410048000640008820096000
bufsize
integer

Bufsize specifies the video buffer size in bits, from 100000 through 50000000. H.264 and H.265 require maxrate. AV1 and VP9 require a bitrate-controlled mode.

Required range: 100000 <= x <= 5e+07
channels
default: 2
integer

Channels specifies the output channel count. Defaults to stereo. Six channels means 5.1; eight means 7.1.

Available options:
1268
crf
default: 21
integer

Crf (Constant Rate Factor) controls the quality of the output video. Lower values mean better quality but larger file size. Range: 16 to 35. Recommended values: 18-28 for high quality, 23-28 for good quality, 28-35 for acceptable quality.

Required range: 16 <= x <= 35
Examples:
23
disable_audio
boolean

DisableAudio omits the audio stream. Defaults to false. A source without audio produces video only.

disable_video
boolean

DisableVideo selects an audio-only AAC M4A export. Defaults to false. The source must contain audio.

duration
number

Duration specifies the requested output length in seconds. Defaults to the remaining source duration and is capped at the source end. Audio-only output must resolve to at least 0.001 seconds after trimming and sample rounding. The accepted interval determines the fixed price.

framerate
number

Framerate specifies the output video frame rate. Defaults to the source rate and must be between 0.001 and 240 fps.

Required range: 0.001 <= x <= 240
gop
integer

Gop specifies the maximum keyframe interval in frames. Defaults to four seconds at the accepted frame rate, capped at 960 frames.

Required range: 1 <= x <= 960
height
integer

Height specifies the output dimension in pixels. Use -2 or omit one dimension to preserve the source aspect ratio. Explicit dimensions must be 2 to 7680 and even. Omitting both preserves the source dimensions rounded down to even pixels.

Required range: -2 <= x <= 7680
level
integer

Level specifies the H.264 decoder level using its two-digit representation, such as 41 for level 4.1. The dimensions, frame rate and rate controls must fit this level and the effective profile. Omitted rate limits resolve to level-compatible defaults.

Available options:
101112132021223031324041425051
Examples:
41
maxrate
integer

Maxrate specifies the video buffer maximum rate in bits per second, from 100000 through 50000000. H.264 and H.265 require bufsize. VP9 requires video_bitrate; AV1 requires CRF mode.

Required range: 100000 <= x <= 5e+07
movflags
default: "faststart"
string

Movflags specifies MP4 packaging. Defaults to faststart, which places playback metadata before the media.

Available options:
faststart
per_title
default: false
boolean

PerTitle enables independent content-based bitrate prediction for each part of the video. Analysis uses only the selected trim interval. Defaults to false. Explicit rate-control settings cannot be combined with it.

pixfmt
default: "yuv420p"
string

Pixfmt specifies the output pixel format. Defaults to yuv420p. The selected profile must support it.

Available options:
yuv420pyuv422pyuv444pyuv420p10leyuv422p10leyuv444p10le
preset
default: "faster"
string

Preset specifies the encoding speed preset. Valid values (from fastest to slowest):

  • ultrafast: Fastest encoding, lowest quality
  • superfast: Very fast encoding, lower quality
  • veryfast: Fast encoding, moderate quality
  • faster: Faster encoding, good quality
  • fast: Fast encoding, better quality
  • medium: Balanced preset, best quality
Available options:
ultrafastsuperfastveryfastfasterfastmedium
Examples:
medium
profilev
string

Profilev specifies the H.264 profile. Valid values:

  • baseline: Basic profile, good for mobile devices
  • main: Main profile, good for most applications
  • high: High profile, best quality but requires more processing
  • high10: High 10-bit profile, supports 10-bit color
  • high422: High 4:2:2 profile, supports 4:2:2 color sampling
  • high444: High 4:4:4 profile, supports 4:4:4 color sampling
Available options:
baselinemainhighhigh10high422high444
Examples:
high
seek
number

Seek specifies the start in source seconds. Defaults to zero and must precede the source end. The accepted interval uses the output frame or sample timeline. Audio-only output must retain at least 0.001 seconds after sample rounding.

Required range: x >= 0
video_bitrate
integer

VideoBitrate specifies the target video bitrate in bits per second, from 1000 through 100000000. Omit it for CRF or per-title encoding.

Required range: 1000 <= x <= 1e+08
width
integer

Width specifies the output dimension in pixels. Use -2 or omit one dimension to preserve the source aspect ratio. Explicit dimensions must be 2 to 7680 and even. Omitting both preserves the source dimensions rounded down to even pixels.

Required range: -2 <= x <= 7680
x264_keyint
integer

X264KeyInt specifies the maximum number of frames between keyframes for H.264 encoding. Range: 1 to 960. Higher values can improve compression but may affect seeking.

Required range: 1 <= x <= 960
Examples:
60