Have anyone make python bindings on windows for mltframwork

I am trying to follow the instruction from the official website, but since I am a beginner programmer, I am always failed to do the compile with SWIG for python binding on windows.

I struggled years ago, failed, now I tried again, still failed. too much out of my league.

If anyone successfully made such python binding for mltframework(melt) , can you help to share here, much appreciate for you generous. Thank you.

I have not done it, but here are some tips:

  • Use only msys2, not the old instructions with a warning at the top of the page.
  • Install additional dependencies from msys2 incrementally by running cmake for MLT to see what is missing. Here is a list of some suggestions:
autotools base-devel coreutils git gzip tar xz zip bzip2 swig
  • If there is a dependency you cannot find or do not care about disable the module with a cmake -D MOD_GDK=OFF for example. Read mlt/CMakeLists.txt to see which modules are available to turn off.
  • Add -D SWIG_PYTHON=ON to the cmake command line to add that. I do not know which python packages it requires.
  • Use the -G Ninja to build with ninja instead of make.

Hi Den,
Much appreciate for your help.

With your answer I finally collect all the courage and try it for all day, finally make it going.

Here is something I found out which may help someone in the future:

  1. install all dependencies as den said.
  2. use this command to get around all the missing part: cmake -D MOD_GDK=OFF -D MOD_MOVIT=OFF -D MOD_PLUS=OFF -D MOD_QT=OFF -D MOD_SDL1=OFF -D MOD_RTAUDIO=OFF -D MOD_JACKRACK=OFF -D SWIG_PYTHON=ON -G Ninja
  3. simplly using ninja to compile. //take me sometime to know why build file generated, but no dll can be found.
  4. not sure if this step is needed or not, I get error when using: ImportError: DLL load failed while importing _mlt7 so I tried to add this two line:
    LINK_DIRECTORIES(“D:\Program Files\Python38\libs”)
    LINK_LIBRARIES(“D:\Program Files\Python38\python38.dll”)
    according this answer:c - MinGW / SWIG built python extension failing to load in Anaconda command terminal - Stack Overflow
    // also be forced to learn a bit about gcc commandline and cmake
  5. after the above steps, I still get error when using: ImportError: DLL load failed while importing _mlt7 so I tried to add this two line:
    take me a lot of hours to trouble shouting, using depencies tool serveral times, all the dependecies resolved good, and try to debug it using x64dbg, seems all fine, but finally I found some library is using the dll under git install path. I’ve got git in my path, so some library such as libgcc_s_seh-1,libiconv-2 from git maybe not compatible. I replace it with those coming from shotcut folder.

Suddenly it works. But still I there is something wrong

import mlt

import sys

from PIL import Image

# setup


profile = mlt.Profile('square_pal_wide')

prod = mlt.Producer(profile, r"D:\mysites\mlt\out\dianzan_3.mov")

the prod.get_length() returns 0. Seems the producer didn;t generated success.

I don’t know what’s wrong when running the example, no hit so far. Anyone know this?

Thanks again.

did anyone know why producer cannot init correctly? did I missed some required dependencies? Is there any way I can debug the problem?

What does prod.debug() show?

the return is None.

I wonder if the dll libraries I copied from shotcut is compiled by MSVC instead of GCC, which makes them incompatible.

OK, I checked, all is gcc, but different version

One thing you are going to have a problem with is MLT locating its data files such as profiles. The Windows build is a relocatable such that it locates run-time data files relative to the executable. This works fine for things such as melt.exe, shotcut.exe, and kdenlive.exe but not python.exe if that is not in the same location as the MLT framework DLLs. I doubt that is why prod is None. More than likely the libmltavformat.dll is not loading. It expects its dependent DLLs to be in the executable’s directory if they are not in the %PATH%. You can set environment variables (either MLT_DATA or MLT_PROFILES_PATH) to help it locate profiles when you get to that point. But first you need to get melt.exe working to verify your MLT build before jumping into code.

yes, you are right, it’s the environment issue.
In windows, without pass a module handle to function GetModuleFileName, it will return python’s path if we suing python bindings, which is the main EXE file directory instead of DLL directory

But I changed the environment, so all solved, thank you again for your help.

another way I tried with change the code:

  HMODULE GetCurrentModule()
  { // NB: XP+ solution!
      HMODULE hModule = NULL;
      return hModule;

HMODULE hm = GetCurrentModule();
  ::GetModuleFileName(hm, path, MAX_PATH);

This topic was automatically closed after 90 days. New replies are no longer allowed.