🔗 TS 文件合并为 MP4 的 3 种方法

🔗 3 Ways to Merge TS Files into MP4

你可能遇到过这种情况:下载了一个视频,结果是一堆 .ts 文件,每个只有几秒钟。这些就是 HLS 视频的分片文件。本文将介绍三种方法将它们合并为一个完整的 MP4 视频。

⚠️ 注意: 如果你还没下载视频,建议直接使用 M3U8 Converter 一步完成下载和合并,无需手动处理 TS 文件。

方法概览

  • 方法一:FFmpeg 命令行 - 最专业、最灵活
  • 方法二:在线合并工具 - 最简单、无需安装
  • 方法三:视频编辑软件 - 可视化操作

📟 方法一:FFmpeg 命令行 ⭐⭐ 中等

FFmpeg 是最强大的视频处理工具,合并 TS 文件非常高效。

步骤 1:创建文件列表

首先,创建一个文本文件 filelist.txt,列出所有 TS 文件:

file 'segment_0.ts'
file 'segment_1.ts'
file 'segment_2.ts'
file 'segment_3.ts'
...

或使用命令自动生成:

# Windows
(for %i in (*.ts) do @echo file '%i') > filelist.txt

# macOS/Linux
for f in *.ts; do echo "file '$f'" >> filelist.txt; done

步骤 2:合并文件

# 直接合并(速度最快)
ffmpeg -f concat -safe 0 -i filelist.txt -c copy output.mp4

# 重新编码(更好兼容性)
ffmpeg -f concat -safe 0 -i filelist.txt -c:v libx264 -c:a aac output.mp4

🌐 方法二:在线合并工具 ⭐ 简单

适合没有安装 FFmpeg 的用户,但有文件大小和数量限制。

推荐工具:

使用步骤:

  1. 打开在线工具网站
  2. 按顺序上传所有 TS 文件
  3. 选择输出格式为 MP4
  4. 点击合并,等待处理
  5. 下载合并后的 MP4 文件

缺点:需要上传文件,隐私性较差;大文件可能超时。

🎬 方法三:视频编辑软件 ⭐ 简单

使用免费的视频编辑软件进行可视化合并。

推荐软件:

  • VLC Media Player - 免费开源
  • Shotcut - 免费视频编辑器
  • DaVinci Resolve - 专业免费版

使用 VLC 合并

  1. 打开 VLC → 媒体 → 打开多个文件
  2. 添加所有 TS 文件(按顺序)
  3. 点击"播放"旁的小箭头 → 转换
  4. 选择输出配置文件和位置
  5. 点击开始

常见问题

Q: 合并后视频和音频不同步?

尝试使用 FFmpeg 重新编码:

ffmpeg -f concat -safe 0 -i filelist.txt -c:v libx264 -c:a aac -async 1 output.mp4

Q: 文件顺序错乱怎么办?

确保文件名按数字顺序排列。如果文件名是 segment_1.tssegment_10.tssegment_2.ts,需要重命名为 segment_01.tssegment_02.ts... 格式。

Q: 合并后无法播放?

可能是容器格式不兼容。尝试转换为标准的 MP4 格式:

ffmpeg -i input.ts -c:v libx264 -c:a aac -movflags faststart output.mp4

更好的方案

与其手动下载和合并 TS 文件,不如使用一站式工具直接从 M3U8 链接转换:

如果你需要先判断应该走在线工具、FFmpeg 还是桌面路径,可以继续阅读 M3U8 Merger 工具指南:3种方法合并TS到MP4,里面有按报错信号组织的排查矩阵。

M3U8 一键转换 MP4

无需手动下载 TS 文件,直接粘贴链接转换

立即使用 →

If you downloaded a video and got many .ts files, you are dealing with HLS segments. This guide explains three practical methods to merge them into one MP4 file.

⚠️ Note: If you still have the original M3U8 playlist URL, use M3U8 Converter directly to avoid manual segment operations.

Quick Overview

  • Method 1: FFmpeg command line - most reliable and flexible
  • Method 2: Online merge tools - easiest, but upload-dependent
  • Method 3: Desktop editors/players - visual workflow

📟 Method 1: FFmpeg CLI ⭐⭐ Medium

FFmpeg is the most powerful option for stable TS merging.

Step 1: Create a file list

Create filelist.txt and list all TS files in playback order:

file 'segment_0.ts'
file 'segment_1.ts'
file 'segment_2.ts'
file 'segment_3.ts'
...

Or generate it automatically:

# Windows
(for %i in (*.ts) do @echo file '%i') > filelist.txt

# macOS/Linux
for f in *.ts; do echo "file '$f'" >> filelist.txt; done

Step 2: Merge segments

# Fast remux
ffmpeg -f concat -safe 0 -i filelist.txt -c copy output.mp4

# Re-encode for compatibility
ffmpeg -f concat -safe 0 -i filelist.txt -c:v libx264 -c:a aac output.mp4

🌐 Method 2: Online Merge Tools ⭐ Easy

Good for users without FFmpeg, but there are upload limits and privacy trade-offs.

Recommended tools:

Steps:

  1. Open the merge tool website
  2. Upload TS files in the correct order
  3. Select MP4 as output format
  4. Start merge and wait for processing
  5. Download the merged MP4

Limitations: requires upload, weaker privacy, and large files may fail.

🎬 Method 3: Desktop Software ⭐ Easy

You can merge with visual tools if command line is not preferred.

Suggested software:

  • VLC Media Player - free and open-source
  • Shotcut - free editor
  • DaVinci Resolve - powerful free tier

Merge in VLC

  1. Open VLC → Media → Open Multiple Files
  2. Add TS files in exact sequence
  3. Use the arrow next to Play → Convert
  4. Select profile and output path
  5. Start conversion

FAQ

Q: Audio/video is out of sync after merge?

Try re-encoding with FFmpeg:

ffmpeg -f concat -safe 0 -i filelist.txt -c:v libx264 -c:a aac -async 1 output.mp4

Q: Segment order is wrong?

Ensure numeric sorting is correct. Rename files like segment_1.ts, segment_10.ts, segment_2.ts to segment_01.ts, segment_02.ts, etc.

Q: Output file cannot play?

Container/codec mismatch can cause this. Re-encode to standard MP4:

ffmpeg -i input.ts -c:v libx264 -c:a aac -movflags faststart output.mp4

Better Workflow

Instead of manually merging TS segments, use a one-step M3U8 to MP4 pipeline whenever possible.

If you need to decide between browser, FFmpeg, and desktop routes before execution, read M3U8 Merger Tool Guide: 3 Ways to Merge TS to MP4 for a signal-based troubleshooting matrix.

One-Click M3U8 to MP4

Paste M3U8 URL and convert directly in your browser

Use Now →