How to calculate the playback duration of an MP4 File

Source: Internet
Author: User
Tags ultraedit

Calculate the playback duration of an MP4 file. You can obtain the timescale and duration values in the mvhd box:

Playback duration = duration/timescale

The Unit is seconds ).

The following describes the structure of mvhd.

Movie header atoms-mvhd

Movie header atom defines the features of the entire movie, such as time scale and duration. Its atom type is 'mvhd '.

The mvhd structure is as follows:

The fields are described as follows:

The following is a text description of the mvhd field:

Field

Length (bytes)

Description

Dimensions

4

The number of movie header atom bytes.

Type

4

Mvhd

Version

1

The version of movie header Atom

Flag

3

The extended movie header flag. Here it is 0

Generation Time

4

The start time of movie atom. The reference time is AM.

Revised on

4

The revision time of movie atom. The reference time is AM.

Time Scale

4

A time value that indicates the time scale for this movie-that is, the number of time units that pass per second in its time coordinate system. A Time Coordinate System that measures time in sixtieths of a second, for example, has a time scale of 60.

Duration

4

A time value that indicates the duration of the movie in time scale units. note that this property is derived from the movie's tracks. the value of this field corresponds to the duration of the longest track in the movie.

Playback speed

4

The speed at which the movie is played. 1.0 indicates normal playback speed

Playback volume

2

Play the volume of this movie. 1.0 indicates the maximum volume.

Retained

10

Here is 0

Matrix Structure

36

This matrix defines the ing between the two coordinate spaces in the movie.

Preview time

4

Start Time to preview this movie

Preview duration

4

In the unit of time scale of movie, preview the duration

Poster time

4

The time value of the time of the movie poster.

Selection time

4

The time value for the start time of the current selection.

Selection duration

4

The duration of the current selection in movie time scale units.

Current Time

4

Current Time

Next track ID

4

The ID of the next track to be added. 0 is not a valid ID value.

Instance analysis:

For example, the duration of a 1mt.mp4 file is 70000 ms, that is, 70 s ):

Use the mp4info tool to view the following red boxes:

The total duration is 70 s, the duration is 42000, and the timescale is 600.

Based on the calculation method described at the beginning of this article, first look at the structure of the mvhd box.

Both mp4info and ultraedit can be used to view the structure information of mvhd, but the number of digits displayed is incomplete. It should be 108 bytes and only 100 bytes. The reason is unknown, it may be the cause of the tool.

Use ultraedit to view details, as shown in:

The Shadow part is all mvhd boxes with a length of 108 bytes, that is, 6C.

The value of timescale in the red box is 00000258, which is converted to decimal value 600.

The values in the following green box are duration and a410, which are converted to decimal 42000.

Therefore, according to the formula duration/timescale = 42000/600 = 70 s.

This duration is the total file length, which is longer in audio and video track.

Refer:

Obtain MP4 file information 1-calculate the length of a movie

Http://www.52rd.com/Blog/Detail_RD.Blog_wqyuwss_7928.html

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.