Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

ffpb = WinError 2 #30

Open
kubinka0505 opened this issue May 4, 2022 · 5 comments
Open

ffpb = WinError 2 #30

kubinka0505 opened this issue May 4, 2022 · 5 comments
Labels

Comments

@kubinka0505
Copy link

C:\Users\kubinka0505>ffpb
'ffpb' is not recognized as an internal or external command,
operable program or batch file.

C:\Users\kubinka0505>pip install ffpb
Collecting ffpb
  Using cached ffpb-0.4.1-py2.py3-none-any.whl (6.2 kB)
Collecting tqdm~=4.25
  Downloading tqdm-4.64.0-py2.py3-none-any.whl (78 kB)
     ---------------------------------------- 78.4/78.4 KB 874.5 kB/s eta 0:00:00
Collecting colorama
  Using cached colorama-0.4.4-py2.py3-none-any.whl (16 kB)
Installing collected packages: colorama, tqdm, ffpb
Successfully installed colorama-0.4.4 ffpb-0.4.1 tqdm-4.64.0

C:\Users\kubinka0505>ffpb
Unexpected exception: [WinError 2] Nie można odnaleźć określonego pliku

C:\Users\kubinka0505>py -V
Python 3.7.6

I've just installed ffpb and this dropped. Any solutions?

@althonos
Copy link
Owner

althonos commented May 4, 2022

Do you have ffmpeg installed and available in your PATH?

@kubinka0505
Copy link
Author

kubinka0505 commented May 4, 2022

Do you have ffmpeg installed and available in your PATH?

>>> from os import *
>>>
>>> # for variable in PATH
>>> #    if lowercase variable ends with ffmpeg.exe
>>> #        print(variable)
>>>
>>> for Variable in environ["PATH"].split(pathsep):
...     if Variable.lower().endswith("ffmpeg.exe"):
...         print(Variable)
...
C:\Users\kubinka0505\Programs\ffmpeg.exe

TLDR: Yes

@kubinka0505
Copy link
Author

If that's important I use:

ffmpeg version 4.2.2 Copyright (c) 2000-2019 the FFmpeg developers
built with gcc 9.2.1 (GCC) 20200122
...

@althonos althonos added the bug label May 4, 2022
@kubinka0505
Copy link
Author

I did some tweaking, and I've figured out that ffpb works only if FFmpeg is in the user's home directory.

C:\Users\kubinka0505>: Not installed
C:\Users\kubinka0505>ffpb
'ffpb' is not recognized as an internal or external command,
operable program or batch file.

C:\Users\kubinka0505>: Install
C:\Users\kubinka0505>pip install ffpb -q

C:\Users\kubinka0505>: Use
C:\Users\kubinka0505>ffpb


C:\Users\kubinka0505>: Check FFmpeg in %UserProfile%
C:\Users\kubinka0505>ffmpeg.exe -loglevel 0

C:\Users\kubinka0505>: Move FFmpeg
C:\Users\kubinka0505>move ffmpeg.exe Programs
        1 file(s) moved.

C:\Users\kubinka0505>: Try to use ffpb
C:\Users\kubinka0505>ffpb
Unexpected exception: [WinError 2] Nie można odnaleźć określonego pliku

C:\Users\kubinka0505>cd Programs

C:\Users\kubinka0505\Programs>: Use ffpb in the directory where FFmpeg is
C:\Users\kubinka0505\Programs>ffpb


C:\Users\kubinka0505\Programs>: Move FFmpeg to home directory
C:\Users\kubinka0505\Programs>move ffmpeg.exe ..
        1 file(s) moved.

C:\Users\kubinka0505\Programs>: Use ffpb
C:\Users\kubinka0505\Programs>ffpb


C:\Users\kubinka0505\Programs>

It's likely that the error is caused by inaccurate path detection of the static FFmpeg executable binary, which is probably performed on this line:

ffpb/ffpb.py

Line 155 in da41f96

cmd = ["ffmpeg"] + argv

I recommend applying some kind of universal detection function like this:

from pathlib import Path

def Detect_Binary(Name: str.lower, Variable_Name: str = "PATH", Format: str = "EXE") -> str:
	"""Looks for binary of `Name` in the `Variable` environment variable."""
	Name_Original = Name
	Name = Name.lower()
	Format = Format.lower()
	#-=-=-=-#
	if os.sys.platform.lower().startswith("win"):
		for Variable in os.environ[Variable_Name].split(os.pathsep):
			if Name + "." + Format in Variable:
				# Fix the final path
				Name = str(Path(Variable).resolve())
				if not os.path.exists(Name):
					raise AttributeError(Name_Original + " not found!")
	#-=-=-=-#
	return Name

...and then

...
cmd = [Detect_Binary("FFmpeg")] + argv
...

@althonos
Copy link
Owner

althonos commented May 5, 2022

That's weird, on my Windows machine ffpb works even with ffmpeg installed somewhere in C:\\...

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants