Batch Merging TS Files Using ffmpy3
2/20/2025Translate · Original Link
How to use Python's ffmpy3
package to batch merge TS files into a single MP4 file.
Before reading, you need to know:
ffmpy3
is a Python wrapper for FFmpegffmpy3
complies FFmpeg command line based on provided parameters and options
Using ffmpy3
Installing ffmpy3
Package
Install using pip
:
1 | pip install ffmpy3 |
Simple ffmpy3
Example
1 | import ffmpy3 |
The final result is equivalent to entering in terminal:
1 | FFmpeg parameter1 -i input_file parameter2 output_file |
Batch Merging TS Files
Directory Structure
1 | ├───folder |
file.txt
Write the TS filenames in file.txt
:
1 | file 'fileA.ts' |
Note:
- Use single quotes, not double quotes - the latter will cause errors!
- Use relative paths within the quotes
Python File
Use this code to batch merge TS files:
1 | ff = ffmpy3.FFmpeg( |
The above code is equivalent to entering in terminal:
1 | FFmpeg -f concat -i file.txt -c copy filename.mp4 |