Convert ts video files to mp4 (FFmpeg)

        Some video resources are found to be .ts files. In addition to using the tool or browser used to download them to view them, is there any way to convert the ts files into a more universal video format?

The almost universal audio and video tool-ffmpeg is here

For installation and environment configuration, please see this blog:FFmpeg command line to open USB camera (windows)_ffmpeg to open camera_athrunsunny's blog-CSDN blog

1. For a single .ts file, convert it to mp4

instruction:

ffmpeg -i xxx.ts output.mp4

2. Multiple .ts files, convert them to mp4

Most of the time, ts files do not exist individually. Here, they need to be merged and then converted into mp4. If it is a windows system, you can create a new .bat batch file and write the following code

@echo off
setlocal enabledelayedexpansion

set OUTPUT_FILE=file_paths.txt
set TEMP_FILE=temp.txt

type nul > %OUTPUT_FILE%
type nul > %TEMP_FILE%

dir /b /s /a-d > %TEMP_FILE%

for /f "usebackq delims=" %%F in ("%TEMP_FILE%") do (
    set "file=%%~F"
    if not "!file:~-4!"==".bat" (
        echo file '%%~F' >> %OUTPUT_FILE%
    )
)

del %TEMP_FILE%

echo done %OUTPUT_FILE%

At this time, place the .bat file in the folder where the .ts file is stored and run it. You can change the paths of all .ts files in the current path to:

file 'X:\xxxx\xxxx\xxxx\xxxx\xxxx.ts' 

The form is saved in file_paths.txt

instruction:

ffmpeg -f concat -safe 0 -i file_paths.txt -c copy output.mp4

If you encounter an error:

ffmpeg -f concat -safe 0  -i file_paths.txt -c:v copy -c:a copy -bsf:a aac_adtstoasc output.mp4

Guess you like

Origin blog.csdn.net/athrunsunny/article/details/134470176