Use php to analyze the format of mp4 video files

不言
Release: 2023-03-24 13:34:01
Original
2730 people have browsed it

This article mainly introduces the format of analyzing mp4 video files using PHP. It has certain reference value. Now I share it with you. Friends in need can refer to it

In recent work, when doing third-party development of small programs, I encountered a problem with the video component of the small program. The development feedback was that because the level of the video component is too high, it always floats at the front and blocks the elements behind it when scrolling.

So the developer said that they need to change the plan and put a screenshot of the video on the original list page, so that users can click on the screenshot to jump to a new page to watch the video. , that page only has one video component, so it will not cause other problems because it is too high-level.

This new solution is feasible, but after the development was completed, I found that the video shot on Apple was rotated, and the cutout pictures were also rotated (using It is Alibaba Cloud’s OSS video screenshot function). As shown in the picture below


##This brings A new problem. Front-end development needs to know how many degrees the video has been rotated, and then rotate the image by the same degree in reverse, so that the effect seen by the user is no rotation.

This requires the back-end interface to analyze the rotation degree of the video and store it in the DB when it receives the uploaded video.


The current problem is that this historical business system was developed using PHP5.5, and the technical leader at the time compiled and installed it from source code, but the php-ffmpeg plug-in is too old and has not been maintained. There are too many problems compiling on php5.5.

#So there is a need to use php to analyze the mp4 video file format taken by Apple mobile phones.



#The implementation principle is to analyze the video transformation matrix in the head tkhd of the mp4 video trak box, and determine how much the rotation has been done through the videotransformationtransformation matrix degree, as shown below.



##Basic of mp4 file format The unit is an atom (or box). The file format structure of mp4 is not posted here. You can search it online.

The effect after implementation is as follows:


Test results, compare with the mobile phone rotation example in the picture above:


https://gitee.com/clwu/IphoneMp4Probe


The above is the detailed content of Use php to analyze the format of mp4 video files. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template