Earlier we covered all aspects of online short video seconds optimization, from server, CDN deployment access, data connection/acquisition, client cache, frame out strategy, to video file I frame location, etc.
Today, from another perspective of video file format, we introduce how the box order of MP4 files affects the online short video playback and second play optimization.
-
All data in MP4 files are installed in box (ISO-14496-12/14)
-
An MP4 is made up of boxes
Here are a few important boxes to keep in mind as you go along:
-
1. Ftyp box, at the beginning of the file, describes the version of the file, compatible protocol, etc.
-
2. Moov box, which does not contain specific media data, but contains macro description information of all media data in this file. Moov box contains MVHD and Trak boxes. MVHD records information such as creation time, modification time, time measurement ruler, and available playback duration. A series of sub-boxes in trak describe specific information about each media track.
-
3. Moof Box, which is the description information of video sharding. It is not a required part of MP4 files, but it is the most important part of all MP4 files that can be played online (such as ISMV files in Silverlight Smooth Streaming).
-
4, MDat box, actual media data. All the data that we eventually decoded and played was in here.
-
5. Mfra box, generally at the end of the file, is the index file of media, which can directly locate the media data required at the time point by querying.
MP4 file generation and analysis, playback
Generate: write mdAT first and then MOOV, so most tools will put MOOV data after MDAT, such as Android mp4Writer, FFmpeg and other tools 2. Parsing: When parsing playback, read mooV first before parsing MDAT
Play influence
1. Local playback, no impact, player software can first seek to the end, read MOOv 2. (3).(1) and (2) will introduce more or less delay, especially (2), affect the second open
Short video on the market mp4 box arranged
-
Douyin, Huoshan and other small video MOOv ranked first, do not seek;
-
Kuaishou, 360 and other MOOV ranked behind the need to seek;
1. Change files to the front of the moov box, during the creation of MP4 on the device or after uploading to the server. This method can be used once and for all.
ffmpeg option faststartqt-faststartCopy the code
Original author: Walker. Xu, the original link: https://segmentfault.com/a/1190000014405913
Welcome to follow my wechat public account “Code farming breakthrough”, share Python, Java, big data, machine learning, artificial intelligence and other technologies, pay attention to code farming technology improvement, career breakthrough, thinking transition, 200,000 + code farming growth charge first stop, accompany you have a dream to grow together.