Monday, September 14, 2020

Fixing: "matplotlib error - no module named tkinter" in Windows 10

If you are using python 3.x in Windows 10 and encoutered this error: "matplotlib error - no module named tkinter", it's very possible that you didn't install the Tcl/Tk module when installing Python to your machine. The tkinter module comes from Tcl/Tk. Fear not, you don't need to uninstall and reinstall Python to fix it. You only need to modify your Python installation to install the missing Tcl/Tk support as follows:

  1. Go to Add/Remove Programs from Windows 10 search box. From there, select your Python installation, like this: 

  2. Then click the option to modify the Python installation. You'll be presented with this dialog: 

  3. Then click on the Modify option in the Python installer dialog. In the Optional Features dialog that shows up, make sure you checked the tcl/tk and IDLE option, like this (inside the red box): 

  4. Next, just follow the instruction after clicking on the Next button to apply the changes.  
After this, the matplotlib error should be fixed as the tkinter python module is installed. 

Note that even if you install the tcl/tk library via pip install successfully when encountering the matplotlib error, you will probably still left with the same matplotlib error. I'm not sure why it happened in my system. It's probably the module search path is somehow not working properly unless you do a "user/account-wide" or system-wide installation for the module to make it work. In any case, the solution above fixed the error in all cases that I have tested. I think it should work for you too. 

Monday, September 7, 2020

Removing "Still" Frames from Video Files with Ffmpeg

 Ffmpeg is a very versatile tool for video pre-processing and post-processing. One of its most useful feature is removing frames which doesn't have a lot of changes in it, i.e. relatively static background. The parameter to use for this purposes is the mpdecimate flag, the presentation timeframe (setpts)flag might also be used for synchronization purposes. In my case, the command I used to throwaway the relatively static vidio frames as follows:

ffmpeg -i input_vid.mp4 -vf mpdecimate,setpts=N/FRAME_RATE/TB output_vid.mp4

Details about the mpdecimate flag can be read over at: https://ffmpeg.org/ffmpeg-filters.html#decimate-1, and details about the setpts parameter is at https://ffmpeg.org/ffmpeg-filters.html#toc-setpts_002c-asetpts. Hopefully, this is helpful for you.