r/ffmpeg • u/robinechuca • Nov 02 '26
Predicting the best FFmpeg configuration setting
By best, I mean: for all the possible configurations, the one that best fit an arbitrary criterion.
The idea is to use a predictive model trained on more than 17,000 encoding scenarios.
This model allow to simulate several thousands configurations in a few seconds.
I have written a Python module that brings all this together. Here a very simplified example of how to optimise the bitrate of a video with a VMAF of 90:
from mendevi.models import Solver
from mendevi.models.nn import QualityNN
model = QualityNN(output_labels=["log_rate", "vmaf"])
model.fit("scatter.db")
solver = Solver(model, lambda **kwd: kwd["log_rate"] + abs(kwd["vmaf"]-90))
_, _, cmd = solver.solve("src_video.mp4", return_cmd=True)
print(cmd)
There is a complete Jupyter Notebook example here: https://mendevi.readthedocs.io/latest/build/examples/optimizer.html
Right now, when I'm writing this post, the model doesn't predict very accurately (1.5% on psnr and 16% on the bitrate). Also, the API is still in its early stages.
If you have any suggestions on how to make it more accessible and transparent, I’d love to hear them!
4
u/raddostudio Nov 02 '26
Interesting approach. Some things that would make me trust the output as a user:
1
u/Filarius Nov 02 '26
TLDR - NN do no simulation, NN is only interpolate result from your input params based on knowladge it get after training.
In the link to docs i barely can read console output in "night mode" (tested on two browsers, main one has "night mode" by default on that page)
For end user and no NN-guys i'd like this also has a wrapper to make it rock-easy: this is my video, i want this encoders and this VMAF (or what of inputs and options are allowed).
1
u/zamroni777 Nov 02 '26
what's your hw btw?
how is the result compared to ffmpeg sr_amf or other ffmpeg ai filter?
1
u/vegansgetsick Nov 03 '26
The best is -CRF 0
0
u/Ill-Information-2086 Nov 02 '26
Beautiful, I will try this in a few days, you are the man!!!