惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

H
Help Net Security
G
Google Developers Blog
aimingoo的专栏
aimingoo的专栏
博客园 - 聂微东
酷 壳 – CoolShell
酷 壳 – CoolShell
小众软件
小众软件
Stack Overflow Blog
Stack Overflow Blog
美团技术团队
博客园_首页
T
Tailwind CSS Blog
博客园 - 三生石上(FineUI控件)
B
Blog
D
DataBreaches.Net
腾讯CDC
C
Check Point Blog
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
U
Unit 42
月光博客
月光博客
V
V2EX
Vercel News
Vercel News
T
The Blog of Author Tim Ferriss
The Cloudflare Blog
博客园 - 叶小钗
Y
Y Combinator Blog

DEV Community

Authentication Security Deep Dive: From Brute Force to Salted Hashing (With Java Examples) Why AI Systems Don’t Fail — They Drift Spilling beans for how i learn for exam😁"Reinforcement Learning Cheat Sheet" I Replaced Chrome with Safari for AI Browser Automation. Here's What Broke (and What Finally Worked) How Python Borrows Other People's Work The $40 Architecture: Processing 1 Billion API Requests with 99.99% Uptime Vibe Coding: A Workflow Guide (From Zero to SaaS) Most webhook security guides protect the wrong side. The scary part is delivery. Headless CMS for TanStack Start: Build a Blog with Cosmic EU Age Verification App "Hacked in 2 Minutes" — What Actually Happened Comfy Cloud’s delete function does not actually remove files Running AI Models on GPU Cloud Servers: A Beginner Guide Event-driven media intelligence with AWS Step Functions and Bedrock I scored 500 AI prompts across 8 quality dimensions — here's what broke How to Call Google Gemini API from Next.js (Free Tier, No Backend Needed) The Portal Protocol: Reclaiming Human Connection in the Age of AI How to Fix Your Team's Scattered Knowledge Problem With a Self-Hosted Forum Intro to tc Cloud Functors: A Graph-First Mental Model for the Modern Cloud Designing Multi-Tenant Backends With Both Ownership and Team Access I Built a Neumorphic CSS Library with 77+ Components — Here's What I Learned PostgreSQL Performance Optimization: Why Connection Pooling Is Critical at Scale Cómo construí un SaaS multi-rubro para gestionar expensas en Argentina con FastAPI + Vue 3 🚀 I Built an Ethical Hacking Scanner Tool – Open Source Project I Replaced /usage and /context in Claude Code With a Single Statusline A Pythonic Way to Handle Emails (IMAP/SMTP) with Auto-Discovery and AI-Ready Design I Collected 8.9 Million Polymarket Price Points — Here's What I Found About How Markets Really Move EcoTrack AI — Carbon Footprint Tracker & Dashboard Everyone's Using AI. No One Agrees How. 5 self-hosted ebook managers worth trying in 2026 Building Your First AI Agent with LangChain: From Chatbot to Autonomous Assistant
How to Trim and Cut Video with FFmpeg (CLI + API Guide)
Javid Jamae · 2026-04-28 · via DEV Community

Originally published at ffmpeg-micro.com.

You need to extract a 30-second clip from a 2-hour video. Or trim the first 5 seconds of dead air. Or cut everything after the outro. FFmpeg handles all of this, but the syntax trips people up more than it should.

This guide covers every way to trim and cut video with FFmpeg, from basic -ss/-t flags to keyframe-accurate cutting. Then we'll show how to do the same thing with a single API call using FFmpeg Micro.

How to Trim Video with FFmpeg Using -ss and -t

The two core flags for trimming are -ss (seek to a start time) and -t (set the duration).

To extract 30 seconds starting at the 1-minute mark:

ffmpeg -ss 00:01:00 -t 00:00:30 -i input.mp4 -c copy output.mp4

Enter fullscreen mode Exit fullscreen mode

Breaking this down:

  • -ss 00:01:00 seeks to 1 minute into the video
  • -t 00:00:30 limits the output to 30 seconds
  • -c copy copies the streams without re-encoding (fast, but see the gotchas below)

You can also use seconds instead of timestamps. This does the same thing:

ffmpeg -ss 60 -t 30 -i input.mp4 -c copy output.mp4

Enter fullscreen mode Exit fullscreen mode

FFmpeg -ss Before vs After -i (This Matters)

Where you place -ss relative to -i changes how FFmpeg seeks.

Before -i (input seeking, fast):

ffmpeg -ss 00:01:00 -i input.mp4 -t 30 -c copy output.mp4

Enter fullscreen mode Exit fullscreen mode

FFmpeg seeks to the nearest keyframe before your timestamp, then starts decoding. This is fast because it doesn't decode the entire file from the beginning.

After -i (output seeking, accurate):

ffmpeg -i input.mp4 -ss 00:01:00 -t 30 -c copy output.mp4

Enter fullscreen mode Exit fullscreen mode

FFmpeg decodes from the start and discards frames until it hits your timestamp. Slower, but frame-accurate.

For most use cases, put -ss before -i. It's fast and accurate enough. If you need frame-perfect cuts (like editing dialogue), put it after -i and drop -c copy so FFmpeg re-encodes:

ffmpeg -i input.mp4 -ss 00:01:00 -t 30 -c:v libx264 -c:a aac output.mp4

Enter fullscreen mode Exit fullscreen mode

How to Cut Video with FFmpeg Using -to

The -to flag specifies an end timestamp instead of a duration. To extract from 1:00 to 1:30:

ffmpeg -ss 00:01:00 -to 00:01:30 -i input.mp4 -c copy output.mp4

Enter fullscreen mode Exit fullscreen mode

The difference between -t and -to: -t 30 means "30 seconds of output." -to 00:01:30 means "stop at the 1:30 mark of the input." If you use -ss with -to, the -to timestamp is relative to the seeked position when -ss is before -i.

Stream Copy vs Re-encode: The Trim Quality Tradeoff

When you trim with -c copy, FFmpeg doesn't re-encode. It just copies the compressed data. This is 10-100x faster, but there's a catch.

Video is compressed in groups of pictures (GOPs), and each GOP starts with a keyframe. When you seek to a specific time, the nearest keyframe might be a few seconds earlier. With -c copy, your trim point snaps to that keyframe, so the actual start time might not match your -ss value exactly.

If precise cuts matter, re-encode:

ffmpeg -ss 00:01:00 -t 30 -i input.mp4 -c:v libx264 -crf 23 -c:a aac -b:a 192k output.mp4

Enter fullscreen mode Exit fullscreen mode

This decodes and re-encodes every frame, giving you an exact cut at the cost of processing time and a slight quality change.

When to use -c copy: Quick rough cuts, splitting long recordings, removing dead air at the start or end. Speed matters more than frame accuracy.

When to re-encode: Editing dialogue, creating clips for social media, any time a few extra frames at the start would look wrong.

Common Gotchas When Trimming with FFmpeg

Audio drift with stream copy. Some containers store audio and video with slightly different timebase references. When you -c copy a trim, the audio can shift by a fraction of a second relative to the video. Re-encoding fixes this, or you can re-encode just the audio: -c:v copy -c:a aac.

Container format matters. MP4 and MKV handle seeking differently. MP4 stores its index (moov atom) either at the start or end of the file. If the moov atom is at the end, FFmpeg has to read the entire file before it can seek. Use -movflags +faststart when outputting MP4 to move the moov atom to the front.

Negative timestamps. When trimming with -c copy and -ss before -i, FFmpeg might produce frames with negative timestamps. Add -avoid_negative_ts make_zero to fix this:

ffmpeg -ss 00:01:00 -t 30 -i input.mp4 -c copy -avoid_negative_ts make_zero output.mp4

Enter fullscreen mode Exit fullscreen mode

Duration mismatch with -to and -ss before -i. When -ss appears before -i, the -to timestamp is relative to the seeked position, not the original file. So -ss 60 -to 90 gives you 30 seconds, not the segment from 1:00 to 1:30 as you might expect. If that's confusing, just use -t for duration instead.

How to Trim Video with FFmpeg Micro's API

All the examples above work great locally, but running FFmpeg on a server means managing binaries, scaling infrastructure, and handling edge cases yourself. FFmpeg Micro is a cloud API that handles all of this with a single HTTP request.

To trim a video to 30 seconds starting at the 1-minute mark:

curl -X POST https://api.ffmpeg-micro.com/v1/transcodes \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "inputs": [{"url": "https://example.com/video.mp4"}],
    "outputFormat": "mp4",
    "options": [
      {"option": "-ss", "argument": "00:01:00"},
      {"option": "-t", "argument": "30"},
      {"option": "-c", "argument": "copy"}
    ]
  }'

Enter fullscreen mode Exit fullscreen mode

You can also pass -ss and -t as input-level options to get the fast input-seeking behavior:

curl -X POST https://api.ffmpeg-micro.com/v1/transcodes \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "inputs": [{
      "url": "https://example.com/video.mp4",
      "options": [
        {"option": "-ss", "argument": "00:01:00"},
        {"option": "-t", "argument": "30"}
      ]
    }],
    "outputFormat": "mp4",
    "options": [
      {"option": "-c", "argument": "copy"}
    ]
  }'

Enter fullscreen mode Exit fullscreen mode

For frame-accurate trimming with re-encoding, drop the -c copy and specify codecs:

curl -X POST https://api.ffmpeg-micro.com/v1/transcodes \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "inputs": [{"url": "https://example.com/video.mp4"}],
    "outputFormat": "mp4",
    "options": [
      {"option": "-ss", "argument": "00:01:00"},
      {"option": "-t", "argument": "30"},
      {"option": "-c:v", "argument": "libx264"},
      {"option": "-crf", "argument": "23"},
      {"option": "-c:a", "argument": "aac"}
    ]
  }'

Enter fullscreen mode Exit fullscreen mode

FFmpeg Micro handles the infrastructure, scaling, and edge cases. You get the full power of FFmpeg's trimming capabilities without managing servers.

For a deeper dive on FFmpeg encoding fundamentals, check out our Learn FFmpeg: Transcoding lesson.

FAQ

What's the difference between FFmpeg -t and -to?

-t sets a duration (how long the output should be). -to sets an end timestamp (where to stop). If you use -ss 60 -t 30, you get 30 seconds of output starting at the 1-minute mark. If you use -ss 60 -to 90, you also get 30 seconds, but -to 90 is interpreted relative to the seek position when -ss is placed before -i.

Can I trim video without re-encoding in FFmpeg?

Yes. Use -c copy to copy streams without re-encoding. This is fast but trims to the nearest keyframe, so the start point might be off by a few frames. For exact cuts, you need to re-encode with -c:v libx264 -c:a aac.

How do I trim the last 10 seconds off a video with FFmpeg?

First, get the total duration with ffprobe -v error -show_entries format=duration -of csv=p=0 input.mp4. Then use -t with the duration minus 10 seconds. There's no native "trim from end" flag in FFmpeg.

Does FFmpeg Micro support -to for trimming?

FFmpeg Micro supports -ss (seek) and -t (duration) for trimming. The -to flag is not currently in the supported options list. Use -t with the desired duration instead, which achieves the same result.

How do I trim multiple sections from a video?

You can't do it in a single FFmpeg command without -filter_complex. The simplest approach: run separate trim commands for each section, then concatenate the results. With FFmpeg Micro, you'd make separate API calls for each segment.