pythonffmpegpyinstaller

Pyinstaller Hidden import 'ffmpeg-python' not found


Trying to convert Python scripts to exe with PyInstaller.

In my code, I use ffmpeg-python:

import ffmpeg
....
def ffmpeg_save_clip(self,output_video: str, clip_start: str, clip_end: str): 
  (ffmpeg 
   .input(self.file.get_videopath(), ) 
   .output(output_video, vcodec='copy', ss=clip_start, to=clip_end, acodec='copy') 
   .global_args('-y') 
   .run())

So Ii call PyInstaller from terminal with related flag:

pyinstaller --windowed --hidden-import "ffmpeg-python" --noconsole --icon=app.ico --name "app" main.py 

I checked also:

pip install ffmpeg-python 
Requirement already satisfied: ffmpeg-python in c:\python38\lib\site-packages (0.2.0) 
Requirement already satisfied: future in c:\python38\lib\site-packages (from ffmpeg-python) (0.18.3)

But I get from PyInstaller:

Hidden import 'ffmpeg-python' not found

App works in visual-studio, but when I run pyinstaller exe and try to save clip, it freeze without response.

Note: I also:

  1. try to add ffmpeg.exe into root folder of pyinstaller app.

  2. try to use .spec file with:

    binaries=[('C:\\ffmpeg\\bin\\ffmpeg.exe', 'ffmpeg/),('C:\\ffmpeg\\bin\\ffplay.exe','ffplay/'), ('C:\\ffmpeg\\bin\\ffprobe.exe', 'ffprobe/')],

Nothing changes

UPDATE Tank you @happy_code_egg, you explained me such a things. I tried what you said and I don't have error any more.

But I can't make work ffmpeg anywhere on Pyinstaller exe. I added a try/except block to isolate problem (when I launch app on Visualstudio it works, but not when use exe).

block is (very symilar to past def):

def ffmpeg_save_clip(self,output_video: str, clip_start: str, clip_end: str):
    input = 'C:\Users\x\Desktop\input.mp4'
    output = 'C:\Users\x\Desktop\output.mp4'
    try:
        (ffmpeg
        .input(input)
        .output(output, vcodec='copy', ss=clip_start, to=clip_end, acodec='copy')
        .global_args('-y')
        .run(capture_stdout=True))
    except Exception as e:
        self.logger.error('Video window -> ffmpeg_save_clip -> error ' + str(e))
        self.logger.error('Video window -> ffmpeg_save_clip -> input file: ' + input)
        self.logger.error('Video window -> ffmpeg_save_clip -> output file ' + output)
        raise ValueError(str(e))

Note: (input and output fixed are only as simple path examples)

When I open log I have:

2024-08-09 11:28:50,293 - ERROR - Video window -> ffmpeg_save_clip -> error [WinError 2] File not found error
2024-08-09 11:28:50,293 - ERROR - Video window -> ffmpeg_save_clip -> input file: C:\Users\x\Desktop\input.mp4
2024-08-09 11:28:50,293 - ERROR - Video window -> ffmpeg_save_clip -> output file C:\Users\x\Desktop\ouput.mp4

(I tried with '/' and also '\' to create path) File paths are correct and, on Visualstudio, they can be processed by ffmpeg (no error), but the exe seems to not find (input or output)

I tried solution described here: Python ffmpeg won't accept path (without effects)

I found also these discussions:

github ffmpeg-python issue1

github ffmpeg-python issue2

in both discussions seems to be a problem with ffmpeg + ffmpeg-python libs cohexistence.

I tried (as said) to uninstal both and reinstall ffmpeg-python, but nothing change.

Note: I've also three other warning during Pyinstaller: (I write them only to complete context, but i think they have no repercussions on this problem.)

57283 ERROR: Hidden import 'fiona._shim' not found
57298 WARNING: Hidden import "fiona._shim" not found!
57392 WARNING: Hidden import "importlib_resources.trees" not found!

tried with:

--hidden-import fiona._shim --hidden-import fiona.schema

tried also with:

--add-data="fiona/*;fiona”

but warnings still remains.


Solution

  • For anyone encountered this issue, I finally found a way to make it work. tank you for @happy_code_egg support (and it's explaining capacity)

    To solve ffmpeg-python including to pyinstaller, follow what @happy_code_egg said.

    Anyway (as I wrote in update section of my question), it still remained a problem: using ffmpeg python command in pyinstaller .exe I had:

    error [WinError 2] The system cannot find the file specified
    

    It was not referenced to video file, but to ffmpeg.exe itself. (app was not able to find ffmpeg.exe) As said also by @happy_code_egg in comment.

    to make it works you can use ffmpeg flag to find ffmpeg.exe:

    (ffmpeg ...
    ...
    .run(overwrite_output=True, cmd=r'c:\FFmpeg\bin\ffmpeg.exe')
    

    Adding cmd flag it works!

    To avoid installation of ffmpeg into host computer (every host computer that will use pyinstallar .exe), put ffmpeg.exe into root directory of main python script and set:

    rel_ffmpeg_path = os.path.dirname(__file__) + '\\ffmpeg.exe'
    ... 
    
    (ffmpeg ...
    ...
    .run(overwrite_output=True, cmd=rel_ffmpeg_path)
    

    Hope this will help.