r/ffmpeg • • Nov 02 '26

Predicting the best FFmpeg configuration setting

Post image

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!

24 Upvotes

13 comments sorted by

4

u/raddostudio Nov 02 '26

Interesting approach. Some things that would make me trust the output as a user:

  1. Show the error per content type (animation, grainy film, screen recordings) and in VMAF points, not one overall percentage. A single number hides where the model breaks.
  2. Add an optional check step: encode a few short samples with the predicted settings and measure the real VMAF, like ab-av1's crf-search does. Then the model only has to get you close and the samples confirm it.
  3. Print which encoder versions it was trained on. SVT-AV1 presets have been retuned between releases, so the same settings can behave differently.
  4. A small CLI that just prints the ffmpeg command would reach people who don't use Python.

1

u/robinechuca Nov 02 '26

The points 2 and 3 are already done. All the contexte is store (more than the av1 version) and vmaf is present. Ia have changed ssim and psnr for vmaf in the otebook example.

Point 1: It has only been train on 30 JVET-CTC videos, not enought to split in sublasses. I'm currently benchmarking on 1000 videos inter4k. But the benchmark will end in 6 mounths...

Point 4: Excelent idear, I will implement that as soon as possible!

1

u/raddostudio Nov 03 '26

Thanks, good to hear the context and VMAF are already in. 30 CTC sequences is a fair start. Even a partial Inter4K run might show whether animation and screen recordings need their own group, since they tend to land far from camera footage at the same CRF. Looking forward to the CLI.

1

u/robinechuca Nov 03 '26

There is screen record video game (not realy animation) in the jvet CTC:

{
    "aov": "Gaming",
    "baolei_balloon": "Gaming",
    "baolei_man": "Gaming",
    "baolei_woman": "Gaming",
    "baolei_yard": "Gaming",
    "boat": "4K-TV",
    "bode_museum": "8K-TV",
    "brest_sedof": "4K-TV",
    "cosmos": "4K-TV",
    "cs_go": "Gaming",
    "elevator": "4K-TV",
    "fountain": "4K-TV",
    "graphics_mix_simple": "ScreenContent",
    "graphics_mix_transitions": "ScreenContent",
    "heroes_of_the_storm": "Gaming",
    "jianling_beach": "Gaming",
    "jianling_temple": "Gaming",
    "life_untouched": "4K-TV",
    "meridian": "4K-TV",
    "mine_craft": "Gaming",
    "mission_control": "ScreenContent",
    "mooving_text": "ScreenContent",
    "neon": "Messaging",
    "neptune_fountain_2": "8K-TV",
    "neptune_fountain_3": "8K-TV",
    "nocturne": "4K-TV",
    "oberbaum_spree": "8K-TV",
    "park_joy": "4K-TV",
    "project_cars": "Gaming",
    "quadriga_tree": "8K-TV",
    "rain_fruits": "4K-TV",
    "riverbank": "4K-TV",
    "skater": "Messaging",
    "soccer": "4K-TV",
    "sol_levante": "4K-TV",
    "sparks": "4K-TV",
    "star_craft": "Gaming",
    "subway_tree": "8K-TV",
    "text_mix_transition": "ScreenContent",
    "tiergarten_parkway": "8K-TV",
    "tunnel_flag": "4K-TV",
    "world_of_warcraft": "Gaming",
}

Inter4k offers more variety than CTC, but it’s not ideal because all the videos are pre-compressed in exactly the same way using H.264. I’m going to look into using the CLI to develop a system that performs validation and helps to feed a collective database. But that will take a bit of time, because it will probably require approval from the ethics committee.

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/robinechuca Nov 02 '26

Year! The night mode is horrible I didn't notice.

I agree with you, the model is not "simulation" but interpolation. The API works with any type of model, tested with linear regression and gaussian regression. NN is the best.

You are the second to ask for a CLI wrapper. I will think about the option then add it in the next release.

Thank you!

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!!!

1

u/robinechuca Nov 02 '26 edited Nov 02 '26

Merci ! Toute l'équipe travaille sur linux, si c'est aussi ton cas, tu peux juste créer ton venv python puis taper :

git clone https://gitlab.inria.fr/rrichard/mendevi.git ~/mendevi_git
cd ~/mendevi_git
uv pip install -e .[all]

Recharge le terminal puis :

mendevi jupyter

Si tu n'es pas sur linux, je peux t'envoyer les poids du modèle pré-entraîné.

2

u/Ill-Information-2086 Nov 02 '26

Thanks, but I am on Linux so it's all good 😁

1

u/robinechuca Nov 02 '26

Excellent choice!

Oups, mistake of packaging, the jupyter-notebook example folder is not in pypi, you have to clone the git repo: https://mendevi.readthedocs.io/latest/developer_guide/installation.html#building-from-source-for-developers

Sorry, I will solve that inconvenient in the next pypi release!

1

u/Ill-Information-2086 Nov 02 '26

Haha to be honest linux is the only choice for work windows be too damn bloated 🫪

No worries cloning the repo works too