Converting All My divx Video Files to mkv Because of Plex

For a long time, we have been using the Raspberry Pi 2 with RasPlex as a frontend for Plex server. However, the RasPlex project seems to be dead as there has not been updated since 2017.
featured.jpeg

For a long time, we have been using the Raspberry Pi 2 with RasPlex as a frontend for Plex server. However, the RasPlex project seems to be dead as there has not been updated since 2017. They do not even have support for the latest Raspberry pi that was released about a year ago. The Raspberry Pi itself has also been quite unstable and constantly corrupts the SD card. So, about 2 months ago I got so frustrated that I stopped using it at plugged in our old gen 1 Chromecast. But, we quickly became tired of us having to start the movies for our kids instead of them being able to just select one themselves. That is why I the other day bought an Nvidia Sheild 4K. I removed everything but YouTube and installed Plex. However, I quickly ran into an issue.

The Plex client for the Nvidia Sheild will not play any of our .divx files at all. It will try for a while and then tell me that my connection to the server is not fast enough to play the file. It quickly became clear that I had to somehow convert all Divx files to something else. I used DivX when I first started to rip DVDs in early 2000. I wanted to do this without having to re-encode the video files because they are already of quite low quality.

A quick google search showed me a couple of methods to convert from one container to another. One uses FFmpeg and the other MKVtoolNix GUI. I opted for the MKVToolNix because it has a GUI. I converted one .divx file and tested that the Plex client would play it. It did. I then wrote a quick script to count the number of video files with the extension .divx on my server just to get an idea of the amount of DivX files. There was 510. Way too many to do by hand via the GUI

I used the GUI to set the settings and used to option to generate a command. I then made a quick python script that would find all files with the extension .divx on my server and convert it to the MKV container using the command generated by MKVToolNix and rename the original video file to have a .backup extension just in case I need the original file for some reason.

import os
import subprocess
count = 0

folder_to_search = '<MOVIES FOLDER>'

for root, dirs, files in os.walk(folder_to_search):
    for file in files:
        if file.endswith(".divx"):
            filename = os.path.join(root, file)
            filename_base = os.path.splitext(filename)[0]
            filename_new = filename_base + '.mkv'
            count += 1
            print(f"{count}: Converting: {filename_new}")

            cmd = f"/usr/bin/mkvmerge --ui-language en_US --output '{filename_new}' --language 0:und --language 1:und '(' '{filename}' ')' --track-order 0:0,0:1"
            print (subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE).stdout.read())
            os.rename(filename, filename_base + '.backup')

This is the first time that I have had issues with playing my DivX video files. Every other Plex client, not to say every other media player, I have used has played these files fine. Ohh well, everything seems to work now and I can watch my old movies again 🙂