Skip to content

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

Merged
jonoomph merged 1 commit into
OpenShot:arm64-supportfrom
Chzrz89:fix/ffmpeg7-codec-capabilities
Oct 17, 2026
Merged

jonoomph merged 1 commit into
OpenShot:arm64-supportfrom
Chzrz89:fix/ffmpeg7-codec-capabilities

Conversation

@Chzrz89

@Chzrz89 Chzrz89 commented Aug 26, 2026

Copy link
Copy Markdown
Contributor

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.

jonoomph commented Oct 3, 2026

Copy link
Copy Markdown
Member

Thanks for the focused helpers and channel-layout comparison fix! Could you guard the entire AVChannelLayout helper for older FFmpeg versions and use the full libavcodec 61.13.100 boundary for avcodec_get_supported_config? The current declaration fails on FFmpeg 4.4, and the major-version check selects an unavailable API on FFmpeg 7.0. Please also preserve the legacy channel-layout validation and include older-version build checks alongside the modern build.

Copy link
Copy Markdown
Member

Thanks for the focused compatibility helpers and channel-layout fix! We’ve integrated this into arm64-support, where we’ll validate it with the other ARM groundwork before merging anything into develop.

  • Corrected the API boundary to libavcodec 61.13.100, guarded the entire newer channel-layout declaration, and restored legacy layout validation.
  • Added context-aware queries (also explored in Split newer-toolchain compatibility fixes from Arm64 readiness #1096), explicit query-error handling, and regression tests.
  • The older full suite and focused FFmpeg 7.0/8.0 export tests pass locally; a new GitHub matrix also checks 7.0, 7.1, and 8.0.

Integration PR: #1117. The broader changes in #1096 remain separate.

jonoomph added a commit that referenced this pull request Oct 17, 2026
Fix PR #1088 version and channel-layout guards, preserve legacy validation, and reject failed capability queries. Use encoder-context queries as suggested by #1096 without importing its broader changes. Add codec regression tests and FFmpeg 7.0, 7.1, and 8.0 CI coverage.
@jonoomph
jonoomph merged commit 6b43fe0 into OpenShot:arm64-support Oct 17, 2026
1 check passed
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.

2 participants