DocsGuides
Trim and clip
Cut a part of a video by start time and length, exact to the frame or at key frames without re-encoding.
trim cuts a part of the input. The input is seeked to the start, so the part before it is not
decoded, and only the part you keep is billed as output.
The request#
curl "$VIDEXO_API_URL/v1/transcode" \
-H "Authorization: Bearer $VIDEXO_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"input": "https://example.com/talk.mp4",
"filename": "talk-clip.mp4",
"trim": {
"start": "00:01:30",
"duration": 30
}
}'Copy failed. The text is selected; copy it with your keyboard.
const response = await fetch(`${process.env.VIDEXO_API_URL}/v1/transcode`, {
method: 'POST',
headers: {
Authorization: `Bearer ${process.env.VIDEXO_API_KEY}`,
'Content-Type': 'application/json',
},
body: JSON.stringify({
"input": "https://example.com/talk.mp4",
"filename": "talk-clip.mp4",
"trim": {
"start": "00:01:30",
"duration": 30
}
}),
});
const job = await response.json();Copy failed. The text is selected; copy it with your keyboard.
ffmpeg \
-ss 90 -t 30 -i https://example.com/talk.mp4 \
-map 0:v:0 \
-vf "scale='min(trunc(iw/2)*2,min(7680,min(trunc(7680*iw/ih/2)*2,trunc(sqrt(33554432*iw/ih)/2)*2)))':-2" \
-c:v libx264 -preset veryfast -crf 23 -pix_fmt yuv420p \
-map "0:a:0?" \
-c:a aac -b:a 128k -movflags +faststart \
talk-clip.mp4Copy failed. The text is selected; copy it with your keyboard.
talk-clip.mp4: the 30 seconds that start at 1:30, re-encoded so the cut lands on the exact frame.
trim takes start and either duration or end, as seconds or HH:MM:SS.fraction.
Without re-encoding#
With "codec": "copy" the job is much faster, but the cut lands on the key frame at or before
start, as in ffmpeg.
curl "$VIDEXO_API_URL/v1/transcode" \
-H "Authorization: Bearer $VIDEXO_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"input": "https://example.com/talk.mp4",
"filename": "talk-part.mp4",
"trim": {
"start": 600,
"end": 900
},
"video": {
"codec": "copy"
},
"audio": {
"codec": "copy"
}
}'Copy failed. The text is selected; copy it with your keyboard.
const response = await fetch(`${process.env.VIDEXO_API_URL}/v1/transcode`, {
method: 'POST',
headers: {
Authorization: `Bearer ${process.env.VIDEXO_API_KEY}`,
'Content-Type': 'application/json',
},
body: JSON.stringify({
"input": "https://example.com/talk.mp4",
"filename": "talk-part.mp4",
"trim": {
"start": 600,
"end": 900
},
"video": {
"codec": "copy"
},
"audio": {
"codec": "copy"
}
}),
});
const job = await response.json();Copy failed. The text is selected; copy it with your keyboard.
ffmpeg \
-ss 600 -t 300 -i https://example.com/talk.mp4 \
-map 0:v:0 \
-c:v copy \
-map "0:a:0?" \
-c:a copy -movflags +faststart \
talk-part.mp4Copy failed. The text is selected; copy it with your keyboard.
Several clips from one input#
Several outputs in one job each read their own part of the same input, which is fetched once.
curl "$VIDEXO_API_URL/v1/jobs" \
-H "Authorization: Bearer $VIDEXO_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"inputs": {
"talk": "https://example.com/talk.mp4"
},
"outputs": [
{
"name": "intro",
"type": "video",
"trim": {
"start": 0,
"duration": 30
}
},
{
"name": "answer",
"type": "video",
"trim": {
"start": "00:12:05",
"duration": 45
}
}
]
}'Copy failed. The text is selected; copy it with your keyboard.
const response = await fetch(`${process.env.VIDEXO_API_URL}/v1/jobs`, {
method: 'POST',
headers: {
Authorization: `Bearer ${process.env.VIDEXO_API_KEY}`,
'Content-Type': 'application/json',
},
body: JSON.stringify({
"inputs": {
"talk": "https://example.com/talk.mp4"
},
"outputs": [
{
"name": "intro",
"type": "video",
"trim": {
"start": 0,
"duration": 30
}
},
{
"name": "answer",
"type": "video",
"trim": {
"start": "00:12:05",
"duration": 45
}
}
]
}),
});
const job = await response.json();Copy failed. The text is selected; copy it with your keyboard.
ffmpeg \
-t 30 -i https://example.com/talk.mp4 \
-ss 725 -t 45 -i https://example.com/talk.mp4 \
-map 0:v:0 \
-vf "scale='min(trunc(iw/2)*2,min(7680,min(trunc(7680*iw/ih/2)*2,trunc(sqrt(33554432*iw/ih)/2)*2)))':-2" \
-c:v libx264 -preset veryfast -crf 23 -pix_fmt yuv420p \
-map "0:a:0?" \
-c:a aac -b:a 128k -movflags +faststart \
intro.mp4 \
-map 1:v:0 \
-vf "scale='min(trunc(iw/2)*2,min(7680,min(trunc(7680*iw/ih/2)*2,trunc(sqrt(33554432*iw/ih)/2)*2)))':-2" \
-c:v libx264 -preset veryfast -crf 23 -pix_fmt yuv420p \
-map "1:a:0?" \
-c:a aac -b:a 128k -movflags +faststart \
answer.mp4Copy failed. The text is selected; copy it with your keyboard.