Jump to content

Fix MKV resume, fast forward and rewind issues WITHOUT remuxing.


pmurphy0881

Recommended Posts

pmurphy0881

I have seen many people have been switching to using mkv over mp4 in recent times and others complaining about playback issues with mkv.  Many know that remuxing can help but it's very time consuming to do so, but it works.  The issue is that the cues of a mkv file are normally written to the end of the file.  This is an issue that's been corrected with mp4 files with -movflags faststart option when encoding mp4 files, but with mkv it's a little different.  The script I have put together makes use of a program to move the cues to the front of the mkv and optimize the file for faster playback and better skipping and resume support.  So I have a rather large library and it's become a bit of a problem for me so I found a program called mkclean from matroska that is used to fix and move the cues to the start of the mkv file.

With very little documentation on the issue I had to go through a lot of trial and error to get things to work properly, but I put together a python script to fix this.  Attached is that python script for those of you who would like to try it out.  As of right now this guide is only for Windows machines but I still believe those that are using linux are more than capable of adapting this info for their environment.

Step 1: Download the MKClean file to a directory.

https://www.matroska.org/downloads/mkclean.html

My files are located in a separate drive lettered K: so I created a folder called K:\mkclean to house my mkclean.exe file.

Step 2: Download and install Python on your machine if you don't already have it installed.  You can see the link below for that.

https://www.python.org/downloads/windows/

Step 3: Open a command prompt as administrator and update pip to the latest then download the watchdog feature to python to be able to monitor your folders for newly added files.  Use the following command

python -m pip install --upgrade pip

when done then run

python -m pip install watchdog

Step 4: Once both of these commands are completed update your system environment PATH with an entry for mkclean.

Settings -> System -> About -> Advanced System Settings -> Environment Variables...

In the system variable section scroll down and select path and click on the edit button.

Then click on New to add an entry for the folder containing the mkclean.exe file.  (In my case it was K:\mkclean)

Once done click ok and reboot your system.

Step 5: Not it's time to create your python file.  Attached is a .txt version of the python file I created for myself and have been running.  You will need to edit it some, but I'm here to help with that.

NOTE THAT WHEN ENTERING A PATH YOU MUST ENTER IT WITH \\ AS EXAMPLE BELOW K:\mkclean WILL FAIL BUT K:\\mkclean WILL WORK.

(Below is the path were you want your database of the the files it's processed to be stored at, update it to the path you want your database created at, but please leave the files_processed.db name for ease of use of you will have to edit more lines.)

LINE 9:

DATABASE_FILE = 'K:\\mkclean\\files_processed.db'   

(Below is the path to make the connection to the database you created on line 9, be sure that the path matches what you have entered on line 9)

LINE 65  

conn = sqlite3.connect('K:\\mkclean\\files_processed.db')

LINE 77: 

conn = sqlite3.connect('K:\\mkclean\\files_processed.db')

 

(Below are lines identifying the folders to work it's way through looking for .mkv files and running this mkclean optimization script on. Change each line to identify your library folders.  You will need 1 line per folder that you are looking to process and it will search recursively through them for any .mkv file)

LINE 95 

process_existing_files("K:\\TV_Shows")

LINE 96:

process_existing_files("K:\\Movies")  

(Below is a line to identify the folders to monitor after it has completed it's initial task of recursively working it's way through your files and checking for .mkv files to optimize.  When new ones are added it will find them and run the optimization on them again making them perfect for streaming.)

On this line all the folders to monitor should be comma seperated values inside of double quotes and AGAIN take note of using \\ when entering a path vs a single \. 

LINE 99:

folders_to_watch = ["K:\\Movies", "K:\\TV_Shows"]

Step 6: Now when you go to save this I recommend saving this in the same folder as your database and the mkclean.exe file so you can locate it easily, but save it once with a txt extension for ease of updating later, and then save it again with a .py extension.

Step 7: Now you can run the file by opening a command prompt and entering this command.

python "K:\mkclean\mkclean_optimization_script.py" 

NOTE: To stop the running program hit CTRL+C with the command window active.

Step 8: Many of you would probably like to have this also start up when your system starts so it's easy enough to do by creating a .bat file and placing it in your startup folder.  I'm not going to walk you though that in this tutorial, but the code is simple enough to add for you and for you to make your edits to so it's below.

@echo off
python "K:\mkclean\mkclean_optimization_script.py"

 

PLEASE NOTE I AM NOT THE BEST PYTHON PROGRAMMER OUT THERE BY FAR AND THIS IS A PERSONAL PROJECT OF MINE THAT I'M MAKING AVAILABLE FOR YOU TO USE IF YOU LIKE, BUT I TAKE NO RESPONSIBILITY FOR IT IN ANY WAY.  PLEASE TEST OUT ON SOME COPIES OF FILES FIRST AND USE AT YOUR OWN RISK.

Other than that enjoy and let me know if this helped you out at all.

 

mkclean_optimization_script.txt

  • Thanks 1
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...