-
Notifications
You must be signed in to change notification settings - Fork 75
Add support for Tensorflow dnn_backends in dnn_processing, sr & derain filters #172
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
Add support for Tensorflow dnn_backends in dnn_processing, sr & derain filters #172
Conversation
…ilters Install: ``` $ brew install homebrew-ffmpeg/ffmpeg/ffmpeg --with-libtensorflow ``` Test case / validation that it compiles: ``` $ ffmpeg -h filter=sr sr AVOptions: dnn_backend <int> ..FV....... DNN backend used for model execution (from 0 to 1) (default tensorflow) tensorflow 1 ..FV....... tensorflow backend flag ``` ``` $ ffmpeg -h filter=dnn_processing dnn_processing AVOptions: dnn_backend <int> ..FV....... DNN backend (from INT_MIN to INT_MAX) (default tensorflow) tensorflow 1 ..FV....... tensorflow backend flag ``` Tensorflow is Apache License 2.0 https://github.com/tensorflow/tensorflow/blob/master/LICENSE
`--with-tensorflow` is the proposed option name in the formula `--enable-libtensorflow` is the FFmpeg compile-time flag [If there is a preferred formula convention that contradicts this proposal, then easy to change.]
After submitting PR, Github CI claimed: > "FormulaAudit/DependencyOrder: dependency "libtensorflow" (line 105) should be put before dependency "svt-av1" (line 111)" This commit reorders the dependencies.
After submitting PR, Github CI claimed: > FormulaAudit/DependencyOrder: dependency "libtensorflow" (line 104) should be put before dependency "srt" (line 111) This commit reorders the dependencies. I hope that this is is the last error. I doubt that neither svt-av1 nor srt is actually a dependency of libtensorflow, but I commit this change to try to appease the CI deity.
Github CI reports... >FormulaAudit/DependencyOrder: dependency "libtensorflow" (line 104) should be put before dependency "speex" (line 111) Moving libtensorflow into absolute alphabetical order, rather than in option-name order. Apologies to any watchers for the level of noise.
The DependencyOrder error generated by Github CI was resolved by ensuring "depends_on" was in strict alphabetical order. Apologies to any watchers for the additional noise in this PR - I was unaware of this requirement prior to PR submission. I believe other that the other CI errors are expected. |
😂 I would prefer CI to work better, but I really don’t have time to look into this … |
I don't know any alternative other than removing the chromaprint dependency altogether... |
Me neither, but I would not remove chromaprint. Maybe there is a possibility to ignore it for testing. |
@slhck Works fine on my end with M3 on macOS 15.0.1. on one of our old test datasets. I can test only next week on Linux. |
Thank you again, @bbgdzxng1 ! |
This branch/patch adds TensorFlow support for general
dnn_processing
and application-specificsr
andderain
filters, using brew's standard libtensorflow formula.These filters can be used with conventional neural network (CNN) and deep neural network (DNN) techniques and can be used with independent models for model-based frame processing. A common application for dnn processing is Super Resolution using a trained model.
Background
There are very few public builds (static or docker) that currently support these filters with TensorFlow. One docker build https://github.com/MIR-MU/ffmpeg-tensorflow does support TensorFlow, with the following observations:
dnn_processing
backends such as OpenVINO and PyTorch.This homebrew-ffmpeg branch does not include or plan to include any pre-trained models. A user is expected to train their own model or source pre-trained models from elsewhere (modelzoo, openmodeldb or similar). A user is expected to place their model in a easily accessible folder and reference it when invoking the FFmpeg filter, eg $HOME/tensorflow-models. This branch does not offer any opinion on the quality or suitability of models.
The awesome homebrew-ffmpeg already includes optional support for OpenVINO backend for the
dnn_processing
filter. This patch adds support for TensorFlow as an alternative backend fordnn_processing
, and with the addition of TensorFlow, supports the application-specificsr
andderain
filters.Assuming that this patch is accepted, homebrew-ffmpeg would support two out of the three active backends. The FFmpeg 'Native' backend was deprecated & removed in April 2023
Installation using the homebrew-ffmpeg option
Validation
After compilation & installation, FFmpeg command-line help lists TensorFlow as an available dnn_backend for each of the following filters.
It is not expected that TensorFlow would be available in the dnn_clasify filter. [https://ffmpeg.org/ffmpeg-all.html#dnn_005fclassify](Formal FFmpeg documentation) for
dnn_classify
states that "This option accepts only openvino now, tensorflow backends will be added.".✅ Compilation and installation was successful using this branch on macOS (13.7 Apple Silicon). Not tested on homebrew linux.
Tests
Wow! it actually JustWorked(TM) using brew's "standard" libtensorflow and borrowing some models for testing.
sr filter with Super Resolution Conventional Neural Network (srcnn) model
A pre-trained srcnn.pb model can be extracted from https://github.com/MIR-MU/ffmpeg-tensorflow Docker container
✅ The above FFmpeg command was successful on macOS (13.7 Apple Silicon) 2024-10-23. Not tested on homebrew linux.
At the time of writing, the HTML docs for the sr filter are outdated (and do not reference mandatory options such as
input='x':output='y'
). Users are advised to use command-line help$ ffmpeg -h filter=sr
for up to date command-line options.Derain filter with derain & dehaze models
✅ The above FFmpeg command was successful on macOS (13.7 Apple Silicon) 2024-10-23. Not tested on homebrew linux.
At the time of writing, the HTML docs for the derain filter are outdated and do not reference mandatory options such as
input='x':output='y'
. Users are advised to use command-line help$ ffmpeg -h filter=derain
for up to date command-line options.General dnn_processing filter
A pre-trained espcn.pb model can be extracted from https://github.com/MIR-MU/ffmpeg-tensorflow Docker container
✅ The above FFmpeg command was successful on macOS (13.7 Apple Silicon) 2024-10-23. Not tested on homebrew linux.
Caveat Emptor
I'm not a developer; I'm not very good with git branches or commits; I can barely write a homebrew formula. If I have broken any git or contribution conventions, please forgive me. I shall aim to learn and improve.