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.
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.
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.
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
mp4_h265 standalone file encoding settings.
id
"mp4_h265"
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.
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: 24
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 HEVC level using its two-digit representation, such as 31 for level 3.1. The dimensions, frame rate and rate controls must fit this level. Omitted rate limits resolve to level-compatible defaults.
Available options:
303141
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.
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
x265_keyint
integer
X265KeyInt specifies the maximum number of frames between keyframes for H.265 encoding.
Range: 1 to 300. Higher values can improve compression but may affect seeking.
Required range: 1 <= x <= 300
Examples:
60
mp4_av1 standalone file encoding settings.
id
"mp4_av1"
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.
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: 35
integer
Crf (Constant Rate Factor) controls the quality of the output video.
Lower values mean better quality but larger file size. Range: 16 to 63.
Recommended values: 16-35 for high quality, 35-45 for good quality, 45-63 for acceptable quality.
Required range: 16 <= x <= 63
Examples:
35
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 AV1 level using its two-digit representation, such as 31 for level 3.1. The dimensions, frame rate and rate controls must fit this level. Omitted rate limits resolve to level-compatible defaults.
Available options:
303141
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:
yuv420pyuv420p10le
preset
default: "8"
string
Preset controls the encoding efficiency and processing intensity. Lower presets use more
optimization features, creating smaller files with better quality but requiring more compute time.
Higher presets encode faster but produce larger files.
Preset ranges:
6-7: Fast encoding for real-time applications (smaller files)
8-10: Balanced efficiency and speed for general use
11-13: Fastest encoding for real-time applications (larger files)
Available options:
678910111213
Examples:
10
profilev
string
Profilev selects the AV1 Main profile. Use pixfmt to select 8-bit or 10-bit output.
Available options:
main
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.
# 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](/docs/transcoding/quickstart#before-you-begin). 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.
<ignore>
SDK publication check: drafted from api/openapi.json and existing SDK conventions. Add Transcodings models, create/retrieve/list/cancel/delete mappings, pagination and data unwrapping to the owning SDK generator configuration. Verify generated method names and Go union/format/storage types in TypeScript, Python, PHP and Go before publication.
</ignore>
<codegroup>
<codeblock lang="TypeScript">
```typescript
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;
});
```
</codeblock>
<codeblock lang="Python">
```python
from chunkify import Chunkify
client = Chunkify(
project_access_token="My Project Access Token",
)
transcoding = client.transcodings.create(
source_id="src_2G6MJiNz71bHQGNzGwKx5cJwPFS",
format={
"id": "mp4_h264",
"height": 720,
"crf": 21,
},
storage={
"path": "exports/video-720p.mp4",
},
)
print(transcoding.id, transcoding.status)
```
</codeblock>
<codeblock lang="PHP">
```php
<?php
use Chunkify\Client;
require_once __DIR__ . '/vendor/autoload.php';
$client = new Client(
projectAccessToken: 'My Project Access Token',
);
$transcoding = $client->transcodings->create(
sourceID: 'src_2G6MJiNz71bHQGNzGwKx5cJwPFS',
format: [
'id' => 'mp4_h264',
'height' => 720,
'crf' => 21,
],
storage: [
'path' => 'exports/video-720p.mp4',
],
);
var_dump($transcoding->id, $transcoding->status);
```
</codeblock>
<codeblock lang="Go">
```go
package main
import (
"context"
"fmt"
"log"
"github.com/chunkifydev/chunkify-go"
"github.com/chunkifydev/chunkify-go/option"
)
func main() {
client := chunkify.NewClient(
option.WithProjectAccessToken("My Project Access Token"),
)
transcoding, err := client.Transcodings.New(
context.Background(),
chunkify.TranscodingNewParams{
SourceID: "src_2G6MJiNz71bHQGNzGwKx5cJwPFS",
Format: chunkify.TranscodingNewParamsFormatUnion{
OfMP4H264: &chunkify.TranscodingMP4H264Param{
Height: chunkify.Int(720),
Crf: chunkify.Int(21),
},
},
Storage: chunkify.TranscodingNewParamsStorage{
Path: chunkify.String("exports/video-720p.mp4"),
},
},
)
if err != nil {
log.Fatal(err)
}
fmt.Println(transcoding.ID, transcoding.Status)
}
```
</codeblock>
</codegroup>
## 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](/docs/transcoding/per-title).
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
<tabs>
<tab title="H.264">
<openapi-schema schema="#/components/schemas/TranscodingMp4H264"></openapi-schema>
</tab>
<tab title="H.265">
<openapi-schema schema="#/components/schemas/TranscodingMp4H265"></openapi-schema>
</tab>
<tab title="AV1">
<openapi-schema schema="#/components/schemas/TranscodingMp4Av1"></openapi-schema>
</tab>
</tabs>