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 Moderator
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 Moderator
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!
 
Top