0

I'm trying to create a python script that deals with audios and videos. so, I need to use ffmpeg and it works -for details, I used a CLI program that deals with it, not me-, but when I tried to create an exe file using pyinstaller, it doesn't contain ffmpeg packages within it! Now, if anyone want to use the app, he couldn't until he downloads ffmpeg independently, and it's a further step that makes it harder reach my app. What is the solution/the way to embed ffmpeg with my app?

  • What I'm expecting is to find a solution...
  • What I've tried is that:
  • I tried to search on google, but I found nothing.
  • I tried to ask chatGPT and it gives me a script that doesn't work :)
# my_app.spec
# Run with: pyinstaller my_app.spec

# Basic PyInstaller configuration
block_cipher = None

a = Analysis(['main.py'],  # Replace 'main.py' with your Python script
             pathex=['.'],
             binaries=[('C:\\ffmpeg\\bin\\ffmpeg.exe', '.'), 
                       ('C:\\ffmpeg\\bin\\ffplay.exe', '.'),
                       ('C:\\ffmpeg\\bin\\ffprobe.exe', '.')],
             ...

             # Rest of the Analysis configuration goes here

             pyz = PYZ(a.pure, a.zipped_data,
                      cipher=block_cipher)

             exe = EXE(pyz,
                       a.scripts,
                       a.binaries,
                       a.zipfiles,
                       ...

                       # Rest of the EXE configuration goes here
)

  • You may find it easiest to use an ffmpeg wrapper for Python - e.g.: https://github.com/kkroening/ffmpeg-python – Mick Aug 16 '23 at 11:51
  • Thanks @Mick! but I don't use ffmpeg directly, the tool I used which is -yt-dlp-, it used ffmpeg not me – Abdelrahman Zaki Aug 17 '23 at 15:07
  • If your code runs properly, I guess you need to put these binaries inside their own directories. Tell the code to read it from these directories while it is bundled. – F T Aug 18 '23 at 09:20
  • @FT, yeah it does it really, before I used to put ffmpeg in PATH variable, but now putting ffmpeg in the same Dir as my exe app will work probably Thanks – Abdelrahman Zaki Aug 22 '23 at 10:12
  • What I am trying to say looks like the following: ` `` a = Analysis(['main.py'], # Replace 'main.py' with your Python script pathex=['.'], binaries=[('C:\\ffmpeg\\bin\\ffmpeg.exe', 'ffmpeg/'), ('C:\\ffmpeg\\bin\\ffplay.exe', 'ffplay/'), ('C:\\ffmpeg\\bin\\ffprobe.exe', 'ffprobe/')],``` This way you can manage them inside their own directory. Most external utilities work this way. – F T Aug 22 '23 at 10:41
  • @FT I tried but it didn't work, below is the last part of pyinstaller outptut – Abdelrahman Zaki Aug 22 '23 at 20:06
  • 24328 INFO: Looking for eggs 24331 INFO: Using Python library C:\Users\Owner\AppData\Local\Programs\Python\Python310\python310.dll 24331 INFO: Found binding redirects: [] 24343 INFO: Warnings written to D:\PycharmProjects\Downloader app_yt-dlp\build\main\warn-main.txt 24529 INFO: Graph cross-reference written to D:\PycharmProjects\Downloader app_yt-dlp\build\main\xref-main.html – Abdelrahman Zaki Aug 22 '23 at 20:07
  • Try to conditionally set the absolute path of these resources in the two cases. Case 1 while you execute the code and Case 2 while the application runs from .exe, in the first case you just provide the path to these binaries on your computer. In the second case you can refer to [this](https://stackoverflow.com/a/13790741/17161627) discussion. If the relative path to these resources exists that means you are running the application from your code otherwise you are executing exe. – F T Aug 23 '23 at 04:13
  • There is a small issue, I didn't control ffmpeg path in anyway, the tool I use `yt-dlp` does it for me, and it works with two ways, either I putted the ffmpeg.exe in the same folder as my app, or I stored its path in the PATH variable in windows, not anything else – Abdelrahman Zaki Aug 24 '23 at 21:37

1 Answers1

0

found a solution!

using auto-py-to-exe.exe will solve this issue, but when using one file option. how auto-py-to-exe.exe embed ffmpeg and ffprobe in your exe file