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

推荐订阅源

K
Kaspersky official blog
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
AI
AI
SecWiki News
SecWiki News
宝玉的分享
宝玉的分享
Scott Helme
Scott Helme
D
Darknet – Hacking Tools, Hacker News & Cyber Security
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
Engineering at Meta
Engineering at Meta
博客园 - 叶小钗
The GitHub Blog
The GitHub Blog
Microsoft Azure Blog
Microsoft Azure Blog
N
News and Events Feed by Topic
Cloudbric
Cloudbric
B
Blog
Cisco Talos Blog
Cisco Talos Blog
V
Vulnerabilities – Threatpost
N
News and Events Feed by Topic
V
Visual Studio Blog
A
Arctic Wolf
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
U
Unit 42
S
Security @ Cisco Blogs
博客园 - 聂微东
T
Threat Research - Cisco Blogs
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
Apple Machine Learning Research
Apple Machine Learning Research
Y
Y Combinator Blog
G
GRAHAM CLULEY
L
LINUX DO - 热门话题
量子位
NISL@THU
NISL@THU
Webroot Blog
Webroot Blog
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
T
Troy Hunt's Blog
Application and Cybersecurity Blog
Application and Cybersecurity Blog
T
Tenable Blog
月光博客
月光博客
S
Security Affairs
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
The Hacker News
The Hacker News
Spread Privacy
Spread Privacy
D
Docker
www.infosecurity-magazine.com
www.infosecurity-magazine.com
雷峰网
雷峰网
博客园 - 司徒正美
T
The Exploit Database - CXSecurity.com
Hugging Face - Blog
Hugging Face - Blog
Help Net Security
Help Net Security
D
DataBreaches.Net

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 Common SOC 2 Failures (Real World) Stop Vibe-Checking Your AI App: A Practical Guide to Evals How to Use SonarQube and SonarScanner Locally to Level Up Your Code Quality Your Next To-Do App Is Dead — I Replaced Mine with an OpenClaw AI Sign a Nostr event in 60 lines of Python using coincurve — no nostr-sdk, no nbxplorer, no rust toolchain ITGC Audit Explained Like You’re in Big 4 Patch Tuesday abril 2026: Microsoft parcha 163 vulnerabilidades y un zero-day en SharePoint Stop scraping everything: a better way to track competitor price changes Listing on MCPize + the Official MCP Registry while routing payments OUTSIDE the marketplace — how I kept 100% of my x402 revenue Building an AI-Powered Risk Intelligence System Using Serverless Architecture Why We Ripped Function Overloading Out of Our AI Toolchain Testing AI-Generated Code: How to Actually Know If It Works SaaS Churn Is Killing Your Business. Here Is What to Do About It (Without a Support Team) The Speed of AI Is No Longer Linear - And Self-Improving Models Are Why How to Implement RBAC for MCP Tools: A Practical Guide for Engineering Teams From Standard Quote to Persuasive Proposal: AI Automation for Arborists I built a CLI that scaffolds complete multi-tenant SaaS apps Axios CVE-2025–62718: The Silent SSRF Bug That Could Be Hiding in Your Node.js App Right Now The dashboard that ended our friendship Data Pipelines Explained Simply (and How to Build Them with Python) The Hidden Cost of AI Systems Nobody Talks About. undefined vs undeclared, and how typeof behaves Switching from file-based jobs to NATS/Kafka in Rust without changing code io_uring Adventures: Rust Servers That Love Syscalls Why Agentic AI is Killing the Traditional Database The POUR principles of web accessibility for developers and designers Quantum Neural Network 3D — A Deep Dive into Interactive WebGL Visualization How To Install Caveman In Codex On macOS And Windows Automation Pipeline Reliability: Why Your Workflow Breaks When Nobody Is Watching I Built an 'Open World' AI Coding Agent — It Works From ANY Folder From Freelancing to Product: A Tech Service Company's SaaS Transformation China's AI Giants: Adding Tencent Hunyuan & ByteDance Doubao to AI University (74 Providers) On the Vibe Coders and Their Lies clerk: Auto-Summarize Your Claude Code Sessions AI Weekly — 2026/04/10–04/17 | The Model Lockdown Is Here, but the Toolchain Is the Real Battleground AI 週報 — 2026/04/10–2026/04/17 模型封鎖潮來了,但工具鏈才是真戰場 Maybe this is how Open-Source apps are born... 🚀 Fine-Tune LLMs with LoRA and QLoRA: 2026 Guide tRPC v11 + Next.js App Router: End-to-End Type Safety Without the Boilerplate ShadCN UI in 2026: Why I Stopped Installing Component Libraries and Started Owning My Components SaaS Billing in React Server Components: Stripe + Supabase Without a Single `useEffect` Join our DEV Weekend Challenge — $1,000 in Prizes Across TEN winners! Submissions Due April 20 at 6:59 AM UTC. Implementing FSRS Spaced Repetition in Flutter + Supabase — Adding Memory Science to an AI Learning App "I Texted My Localhost From the Train — Claude Code Fixed the Bug Before I Got Home" I Built a Sales Prep AI and It Went Deeper Than Expected Design to Code #2: One JSON, Eleven Outputs Solving the 100M-Row Problem: A Summary Table Pattern for High-Volume Push Notification Logs Flutter Web With Wasm: What Actually Changes For Developers I Built 50 Royalty-Free Soundtracks for My Side Project in a Weekend Using AI Music Generation The Vibe Coding Security Checklist: 7 Things to Check Before You Ship Stop Letting Googlebot Guess Fix Your React App's SEO Right Desconstruindo o Streaming do LinkedIn: Como Criar um Engine de Extração de Vídeo de Alta Performance com HLS e FFmpeg (EDA Part-1) EDA (Exploratory Data Analysis) Explained With Real Life — Why Looking at Your Data Is the Most Important Step in Machine Learning Brand Relationship Management at Scale: Our 4-Touch Outreach System for 200+ Brands Why String.fromEnvironment() Might Return an Empty String in Dart JGuardrails 1.0.0 — Hardening Java LLM Apps Against Jailbreaks, Toxicity, and Prompt Injection Plan and Schedule a Full Week of Threads Content From One Claude Conversation Coding Cat Oran Ep3, Five Tables Changed Everything Updated: BFF Pattern I'm done watching freelancers get buried by 200 proposals. So I'm building the alternative. This is my first post BFS Algorithm in Java Step by Step Tutorial with Examples Tracking LLM Pricing Monthly: An Open Dataset for 22 AI Models How We Measure Content ROI on a Comparison Site: Revenue Attribution Without Perfect Data Introducing Nova AI Ops: The AI-Native Operating System for SRE Teams I built a free desktop video downloader for Windows — Grabbit How Talkie OCR Helps Vision-Impaired & Dyslexic Users Read the World Around Them VRCFaceTracking安装和iPhone面捕配置教程,有bug Even CrowdStrike Can't See Your Agents The Automation Gold Rush: What n8n Workflows and Claude Are Opening Up for Developers Right Now
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.