The system cannot find the file specified with ffmpeg
Asked Answered
J

6

18

In the process of using the ffmpeg module to edit video files i used the subprocess module

The code is as follows:

#trim bit

import subprocess
import os
seconds = "4"
mypath=os.path.abspath('trial.mp4')
subprocess.call(['ffmpeg', '-i',mypath, '-ss', seconds, 'trimmed.mp4'])

Error message:

Traceback (most recent call last):
  File "C:\moviepy-master\resizer.py", line 29, in <module>
    subprocess.call(['ffmpeg', '-i',mypath, '-ss', seconds, 'trimmed.mp4'])
  File "C:\Python27\lib\subprocess.py", line 168, in call
    return Popen(*popenargs, **kwargs).wait()
  File "C:\Python27\lib\subprocess.py", line 390, in __init__
    errread, errwrite)
  File "C:\Python27\lib\subprocess.py", line 640, in _execute_child
    startupinfo)
WindowsError: [Error 2] The system cannot find the file specified

After looking up similar problems i understood that the module is unable to pick the video file because it needs its path, so i took the absolute path. But in spite of that the error still shows up. The module where this code was saved and the video file trial.mp4 are in the same folder.

Jd answered 16/7, 2017 at 17:29 Comment(3)
And from which path did you call your script? This should matter. Manually check mypath! (and maybe use os.path.exists() for more checking). Edit: error is ambiguous and i'm not even sure if the problem is within ffmpeg. Is ffmpeg in your system-path? Can it be called from console (like you do here, no absolute path!)?Detention
I'm quite sure that the problem is that it's not finding ffmpeg - if the error was that it couldn't find the input file, it would not come in a neat Python exception, but as an error message on standard error from ffmpeg.Unnecessary
try installing ffmpeg with chocolatey: choco install ffmpegWeevil
S
12

The WindowsError you see does not refer to the video file but to the ffmpeg executable itself. The call to subprocess.call has no idea that trimmed.mp4 is a filename you are passing. Windows knows that the first parameter ought to be an executable file and reports back to the interpreter that it can't find it.

Double-check that ffmpeg can be executed in the environment your interpreter is running in. You may either add it to your PATH or specify the full path to ffmpeg.exe.

Shag answered 16/7, 2017 at 17:40 Comment(3)
If you talking about setting the environment variable to ffmpeg.exe , then it was already set before i ran this code .Jd
Is it actually correct and picked up by the interpreter? Opening a shell and typing ffmpeg should work then. In any case, the error says it's not there.Shag
Thanks, for me, despite being in my environment variables, i had to add the full path to ffmpeg.exe! The ffmpeg command was callable from cmd without issue but not via the python subprocess or os.systemDeconsecrate
C
15

None of the above answers worked for me.

I got it working, by opening Anaconda Navigator > CMD prompt.

conda install ffmpeg
Condensate answered 21/10, 2020 at 7:32 Comment(0)
S
12

The WindowsError you see does not refer to the video file but to the ffmpeg executable itself. The call to subprocess.call has no idea that trimmed.mp4 is a filename you are passing. Windows knows that the first parameter ought to be an executable file and reports back to the interpreter that it can't find it.

Double-check that ffmpeg can be executed in the environment your interpreter is running in. You may either add it to your PATH or specify the full path to ffmpeg.exe.

Shag answered 16/7, 2017 at 17:40 Comment(3)
If you talking about setting the environment variable to ffmpeg.exe , then it was already set before i ran this code .Jd
Is it actually correct and picked up by the interpreter? Opening a shell and typing ffmpeg should work then. In any case, the error says it's not there.Shag
Thanks, for me, despite being in my environment variables, i had to add the full path to ffmpeg.exe! The ffmpeg command was callable from cmd without issue but not via the python subprocess or os.systemDeconsecrate
A
10

This answer is directed at Windows users of the ffmpeg-python library since this question is the first search result for a stricter instance of the same issue.

Adding on to user2722968's answer because neither of the existing answers solved the problem for me.

As of this post, ffmpeg-python uses subprocess.Popen to run ffmpeg. Per this issue, subprocess does not look in Path when resolving names, so even if FFmpeg is installed and in your Path and you can run it from CMD/PowerShell, ffmpeg-python may not be able to use it.

My solution was to copy ffmpeg.exe into the Python environment where python.exe is. This workaround seems far from ideal but it seems to have solved the problem for me.

Ankeny answered 14/3, 2021 at 11:50 Comment(1)
I recently found that when my PyQt5 app converted to an exe, it still needs ffmpeg.exe in the same folder my app.exe is located.Sikko
T
9

Most of the answers didn't work. Here is what worked for me using conda env:

pip uninstall ffmpeg-python
conda install ffmpeg
pip install ffmpeg-python

Just the conda installation gives library not found error. Didn't try uninstalling conda library either but this works.

Torrlow answered 17/7, 2021 at 20:0 Comment(0)
I
0

First Uninstall all pip libraries

pip uninstall ffmpeg
pip uninstall ffmpeg-python

Then install using conda

conda install ffmpeg
Icebox answered 24/10, 2021 at 8:36 Comment(0)
S
0

If you are going to use 'ffmpeg.exe' or its linux binary, you need this

conda install ffmpeg

Then you will call it via subprocess or os.system() in your code. And make sure you will run a different thread to run ffmpeg code otherwise there will be a huge bottleneck in your main thread.

class SaveAll():
    def init(self):
        super(SaveAll, self).__init__()

    def save(self):
        try:
            command = "ffmpeg -i {} -c copy -preset ultrafast {}"format(...)
            os.system(command)
        except ffmpeg.Error as e:
            print (e.stout, file=sys.stderr)
            print (e.stderr, file=sys.stderr)

    def run(self):
        self.thread= threading.Thread(target=self.save)
        self.thread.start()
        self.thread.join(1)

...

saver = SaveAll()
saver.start()
Sikko answered 30/1, 2023 at 0:39 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.