A Python-ese frontend for FFMPEG! 😎

Article by pkg-dot-zip
Published Mon, 17 Mar 2025 20:14:00 GMT (last edited Mon, 17 Mar 2025 21:10:00 GMT)

Python, a language I genuinely dislike, but extremely popular. 🌟 I believe that if you dislike something, but you have never used or experienced it you can not really make an argument at all. Time to create a project in Python! 🐍

Note

This project was created in under half an hour! ⌚ Isn't that crazy?! 🤯

What are we creating? 😮

Well, you see, I, for one, love my storage space! ~~Especially when I host media on a server of a friend of mine.~~

So it makes sense that we do not want to save everything. However, even when discarding all unneeded documents on your computer you might notice some everlasting enormous files: the videos. Unless you are hosting a cinema this should not be the case! 🎥

Introducing, FFMPEG, a beautiful cross-platform solution to record, convert and stream audio and video. This means you can also use it to compress your videos. In fact, I have always used FFMPEG to convert my videos to the .webm format when I want to send it to friends!

However, sometimes that is not good enough, or you want a different format, framerate etc. When typing I sometimes made typos and only realised after waiting for the conversion to be finished. We can avoid this with our own frontend GUI! 🤓

The good 😇

So, getting started was extremely easy. I already had PyCharm installed from a university course on machine learning, so I just opened it and got started. After some research I decided I was going to use TKinter for the GUI because it looked really straightforward. Look at how easy it is to create a label and a button together:

def create_crf_quality_slider(self):
    crf_label = tk.Label(self.root, text="CRF Quality (0-51):")
    crf_label.grid(row=2, column=0, sticky=tk.W, padx=10)

    self.crf_value = tk.IntVar(value=23)
    self.crf_slider = tk.Scale(self.root, from_=0, to=51, orient=tk.HORIZONTAL, length=200, variable=self.crf_value)
    self.crf_slider.grid(row=2, column=1, padx=10)

I then simply created the rest of GUI and that was it. We are almost done! 🤯

gui.png

Although extremely primitive, this is all I will ever need! I don't need control that precise. I need that file-size to go down quickly. 🏃🏻‍♂️💨

Compression

Building 🏗

Using PyInstaller it was extremely easy to create an .exe that embeds all packages required.

pyinstaller --onefile --windowed --add-data "resources/icon.ico;resources" main.py
12:33

This does mean we have a 8MB executable. I suppose that is quite unfortunate, but it was it is. 🤷🏻‍♂️ You can download the program here!

The bad & the ugly 🤮🤢

Python has no types! This makes it very easy to make mistakes. 😞 Look at this code:

@staticmethod
def stop_progress_window(progress_window, progress_bar):
    progress_bar.stop()
    progress_window.destroy()

Can you tell me exactly what type progress_bar is? 🤔

It is also completely legal (as in executable; you will not go to jail) to return multiple objects. I guess this is just a tuple with no types declared?

@staticmethod
def create_progress_window(app):
    # Progress window.
    progress_window = tk.Toplevel(app.root)
    progress_window.title("Compressing Video")
    progress_window.geometry("300x100")
    progress_label = tk.Label(progress_window, text="Compressing video, please wait...")
    progress_label.pack(pady=10)

    # Progress bar in window.
    progress_bar = ttk.Progressbar(progress_window, mode='indeterminate')
    progress_bar.pack(pady=10, fill=tk.X, padx=20)
    progress_bar.start()

    return progress_window, progress_bar

However, by far my biggest complaint is the lack of access modifiers. Python programmers wrap their function names with underscores and call it a day. This is ridiculous! 😭

Ridiculous GIF

What did I learn?

Well, after this project and the machine learning course I am confident enough to put Python on my CV, since I fully understand the language. However, that does not mean I like it. I will choose C++, Kotlin & C# all over Python without hesitating.

However, I do feel like I need to point out that I do not think it is a bad language. Python was never intended for a programmer like me to use it. It is made for non-programmers! So if you are reading this and think

You are so wrong! Python is the best!!! 🥰

I am happy that you feel that way! It's just not made for everyone. 🙂

If you want to download this project, checkout the releases on GitHub. That concludes this tiny project. Cya! 👋🏻