m3u8 video format analysis

" Learn the m3u8 format. "

 

Some time ago, riding the wind of a beautiful CEO, I learned a new data format, the m3u8 format.

 

After a period of precipitation, the upsurge of beautiful CEOs has probably faded, and I only analyzed this format today, hehe.

 

First introduce the ins and outs:

One day, a screenshot of a WeChat chat record and a video were reposted in each WeChat group and spread, and then everyone saw a scene of four men and a woman playing Russian roulette, which lasted for tens of minutes. Some shame.

Then after several days of fermentation, the video was blocked by WeChat and could not be opened on WeChat. It is a pity for those who wanted to watch but didn't have time to watch it.

However, it doesn’t matter, the resource is still there, but it can’t be opened on WeChat, so I found out the address and opened it with a mobile browser. It’s very smooth, it’s this URL:

https://dadi-yun.com/20190305/1826_4d2ecxxx/index.m3u8

However, does the phone look uncomfortable?

So I tried to open it with a PC browser, but a text file was downloaded, which is very strange.

Therefore, after some analysis and study, this article was finally completed.

 

This article first analyzes the m3u8 format, and then introduces the method of extracting and merging data in this format to generate the final mp4 file.

 

 

01

format description

 

To introduce M3U8, we must first introduce M3U, which is a file format and a "special video format" for some mobile devices such as Android and Apple mobile phone browsers to cache videos. The M3U file is an indexed plain text file. When it is opened, the playback software does not play it, but finds the network address of the corresponding audio and video file according to its index for online playback.

M3U8 files refer to M3U files in UTF-8 encoding format, which is equivalent to a special case of M3U.

 

The main advantage of M3U8 is that it can do multi-bit rate adaptation. According to the network bandwidth, the client will automatically select a file that suits its own bit rate to play to ensure the smoothness of the video stream. It is mainly used on mobile devices.

 

Next, format analysis will be performed based on the URL of the beautiful CEO video.

 

First, we open the URL with the m3u8 suffix through the browser on the PC browser, and an m3u8 file will be downloaded. Open it with Notepad, and you can see the content as follows:

#EXTM3U

#EXT-X-STREAM-INF:PROGRAM-ID=1,BANDWIDTH=800000,RESOLUTION=1080x60

8800k/hls/index.m3u8

 

The first line is a fixed value for each m3u8 file.

The second line is the attribute of the file.

The third line is the url of the document being indexed.

 

This is a plain text index file. On the mobile device, due to the support of the system, it can be automatically downloaded and played according to the index. On the PC, windows and browsers do not support it, so we have to go to the index first. Download the next file before proceeding.

 

The next step is to get the url of the next step.

 

The "8800k/hls/index.m3u8" in the above index content is obviously incomplete and needs to be spliced ​​with the previous url. Of course, the previous url needs to remove the content of the last level file.

The splicing of this url is:

"https://dadi-yun.com/20190305/1826_4d2ec220/" + "800k/hls/index.m3u8" is "https://dadi-yun.com/20190305/1826_4d2ec220/800k/hls/index.m3u8"
The third step is to visit the spliced ​​URL, and another m3u8 file will be downloaded. Open it with Notepad, and you can see the content as follows:

 

#EXTM3U

#EXT-X-VERSION:3

#EXT-X-TARGETDURATION:8

#EXT-X-MEDIA-SEQUENCE:0

#EXTINF:4.000000,

2cb056dc5bb000000.ts

#EXTINF:4.000000,

2cb056dc5bb000001.ts

#EXTINF:4.000000,

2cb056dc5bb000002.ts

.

.

.

#EXTINF:4.000000,

2cb056dc5bb000447.ts

#EXTINF:1.400000,

2cb056dc5bb000448.ts

#EXT-X-ENDLIST

The above is a list, most of which have been omitted from copying for simplicity. It can be seen that the front of the content is the description of the normal M3U8 file, followed by an index list, from

2cb056dc5bb000000.ts to 2cb056dc5bb000448.ts, a total of 449 ts files in sequence, these are the specific video content file fragments, downloaded one by one, and then the final playable video file can be formed by merging the files.
The file URL here also needs to be concatenated, and finally looks like this:
https://dadi-yun.com/20190305/1826_4d2ec220/800k /hls/2cb056dc5bb000000.ts

 

The ts file is a transport stream file. The video encoding is mainly in h264 format , and the audio is in ACC format. This is based on practicality, so I won’t introduce it in detail. If you need it, you can leave a message and introduce it later.
The previous step-by-step manual operation is very troublesome, but if you understand the principle, can you write an m3u8 download converter? not difficult.
The purpose of this article is to learn scientific knowledge and improve professional skills, so the previous ones are important.
Of course, the purpose of learning is to provide better life services. Therefore, this article also provides a tool for downloading and extracting the final video file. The tool is realized based on the above principles. If necessary, please continue to read the next section.

 

 

 

02

Content Extraction Merge Tool

 

If you just want to learn the method and theory of this nearly 30-minute 4-man-1-female multiplayer Russian roulette game, you can use the online conversion website. Here is one:

https://jx.618g.com/?url=

Add the original m3u8 address after this equal sign to use the browser for real-time playback, but flash support is required. Of course, remember not to open it in public!

 

If you want to save this nearly 180M multiplayer game video on your PC, you still need to download this video. It is strongly recommended to download and save, the video content is very good.

 

The m3u8 file downloader used in this article is called ts assistant. It is easy to find online. Although it needs to be registered, it is basically no problem to download it a few times. It looks like this:

640?wx_fmt=png

 

Enter the URL of the m3u8 file, write the media name freely, select the directory you want for the download directory, and then click Add and Download to automatically download the video and merge it into the final mp4 file, but the interface design of this software is not automatic enough , if there is a caring person, it is also a kind of merit to improve the UI appropriately for the convenience of everyone.

 

Tool download address, please long press the QR code below to follow me, and send "m3u8" in the dialog box to get it.

640?wx_fmt=jpeg

Long press to follow.

 

 

 

 

 

 

Guess you like

Origin blog.csdn.net/yeyiqun/article/details/99310552