How to convert ts format file to MP4 format file

Reading this article carefully will let you fully understand:

  1. How to convert ts to mp4 in cmd
  2. How to merge many ts files into mp4 files with python
  3. How to define the order in which ts are merged into mp4

What is TS

Let's take a look at Baidu Encyclopedia's sophistry
insert image description here
. In short, a ts file is a video clip , which is mainly used in real-time transmission programs.

For example, some of the videos we watch online, many of them are sent ts files from the background, and then play them one by one for us to see. We insert image description here
send ts files while watching the background, so we can enjoy the video smoothly.

Convert TS files to MP4

A ts file can be played for a few seconds, which is not pleasant to watch. It would be great if we could combine them into one MP4 file.

For example, convert these ts files to MP4

insert image description here
We can use the copy /b E:\ts\*.ts E:\Pikachu Detective.mp4 command in cmd

Note that slashes and backslashes cannot be reversed, otherwise an error will be prompted

insert image description here
Haha, a video is synthesized in the path you specified. Now that we have seen the appearance, it is time to understand the truth behind it.

copy /b E:\ts\*.ts E:\Pikachu Detective.mp4 Merge all ts files in the source path into the target path in binary format
copy /b means merge in binary format
E:\ts\*. ts means all ts files in the ts directory under the E disk
E:\Pikachu Detective.mp4 means the directory where the generated files are stored

Precautions

To avoid confusion in the merged video, we have to name each ts file
because the order of merging is based on the name of the ts file : the command is compared character by character from left to right in the file name, and the smaller file name is merged first; For example, let's change the ts file name: 013.ts in the figure is smaller than 08.ts, so this command will merge 013.ts first, and then merge 08.ts file

insert image description here

Convert ts file to MP4 file with python

As a glorious programmer, we will never do the work that can be done in the code manually.
In the py file:

import os
os.system(r'copy /b E:\ts\*.ts E:\皮卡丘大侦探.mp4' )

os.system() can run shell or CMD commands
At this point, the process of converting ts to mp4 with python has been completed, over

Guess you like

Origin blog.csdn.net/qq_36291294/article/details/99650386