Question / Help Remuxing MKV file results in Variable Framerate

I started recording in mkv format to avoid corrupt files. It works amazing and allows for multi audio tracks. It's necessary to remux it to mp4 afterwards, otherwise Vegas won't play it.

Thing is, when remuxing via OBS I'm getting a variable framerate file. Is there a way to remux it and keep the constant framerate?
 

koala

Active Member
Simply remuxing from within OBS doesn't change the frame rate. If it is variable as mp4, it was variable as mkv. Post your recording settings or a log file with a recording in it, and we can tell if you recorded with a constant or a variable bitrate. Relevant is the rate control settings. CBR is constant, everything else is variable.
 
Last edited:

RytoEX

Forum Admin
Forum Moderator
Developer
Replying here a bit late because it was linked in a Mantis issue.

Simply remuxing from within OBS doesn't change the frame rate. If it is variable as mp4, it was variable as mkv. Post your recording settings or a log file with a recording in it, and we can tell if you recorded with a constant or a variable bitrate. Relevant is the rate control settings. CBR is constant, everything else is variable.
CBR (Constant BitRate) vs. VBR (Variable BitRate) has nothing to do with CFR (Constant Frame Rate) vs. VFR (Variable Frame Rate).

OBS produced media files should all be CFR. However, there is an issue I've been investigating where a remuxed file is read as VFR by media reading/parsing/probing tools where the original file is read as CFR. This even occurs when attempting to remux with directly with FFmpeg. I have a few theories and some test code, but I need to do some more experiments and tests, and OBS Studio 22 work had taken precedence. Now that OBS Studio 22 has been released, I'm looking at this again.
 

RytoEX

Forum Admin
Forum Moderator
Developer
Does any old version of OBS avoid this problem? I could keep an old version only for remuxing.
No. This is not specifically a problem with OBS, as far as I know. Remuxing with FFmpeg from commandline with default parameters will exhibit the same issue in some media software (editors, converters, parsers, etc.). I've been doing some testing into forcing a remux operation to stick to a specified framerate from metadata, but I need to do a lot more testing before I'd consider it stable and production-ready.
 
I'm bumping this thread to thank you guys for solving the problem in this entry: https://obsproject.com/mantis/view.php?id=1115

You can remux mkv to mp4 keeping all audio tracks and constant framerate by using the following ffmpeg command:
Code:
ffmpeg -i <filename>.mkv -c copy -map 0 -video_track_timescale 60 <filename>.mp4
I tested once and it worked. Need to do more testing to make sure it works as it should.

I went even further and made a context menu "mkv to mp4" so I can just right click any mkv file and remux it.

To do this, install ffmpeg in C:\ffmpeg and create a batch file named "mkvtomp4" (or whatever you want) with the code:

Code:
@echo off
setlocal ENABLEDELAYEDEXPANSION
set fName=%1
set ffmpeg="C:\ffmpeg\ffmpeg.exe"

for /f "tokens=* delims= " %%F in ('echo %fName%') do (
%ffmpeg% -i "%%~fF" -c copy -map 0 -video_track_timescale 60 "%%~dpnF.mp4"
)

Now open regedit and go to HKEY_CLASSES_ROOT\*\shell. Right-click on the “shell” folder on the left panel, and choose “New”>“Key”. Type “mkvtomp4” (or whatever you want). Right click on the newly created “mkvtomp4” key and choose again "New">“Key”. Type “command”. Now double-click the “(default)” value name on the right panel, and type the following:

Code:
"C:\ffmpeg\mkvtomp4.bat" "%1"

Credits to this page (I just adapted the code): http://fluorware.tumblr.com/post/12786344562/integrate-ffmpeg-in-right-click-menu-to-convert
 
Last edited:

EzioTheDeadPoet

New Member
Man thank you totally saved me here cause I had found a workaround that used Handbrake, but this is way faster and efficient.
And I litteraly created an account right now to say thanks. ;-)
 

CampbellChemin

New Member
Sorry to bump this again, but this also fixed this problem for me. In my case I was remuxing using MP4Tools for macOS (awesome tool), and MediaInfo was also reporting the change of constant to variable framerate.

I also made a command line function in case anyone needs it. From this point forward I assume you have some basic bash knowledge.
  1. Download ffmpeg and save it anywhere, let's assume it is in your Downloads folder.
  2. Add this function to your bash_profile:
  3. Code:
    mkv2mp4(){
        input=$1
        output=${input::${#input}-4}
        output="${output}.mp4"
        ~/Downloads/ffmpeg/./ffmpeg -i "$input" -c copy -map 0 -video_track_timescale 60 "$output"
    }
  4. In terminal, just run the function with the input file as the only parameter.
  5. The remuxed mp4 file will be created in the same folder.
Note that you can just write in terminal "mkv2mp4", drag your source file in and hit enter.
 

NineReflections

New Member
Apologies to resurrect this thread again.

I'm having the same issues with OBS recordings. It seems like you were the only ones to find a solution that didn't require using handbrake or similar software.

Unfortunately I remuxed all my recordings and deleted all my original mkv files before I found this thread. So now I'm left with 7TB of mp4 video that is really choppy and hard to edit in Premiere.

I followed the instructions from Guilherme Hoffmann and created the batch file context menu. This leaves me with two questions/issues.

1. I copied some files to a new location to test. When I run the command it tells me the file already exists and do I want to overwrite. When I enter "y" nothing seems to happen. Is there anyway to confirm it worked?

2. Will the code still work even though I'm going from mp4 to mp4?

Sorry for the newb questions. This is the first time I've ever messed with regedit ,batch files, and ffmpeg.

Thanks!
 

prantikv

New Member
is there a setting i can change to get 24 fps constant frame rate? currently getting varible frame rate and it is giving clip missmatch error in premiere pro.
 

RytoEX

Forum Admin
Forum Moderator
Developer
is there a setting i can change to get 24 fps constant frame rate? currently getting varible frame rate and it is giving clip missmatch error in premiere pro.
If you mean recording in 24 FPS instead of 24 NTSC (23.976), then simply change the Video settings to "Integer FPS Value" and "24".

If you mean that you're having a video file end up reading as Variable Frame Rate (VFR) after remuxing, no. As far as I know and have written previously, there is an inherent issue between how MKV handles timestamps/timebases and how MP4 does, so that when you remux from one to the other, you end up with some editors thinking the file is VFR, even though it is not. As I mentioned before, this occurs even when remuxing with FFmpeg directly. The only way I've seen to prevent this is to force a timescale, as shown in the scripts above, for which you have to know the timescale of the source file.
 

bartybutter

New Member
I also followed the instructions to create a context menu and I can't seem to get it to work. I've checked it over at least twenty times but every time I try to use it, it opens a command window for half a second and then immediately closes.

Not sure what information would be necessarily helpful but it would be great to get it working as ffmpegs conversion is about 5 times faster than shutter encoder.
 
Top