-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Check ffmpeg version instead of checking for presence of BTBN_PATH #7023
Check ffmpeg version instead of checking for presence of BTBN_PATH #7023
Conversation
✅ Deploy Preview for frigate-docs canceled.
|
that is not quite correct, frigate uses 5.1.2 |
looks like 59 is the current major version used though, so this should work as expected. |
Would appreciate if this could be a pure python implementation, so the docker environment does not become more bespoke. How about: import subprocess
import re
from functools import cache
from typing import Optional
libavformat_version = rb"^libavformat\s+(?P<version>\d+)"
@cache
def get_libavformat_version() -> Optional[int]:
try:
response = subprocess.check_output([
"ffmpeg", "-version"
])
except FileNotFoundError:
raise RuntimeError("No ffmpeg executable in PATH")
if match := re.search(libavformat_version, response, re.MULTILINE):
return int(match.group('version'))
return -1 |
@mweinelt We are moving towards the opposite, the goal is that at some point parts of the code base won't even be implemented in python to improve performance. subprocess is slow and especially in cases where it needs to be run multiple times is very inefficient. |
The only thing I could offer to counter running it multiple times is cache out of the functools module. It ensures it is really only run once, even if imported multiple times. I've updated the snippet accordingly and tested it like so: for _ in range(10):
from ffmpeg import get_libavformat_version
print(get_libavformat_version())
|
It will be called fewer times with that, but will still be called multiple times in that case for frigate. Functools creates a cache that is used for that process, however Frigate has multiple processes that use this function. In any case, setting an env will also work for other implementations / changes that may come in the future |
@madsciencetist need to fix formatting and the tests |
To @mweinelt 's point though, won't doing it in the s6 service break the dev container workflow? Docs suggest invoking |
yes, but it would just need to be added to https://github.com/blakeblackshear/frigate/blob/dev/docker/fake_frigate_run as well or frigate-prepare could be added and it could be handled there |
@NickM-27 adding |
just need to add |
@NickM-27 Adding Solution: I added the env export to the devcontainer's .bashrc. In the devcontainer, it will be evaluated once per login shell via .bashrc, while in deployment, it will only be evaluated once ever, via the s6 service. |
Ugh, still doesn't work with unittests, because those are launched without going through s6 or a login shell. Best idea I have for unittests is to set the ENV in the Dockerfile, based on the ffmpeg in the image, and assume that no one wants to run unittests with a custom-mounted ffmpeg. I just don't love having three separate mechanisms for defining an env. If we're willing to drop support for runtime-mounted ffmpeg altogether, just the Dockerfile ENV would be sufficient. Or we say it doesn't matter for unit tests and just add |
I'd say just set the environment variable in the python test setUp method. The tests aren't there to test the ffmpeg version check itself. |
Should I just replace |
Yeah that is probably fine, I mean that is essentially what was done previously where we assumed if ffmpeg was installed it was version 5.0 or greater. In this case runtime checks, but if it can't get the version for whatever reason it would make sense to still default to 5.0+ behavior |
Frigate (the actual python app) assumes that if
/usr/lib/btbn-ffmpeg
exists, ffmpeg is version 5, and if not, ffmpeg is version 4. This assumption matches the provided Docker builds, but is a brittle coupling between Dockerfile and app - for example, it can break if the user follows the docs that suggest a custom ffmpeg (of unspecified version) can be mounted to/usr/lib/btbn-ffmpeg
.Now the ffmpeg version is directly queried from the ffmpeg binary on the path.