Cannot include ffmpeg.exe using auto-py-to-exe

53 Views Asked by At

I'm trying to generate an exe for my PyQT application that uses ffmpeg using auto-py-to-exe.

Within the application, there are calls to ffmpeg as an os command (like 'ffmpeg -i file ... output) . As I have ffmpeg installed on my machine and accessible from the Windows Path, when I run the app exe on my machine, I don't have any issue.

However, when it's someone that doesn't have ffmpeg installed, he/she encounters an error like "'ffmpeg' is not recognized as an internal or external command, operal program or batch file"

I don't want to put ffmpeg within a folder of the app as I call local modules that already call ffmpeg as an os command.

I have tried first to add ffmpeg.exe as a file (as recommended in one stackoverflow post) and then as a binary but without success autopytoexe

I've already tried with the configuration stated in this

Can anyone help me on this ?

EDIT N°2

It turns out that when I export the exe on my machine by including ffmpeg as a binary either with pyinstaller or auto-py-to-exe, the final exe doesn't recognize the ffmpeg command even if it's in the folder.

__internal folder

However, I've tried the same configuration on another machine and it worked without any error.

I've tried to install another ffmpeg version and link this version on the final exe but without success

1

There are 1 best solutions below

1
Explosivedoor On

Answer that helped me with it was here. I added ffmpeg.exe to binary at root and added it as an additional file at root.

--add-data "D:/sdw/ffmpeg/ffmpeg.exe;." --add-binary "D:/sdw/ffmpeg/ffmpeg.exe;."  

Then in the code you need to call the ffmpeg -i... stuff with an absolute path to the resource as highlighted in the above answer.

def resource_path(relative_path):
""" Get absolute path to resource, works for dev and for PyInstaller """
    try:
    # PyInstaller creates a temp folder and stores path in _MEIPASS
        base_path = sys._MEIPASS
    except Exception:
        base_path = os.path.abspath(".")

    return os.path.join(base_path, relative_path)

so the subprocess.run is something like

subprocess.run(resource_path('ffmpeg -i .... ')

This worked for me, however I am just noob working on a small project so I hope it at least points you in the right direction.