Skip to content

FFmpegWriter: use avcodec_get_supported_config for FFmpeg 7+ (libavcodec 61+) - #1088

Open
Chzrz89 wants to merge 1 commit into
OpenShot:developfrom
Chzrz89:fix/ffmpeg7-codec-capabilities
Open

FFmpegWriter: use avcodec_get_supported_config for FFmpeg 7+ (libavcodec 61+)#1088
Chzrz89 wants to merge 1 commit into
OpenShot:developfrom
Chzrz89:fix/ffmpeg7-codec-capabilities

Conversation

@Chzrz89

@Chzrz89 Chzrz89 commented Aug 26, 2026

Copy link
Copy Markdown

Summary

FFmpeg 7 removed the codec capability lists (pix_fmts, supported_samplerates, sample_fmts, ch_layouts, and pre-5.1 channel_layouts) from the public AVCodec struct, so FFmpegWriter.cpp no longer compiles against current FFmpeg releases (8.x/9.x as shipped by MSYS2, Fedora 41+, Arch, etc.).

This adds four small inline helpers to FFmpegUtilities.h:

ffmpeg_codec_pix_fmts(codec)      // AV_CODEC_CONFIG_PIX_FORMAT
ffmpeg_codec_sample_rates(codec)  // AV_CODEC_CONFIG_SAMPLE_RATE
ffmpeg_codec_sample_fmts(codec)   // AV_CODEC_CONFIG_SAMPLE_FORMAT
ffmpeg_codec_ch_layouts(codec)    // AV_CODEC_CONFIG_CHANNEL_LAYOUT
  • For LIBAVCODEC_VERSION_MAJOR >= 61: backed by avcodec_get_supported_config() (the API introduced alongside the struct-field removal)
  • For older FFmpeg: return the existing struct fields directly, so behavior is byte-for-byte identical on FFmpeg <= 6 (including current CI on Ubuntu 22.04/24.04)

All call sites in FFmpegWriter.cpp now go through these helpers.

Incidental fix: while porting, a latent bug in the HAVE_CH_LAYOUT path became visible - the layout loop tested if (av_channel_layout_compare(&ch_layout, &codec_layouts[i])), treating non-matching layouts as valid instead of matching ones. Corrected to compare == 0. On old FFmpeg this bug was masked because both branches copied the same requested layout; on FFmpeg 7 it would have accepted the first non-matching entry.

Also: add missing #include "Exceptions.h" to tests/BeatSync.cpp, which uses openshot::InvalidJSON but previously only got it transitively.

Testing

Windows 11 / MSYS2, MinGW-w64 GCC 16.2.0, FFmpeg 9.0.1 (libavcodec 63.1.101):

  • Full build: library, all unit tests, SWIG Python bindings, openshot-player example - PASS
  • Functional round-trip via the Python bindings: read H.264/AAC MP4 -> Timeline with Blur effect -> export via FFmpegWriter (libx264 + AAC, sample format auto-negotiated to fltp through the new config path) -> output verified with ffprobe - PASS
  • The legacy path is untouched for LIBAVCODEC < 61, so existing CI (FFmpeg 4.x/6.x) is unaffected

…dec 61+)

FFmpeg 7 removed the codec capability lists (pix_fmts,
supported_samplerates, sample_fmts, ch_layouts, channel_layouts) from
the public AVCodec struct. Accessing them no longer compiles against
current FFmpeg releases (e.g. 8.x/9.x as shipped by MSYS2 and newer
distros), breaking the build entirely.

Add wrapper helpers in FFmpegUtilities.h:

  ffmpeg_codec_pix_fmts()      -> AV_CODEC_CONFIG_PIX_FORMAT
  ffmpeg_codec_sample_rates()  -> AV_CODEC_CONFIG_SAMPLE_RATE
  ffmpeg_codec_sample_fmts()   -> AV_CODEC_CONFIG_SAMPLE_FORMAT
  ffmpeg_codec_ch_layouts()    -> AV_CODEC_CONFIG_CHANNEL_LAYOUT

For LIBAVCODEC_VERSION_MAJOR >= 61 they call
avcodec_get_supported_config(); for older FFmpeg they return the
existing struct fields directly. All call sites in FFmpegWriter.cpp
now go through these helpers, so behavior is identical on FFmpeg <= 6.

Also fix a pre-existing bug visible on the new path: the channel-layout
loop used 'if (av_channel_layout_compare(...))' — treating NON-matching
layouts as valid — instead of comparing == 0. On FFmpeg 7 this would
have accepted the first non-matching layout; now it matches upstream
intent (accept only an equal layout).

And add the missing #include "Exceptions.h" to tests/BeatSync.cpp,
which uses openshot::InvalidJSON but previously got it transitively.

Verified on Windows/MSYS2 with FFmpeg 9.0.1 (libavcodec 63) + GCC 16:
full build passes and a Timeline render + libx264/AAC export via
FFmpegWriter produces a valid MP4.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant