MKV recording doesn't respect FPS values

Boldegg

Member
Hi, I've found an issue with the MKV encoder. The point of using the MKV container is that it doesn't require a finalizing process, so in case of crash, bsod, etc the video isn't corrupted. This is important as my goal is to record a live podcast that can't be re-recorded. MKV also supports uncompressed audio stream.

The issue is that OBS doesn't record the FPS values correctly in MKV while it's working perfectly in MP4. I've even remuxed my MKV files to MP4 using ffmpeg and the correct timecode comes back after remux is done. Pretty strange...

MKV(x264/pcm_s24le) - 59.94 FPS
https://www84.zippyshare.com/v/wMcyNFeY/file.html

Format profile : High@L4.2
Format settings : CABAC / 4 Ref Frames
Format settings, CABAC : Yes
Format settings, Reference frames : 4 frames
Codec ID : V_MPEG4/ISO/AVC
Duration : 1 min 0 s
Bit rate : 9 374 kb/s
Nominal bit rate : 10 000 kb/s
Width : 1 920 pixels
Height : 1 080 pixels
Display aspect ratio : 16:9
Frame rate mode : Constant
Frame rate : 60.000 FPS

Full MediaInfo https://pastebin.com/Ctkv1vAw

MKV(x264/pcm_s24le) - 60 FPS
https://www84.zippyshare.com/v/N44PIPZS/file.html

Format profile : High@L4.2
Format settings : CABAC / 4 Ref Frames
Format settings, CABAC : Yes
Format settings, Reference frames : 4 frames
Codec ID : V_MPEG4/ISO/AVC
Duration : 1 min 0 s
Bit rate : 10 000 kb/s
Width : 1 920 pixels
Height : 1 080 pixels
Display aspect ratio : 16:9
Frame rate mode : Constant
Frame rate : 60.119 FPS

Full MediaInfo https://pastebin.com/zSRRccYZ

MP4(x264/aac) - 59.94 FPS
https://www84.zippyshare.com/v/wMcyNFeY/file.html

Format profile : High@L4.2
Format settings : CABAC / 4 Ref Frames
Format settings, CABAC : Yes
Format settings, Reference frames : 4 frames
Codec ID : avc1
Codec ID/Info : Advanced Video Coding
Duration : 1 min 0 s
Bit rate : 10 000 kb/s
Width : 1 920 pixels
Height : 1 080 pixels
Display aspect ratio : 16:9
Frame rate mode : Constant
Frame rate : 59.940 (60000/1001) FPS

Full MediaInfo https://pastebin.com/BkshFD6N

MP4(x264/aac) - 60 FPS
https://www84.zippyshare.com/v/Fh3sKuzq/file.html

Format profile : High@L4.2
Format settings : CABAC / 4 Ref Frames
Format settings, CABAC : Yes
Format settings, Reference frames : 4 frames
Codec ID : avc1
Codec ID/Info : Advanced Video Coding
Duration : 1 min 0 s
Bit rate : 10 000 kb/s
Width : 1 920 pixels
Height : 1 080 pixels
Display aspect ratio : 16:9
Frame rate mode : Constant
Frame rate : 60.000 FPS

Full MediaInfo https://pastebin.com/GcwJSZPU

As you can see the framerate isn't respected recording in MKV format where 59.94 FPS ends up as 60 FPS and 60 FPS ends up as 60.119 FPS.

Thank you for the person who'll explain me the science behind this intriguing behavior!
 

konsolenritter

Active Member
Your zippyshare links doesn't work, unfortunately (at least for me, using firefox). (nginx - 403 forbidden reported)

Interesting fact. Who reported these information from the files?
And: If you record to mkv and remux within obs, does the information regarding such remuxed mp4 files show the same strange behaviour?
 

konsolenritter

Active Member
I checked again. Read on: A "403 forbidden" is given by the nginx, which is the webserver at zippyshare.

So it seems that zippyshare possibly works great for you, because you're (for sure) logged in there.
Can anybody else see the contents there?
 

TryHD

Member
zippyshare blocked access from germany because of some german copyright trolls, that is why you see the 403.
 

Boldegg

Member
Hi and really sorry that zippyshare is blocked in your country. Here's a Mega link that should work in germany.


There's definitely an issue with OBS custom ffmpeg recording. Here's a detailed explanation from a member of videohelp concerning the issue and the 60.119 FPS MKV file. So in fact OBS doesn't create true 60 FPS files. Note that there were 0 frame dropped/missed in these recordings.

Normally it's jitter in the timestamps, because of the MKV timebase 1/1000. ie. It's not precise enough . 1ms

If you extract the timestamps, the delta PTS varies between frame. You cannot divide 1/60 (~ 0.0166666...) evenly into that timebase resulting in an exact value each frame. So each entry rounds up or down.

A "normal" 60/1 FPS CFR in MP4 looks like this: the delta PTS is constant, and predictable

Code:
# timecode format v2
0.00
16.67
33.33
50.00
66.67
83.33
100.00
116.67
133.33
150.00
166.67
183.33
200.00
216.67
.
.

MKV container specs only allow 1ms, so values are rounded to the nearest ms . So you get a delta PTS of 16 or 17, and that is variable.

Code:
0
17
33
50
67
83
100
117
133

I'm not sure how mediainfo calculates how it declares "constant", but in actual recordings, sometimes at the beginning or end, there are duplicate frames as recording "warms up" so that can cause deviation. Also, frame drops can cause deviation from the constant pattern . Any deviation is technically variable frame rate

But of we take mkv-60.mkv, track 1 timestamps are really buggy, it looks like this

Code:
# timestamp format v2
0
21
43
64
85
107
128
149
171
192
213
235
256
.
.

delta is 21,22.. etc. and at the end there are repeats. But ~ 21 delta PTS average means the fps is ~47 , not 60

1/60 =~ 0.016666.. . So you should be seeing 16.7 ms for each entry (again round up, round down) , but the point 21 suggests a different framerate

There might be something else going on with the audio timestamps, but this is abnormal

Thank you for helping and hope this report will help OBS team to fix these critical issues.
 

Suslik V

Active Member
Unfortunately, small precision is set in the FFmpeg (OBS uses it to write the files)... and this way it works everywhere:


matroskaenc.c said:
Code:
// ms precision is the de-facto standard timescale for mkv files
avpriv_set_pts_info(s->streams[i], 64, 1, 1000);

Nothing to fix on OBS side.

You still can write into mp4 but with some caution: https://obsproject.com/forum/thread...g-and-eventually-corrupts.147212/#post-538560
 

Boldegg

Member
What does it mean? If you read the quote in my last reply it's said that the MKV file is abnormal and the FPS is wrong at ~47 FPS instead of 60 FPS. Why is that?

You still can write into mp4 but with some caution:

No I can't since the m4v container can't have a lossless audio track which is essential for my project.

Thank you for helping.
 

Boldegg

Member
Use the QuickTime container.

The MOV container wont be recoverable if there's a power loss, BSOD, freeze, etc. The only formats that does it are FLV and MKV to my knowledge.

Unfortunately, small precision is set in the FFmpeg (OBS uses it to write the files)... and this way it works everywhere:


Nothing to fix on OBS side.

For the precision issue - it's not ffmpeg/libavformat's fault, they are just following MKV container specs. To code more precision would break specifications.

But the timestamps are buggy regardless of the precision issue - There is more than 1 issue at play here.

 

rockbottom

Active Member
User was warned for this post.
If your scared about losing a recording, tough shit. Get over it....

I'm not using OBS that much anymore, but in 6 years of using it, I never lost a single recording.

Use AVIDEMUX if you record to MKV to save your audio tracks, works with just about everything except Floating Point.
 

Suslik V

Active Member
Nobody will going to fix the things that are not broken. Abnormal? Maybe.

It could be better if you have posted the actual OBS log-file (maybe there was dropped frames during recording) and described the issue you had.
The tracks length (audio/video) can be different (and to be honest it different in many many media files).

If the main issue is the tracks length difference then additional info is needed - where they were desynchronized (device fault or...???).
If audio is simply longer but stays in sync you can cut it... By the way, for MP4 the movie lasts as longest track.
 

Boldegg

Member
If your scared about losing a recording, tough shit. Get over it....

Why are you even commenting. It's not because YOU don't need a feature that everyone else should. I need a safe workflow because we can't take the chance to lose a track as it's a live podcast. We're 4 people in 4 different studios and can't lose a track.

Use AVIDEMUX if you record to MKV to save your audio tracks, works with just about everything except Floating Point.

The workflow is kind of complicated as we're in 4 different studios, but I gotta keep things simple. Even if MKV recording is broken on OBS, the files still works, so that's just gonna be it. Take this thread as a bug report, if the devs care.

Nobody will going to fix the things that are not broken. Abnormal? Maybe.

Thing is that it is broken, but it seem you don't understand the reply from video help.

It could be better if you have posted the actual OBS log-file (maybe there was dropped frames during recording) and described the issue you had.

I've monitored the files while recording, they're 1 minute recordings and had 0 drop/missed frames whatsoever. Perfect recording.

If the main issue is the tracks length difference then additional info is needed - where they were desynchronized (device fault or...???).
If audio is simply longer but stays in sync you can cut it... By the way, for MP4 the movie lasts as longest track.

A/V is synced on a 4 hours recording, with a 8-10 hours recording the MKV file gets corrupted using custom ffmpeg. I only need 2 hours maximum, so I don't really care about this issue as it's indistinguable. This is more a bug report for the devs if they care.
 

rockbottom

Active Member
User was warned for this post.
Dude we get it, would you like some cheese with that whine?

Either you opt for a fault tolerate recording or the 60 FPS but you're not getting both with OBS at the moment or if ever. If you absolutely positively have to have both right now, I suggest you find another app that offers what you require. Expect to pay for it too.....
 

Fenrir

Forum Admin
Bit late on this, but please be kind and respectful to other members of the community. Personal attacks are never warranted, and warnings have been issued where appropriate.
 
Top