FFmpegWriter: use avcodec_get_supported_config for FFmpeg 7+ (libavcodec 61+) - #1088
Open
Chzrz89 wants to merge 1 commit into
Open
FFmpegWriter: use avcodec_get_supported_config for FFmpeg 7+ (libavcodec 61+)#1088Chzrz89 wants to merge 1 commit into
Chzrz89 wants to merge 1 commit into
Conversation
…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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
FFmpeg 7 removed the codec capability lists (
pix_fmts,supported_samplerates,sample_fmts,ch_layouts, and pre-5.1channel_layouts) from the publicAVCodecstruct, soFFmpegWriter.cppno 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:LIBAVCODEC_VERSION_MAJOR >= 61: backed byavcodec_get_supported_config()(the API introduced alongside the struct-field removal)All call sites in
FFmpegWriter.cppnow go through these helpers.Incidental fix: while porting, a latent bug in the
HAVE_CH_LAYOUTpath became visible - the layout loop testedif (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"totests/BeatSync.cpp, which usesopenshot::InvalidJSONbut previously only got it transitively.Testing
Windows 11 / MSYS2, MinGW-w64 GCC 16.2.0, FFmpeg 9.0.1 (libavcodec 63.1.101):
FFmpegWriter(libx264 + AAC, sample format auto-negotiated to fltp through the new config path) -> output verified with ffprobe - PASS