Welcome to Doom9's Forum, THE in-place to be for everyone interested in DVD conversion. Before you start posting please read the forum rules. By posting to this forum you agree to abide by the rules. |
|
|
Thread Tools | Search this Thread | Display Modes |
22nd April 2021, 10:27 | #1 | Link |
Registered User
Join Date: Feb 2003
Location: Palmcoast of Norway
Posts: 363
|
How to extract and calculate the framerate of the video in a mp4 container
hi, afaik, the mp4 container doesnt have a absolute moov atom describing the actual framerate of the video within, but its rather calculated based on the PTS/DTS timing values.
Are there tools, pref opensource, that can show the PTS/DTS values and do this calculation? I know mediainfo, ffprobe etc can do it, but i want to understand where in the mp4 container this data resides.. |
23rd April 2021, 09:39 | #2 | Link |
Registered User
Join Date: Jun 2020
Posts: 303
|
maybe https://github.com/nu774/mp4fpsmod
Tiny mp4 time code editor. You can use this for changing fps, delaying audio tracks, executing DTS compression, extracting time codes of mp4.
__________________
bShaders: realtime Effects/filters for video players |
23rd April 2021, 13:38 | #3 | Link |
Useful n00b
Join Date: Jul 2014
Posts: 1,667
|
The frame rate can be calculated from the number of samples and the duration:
Code:
u_int32_t mp4_numSamples = MP4GetTrackNumberOfSamples(mp4File, trackId); MP4Duration duration = MP4GetTrackDuration(mp4File, trackId); double msDuration = (double)(MP4ConvertFromTrackDuration(mp4File, trackId, duration, MP4_MSECS_TIME_SCALE)); double mp4_Frame_Rate = mp4_numSamples * 1000LL / msDuration; Last edited by videoh; 23rd April 2021 at 22:07. |
24th April 2021, 00:59 | #4 | Link | |
Moderator
Join Date: Jan 2006
Location: Portland, OR
Posts: 4,770
|
Quote:
The ES is generally what players go by, so it'd go for that. The MP4 headers can be wrong, and often give the average fps for variable frame rate content, which isn't that helpful. |
|
24th April 2021, 09:32 | #5 | Link |
Life's clearer in 4K UHD
Join Date: Jun 2003
Location: Notts, UK
Posts: 12,227
|
Indeed... Even back in the old MPEG-4 Part 2 encoding days, it soon became apparent after .mp4 container support was added to hardware playback devices, that the fps data needed to be added to the elementary video stream, not the container. Same too with the aspect ratio signalling.
__________________
| I've been testing hardware media playback devices and software A/V encoders and decoders since 2001 | My Network Layout & A/V Gear |
|
28th April 2021, 00:36 | #6 | Link | |
Moderator
Join Date: Jan 2006
Location: Portland, OR
Posts: 4,770
|
Quote:
Were I God of Video, I'd say that the elementary stream would always take precedence, and it's the job for each layer above to conform to it. |
|
28th April 2021, 05:43 | #7 | Link | |
Registered User
Join Date: Dec 2013
Posts: 349
|
Quote:
|
|
30th April 2021, 01:45 | #9 | Link |
Useful n00b
Join Date: Jul 2014
Posts: 1,667
|
It depends on the video format, i.e., AVC, HEVC, MPEG2, or VC1. Did you have one in mind? ES just means what you would get if you demuxed the video. You can consult the appropriate video specification. They are readily available. I'll help if you specify your format.
Be warned: there may not be a specification in the ES for any given file. |
30th April 2021, 10:11 | #10 | Link | |
Life's clearer in 4K UHD
Join Date: Jun 2003
Location: Notts, UK
Posts: 12,227
|
Quote:
When it comes to generating encodes suitable for playing in a 'hardware playback device', you should never create files with a variable frame rate, regardless of where the frame rate information is stored.
__________________
| I've been testing hardware media playback devices and software A/V encoders and decoders since 2001 | My Network Layout & A/V Gear |
|
|
1st May 2021, 17:31 | #11 | Link | |
Registered User
Join Date: Feb 2003
Location: Palmcoast of Norway
Posts: 363
|
Quote:
|
|
5th May 2021, 12:48 | #12 | Link |
Registered User
Join Date: Mar 2007
Posts: 95
|
If a player ignores the container PTS/DTS, then that player is hopelessly broken.
videoh code is not entirely correct. MP4 has a feature called "edit lists", and the tkhd box duration is equal to the sum of the durations of all of the tracks edits. But the edits can use less the actual samples in a track, so you can't divide it by the number of samples of the track. To get the actual frame rate, you would need to calculate the actual presentation timestamp of each sample included in an edit list, and them make an average. And edit list can change the rate at which samples at played or be a "dwell" without any sample for extra fun. Refer to the free ISO/IEC 14496-12 Fifth edition pdf for a description of all this fun little features. |
6th May 2021, 00:25 | #13 | Link |
Moderator
Join Date: Jan 2006
Location: Portland, OR
Posts: 4,770
|
Yeah, the MPEG-4 file format is derived from the QuickTime file format, which was Turing Complete! Modern implementations don't support all of the late 90's interactive features of QuickTime, but the file format was capable of things akin to what Director or HyperCard could create.
|
14th May 2021, 01:21 | #15 | Link | |
Moderator
Join Date: Jan 2006
Location: Portland, OR
Posts: 4,770
|
Quote:
More a technology can do same thing in different ways, the more implementations will wind up diverging. That was one nice thing about AVI as a format - it was so brain-dead simple it was really hard to get into trouble with it. |
|
Thread Tools | Search this Thread |
Display Modes | |
|
|