Page MenuHome

FFmpeg: Initialize encoders with default values
AbandonedPublic

Authored by Richard Antalik (ISS) on Apr 16 2021, 6:39 AM.

Details

Summary

Aim of this patch is to mirror behavior of ffmpeg tool when encoding.
So far I was focused on H264 codec, because it didn't work as expected.
H264 codec is also only one I have tested so far.

Use avcodec_get_context_defaults3() to initialize encoder codec
context. In case of H264, when not using default values, presets are
working incorrectly. In case of ultrafast preset, this caused crash.
On crash, error was reported: "broken ffmpeg default settings detected"
See libx264 source x264/encoder/encoder.c for more details.

Removed H264 settings are from 12 years ago, and I am not familiar with
how libx264 worked back then, nor whether this was correct approach.

With this patch all settings except user controllable ones
(quality, gop size, ...) match ffmpeg tool.

Diff Detail

Repository
rB Blender
Branch
arcpatch-D10988 (branched from master)
Build Status
Buildable 14115
Build 14115: arc lint + arc unit

Event Timeline

Richard Antalik (ISS) requested review of this revision.Apr 16 2021, 6:39 AM
Richard Antalik (ISS) created this revision.
Richard Antalik (ISS) planned changes to this revision.Apr 16 2021, 7:24 AM

Marking as WIP since I need to do more testing. Feel free to provide feedback on code though.

source/blender/imbuf/intern/indexer.c
519

Is this still the case now that the source of these defaults have changed? I can't really imagine FFmpeg shipping with such default settings for the most-used codec that it crashes itself.

Richard Antalik (ISS) marked an inline comment as done.
  • Remove unnecessary quality field initialization for H264

I have tested these changes, and all codecs seem to work as before, so I consider this patch good for review.

source/blender/imbuf/intern/indexer.c
519

Correct, these are no longer needed. Removed them also from writeffmpeg.c

Not really my area of expertise (I'm not the preset aficionado), but it does sound very nice to remove own hardcoded settings and use avcodec_get_context_defaults3().

Can't spot anything unwanted in the code. But wouldn't mind a second look from Sybren!

Sybren A. Stüvel (sybren) requested changes to this revision.May 3 2021, 2:37 PM

Parameters aren't passed properly any more. Check the difference in image quality:

Master produces a 95KB file:

Patched produces a 41K file:

This revision now requires changes to proceed.May 3 2021, 2:37 PM

Fix CRF mode not working for VP9 codec

Parameters aren't passed properly any more.

There are 2 issues:

So this patch seem to only change bitrate from uninitialized to codec default value.

Closing as this was implemented in rBce649c73446e