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

推荐订阅源

A
About on SuperTechFans
人人都是产品经理
人人都是产品经理
量子位
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
博客园 - 三生石上(FineUI控件)
小众软件
小众软件
月光博客
月光博客
T
Tailwind CSS Blog
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
V
Visual Studio Blog
博客园 - 叶小钗
博客园 - 司徒正美
美团技术团队
博客园_首页
宝玉的分享
宝玉的分享
Apple Machine Learning Research
Apple Machine Learning Research
Hugging Face - Blog
Hugging Face - Blog
WordPress大学
WordPress大学
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
The Cloudflare Blog
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
有赞技术团队
有赞技术团队
D
DataBreaches.Net
Google DeepMind News
Google DeepMind News

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
FFmpeg Segment Muxer: segment_time, strftime, and reset_t...
Javid Jamae · 2026-05-30 · via DEV Community

Javid Jamae

Originally published at ffmpeg-micro.com

The FFmpeg segment muxer splits a video into multiple files based on duration. Three flags cause most of the confusion: segment_time, strftime, and reset_timestamps. The official FFmpeg docs define each in one sentence. This guide shows what they actually do, with verified examples and the gotchas that trip people up.

Quick answer: Split a video into 5-second segments with timestamped filenames and clean playback timestamps:

ffmpeg -i input.mp4 -c copy -f segment -segment_time 5 -reset_timestamps 1 -strftime 1 "segment_%Y%m%d_%H%M%S.mp4"

Enter fullscreen mode Exit fullscreen mode

What segment_time Does (and Why Your Segments Are the Wrong Length)

segment_time sets the target duration for each segment in seconds. With -c copy (stream copy, no re-encoding), FFmpeg can only cut at keyframe boundaries. If your video has keyframes every 8 seconds and you set -segment_time 3, your segments will be roughly 8 seconds each.

Actual segment durations from a 13-second test video with -segment_time 3 -c copy:

Segment Expected Actual
output_000.mp4 ~3s 8.34s
output_001.mp4 ~3s 5.01s

The muxer waited for the next keyframe after the 3-second mark. Stream copying can't split mid-GOP because there's no re-encoding to create a new keyframe at the cut point.

Fix: force keyframes at your split points. This requires re-encoding:

ffmpeg -i input.mp4 -c:v libx264 -preset ultrafast -crf 23 \
  -force_key_frames "expr:gte(t,n_forced*3)" \
  -f segment -segment_time 3 -reset_timestamps 1 "output_%03d.mp4"

Enter fullscreen mode Exit fullscreen mode

Now the segments are exactly 3 seconds each.

reset_timestamps: Why Your Player Shows the Wrong Time

Without reset_timestamps, each segment inherits its position from the original video. Check with ffprobe: start_time=8.408000. Add -reset_timestamps 1 and it becomes start_time=0.000000.

If you're generating segments for standalone playback, always use -reset_timestamps 1.

strftime: Timestamped Filenames

With -strftime 1, use date/time tokens in the filename: segment_%Y%m%d_%H%M%S.mp4 produces files like segment_20260530_050835.mp4. You can't mix %03d and strftime in the same pattern.

Common Pitfalls

  • Segments way longer than segment_time: Using -c copy with a GOP interval larger than segment time. Re-encode with -force_key_frames or accept keyframe-aligned cuts.
  • Player shows black frames: Missing -reset_timestamps 1.
  • "Could not write header" error: Use -segment_format mp4 explicitly.

FAQ

Does segment_time guarantee exact segment durations?

Only when re-encoding. With -c copy, FFmpeg cuts at the nearest keyframe after the target time.

What's the difference between the segment muxer and HLS muxer?

The HLS muxer (-f hls) is purpose-built for Apple HLS streaming. The segment muxer (-f segment) is a general-purpose splitter. Use HLS muxer for streaming delivery, segment muxer for batch splitting.

Last verified: 2026-05-30 against FFmpeg 4.3