How to Trim and Cut Video with FFmpeg (Without Re-encoding)
Trim video with FFmpeg: a fast cut with -c copy, a frame-accurate cut with a re-encode, -t versus -to, and the same job as one API call with no FFmpeg install.
To trim a video with FFmpeg without re-encoding, use ffmpeg -ss 60 -i input.mp4 -t 30 -c copy output.mp4. This cuts 30 seconds from the 1-minute mark with no quality loss, but it starts on the nearest keyframe; for a frame-accurate cut, re-encode with -c:v libx264 in place of -c copy.
Below are both commands with each flag explained, the same job as one Xora API call, the variants you will need, and the common errors. For other common commands, see the FFmpeg cheat sheet.
The local commands
Fast cut: stream copy
ffmpeg -ss 60 -i input.mp4 -t 30 -c copy output.mp4| Flag | What it does |
|---|---|
-ss 60 | Start time, in seconds or as 00:01:00. Before -i, FFmpeg seeks in the input before it reads, which is fast. |
-t 30 | Duration of the output: 30 seconds. |
-c copy | Copy the streams without re-encoding. No quality loss, but the cut can only start on a keyframe. |
Frame-accurate cut: re-encode
ffmpeg -ss 60 -i input.mp4 -t 30 -c:v libx264 -crf 20 -preset medium -c:a aac -movflags +faststart output.mp4With a re-encode, FFmpeg decodes from the keyframe before the start and drops the frames before your time, so the clip starts on the exact frame. -crf 20 keeps the quality close to the source.
| Which one | When |
|---|---|
-c copy | Rough cuts, long clips, or when the source quality must stay exactly the same. |
| Re-encode | Short clips, social posts, or any cut that must start on an exact frame. |
The same job with the Xora API
The trim recipe takes a start and a duration in seconds:
{ "mode": "recipe", "input": { "url": "https://example.com/webinar.mp4" }, "output": { "format": "mp4" }, "recipe": { "name": "trim", "startSeconds": 60, "durationSeconds": 30 }}To choose between stream copy and a re-encode yourself, send the arguments:
{ "mode": "ffmpeg", "input_files": { "in_1": "https://example.com/webinar.mp4" }, "output_files": { "out_1": "clip_60_90.mp4" }, "ffmpeg": { "args": ["-ss", "60", "-i", "{{in_1}}", "-t", "30", "-c", "copy", "{{out_1}}"] }}Send the body to https://api.xora.sh/v1/jobs with Authorization: Bearer YOUR_API_KEY. Poll GET /v1/jobs/{id} or pass webhookUrl, then download the clip from the signed URL. If the start plus the duration goes past the end of the file, the clip stops at the end with no error. See the trim recipe.
Variants
Remove the intro
Leave out -t to keep everything after the start:
ffmpeg -ss 5 -i input.mp4 -c copy output.mp4With Xora, send only startSeconds: 5.
Keep the first N seconds
ffmpeg -i input.mp4 -t 10 -c copy first_10s.mp4With Xora, send only durationSeconds: 10.
Cut several clips from one file
Run one job for each clip. Each job has its own result. Add an idempotencyKey to each job so a retry does not create a second clip.
Trim audio
The same commands work on audio files: ffmpeg -ss 0 -i podcast.mp3 -t 60 -c copy intro.mp3. The trim recipe also accepts mp3, aac and wav outputs.
Common errors
| Error | Cause | Fix |
|---|---|---|
| The clip starts early or has a frozen first second | -c copy started on a keyframe before your time. | Re-encode, or accept the keyframe cut. |
| The clip is longer or shorter than expected | -to was used with -ss before -i, so the times restarted at zero. | Use -t for the duration. |
| Audio and video are out of sync after a copy | The streams have keyframes at different times. | Re-encode the clip. |
VALIDATION_ERROR (Xora) | A field in the job body is wrong, such as a negative time. | Read error.message; it names the field. |
Failed and rejected Xora jobs cost nothing. See error handling.
Related
- Trim recipe reference.
- FFmpeg cheat sheet: the common commands, each as an API call.
- How to concatenate videos with FFmpeg.
Frequently asked questions
How do I trim a video with FFmpeg without re-encoding?
Use stream copy: ffmpeg -ss 60 -i input.mp4 -t 30 -c copy output.mp4. This keeps the original quality and finishes quickly, but the cut starts on a keyframe, so it can begin up to a few seconds before the time you asked for.
How do I make a frame-accurate cut with FFmpeg?
Re-encode the clip: ffmpeg -ss 60 -i input.mp4 -t 30 -c:v libx264 -crf 20 -c:a aac output.mp4. With a re-encode, FFmpeg can start on the exact frame.
What is the difference between -t and -to in FFmpeg?
-t sets the duration of the output. -to sets the time where the output stops. When -ss is before -i, the timestamps restart at zero, so -to 30 also gives a 30-second clip. To avoid confusion, use -t.
Can I trim a video without installing FFmpeg?
Yes. Send the video URL to the Xora API with the trim recipe, startSeconds and durationSeconds. Or send your own FFmpeg arguments in mode ffmpeg. Xora returns a signed URL for the clip.