Fix FFmpeg 6+ compatibility issues #360
Open
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
This PR fixes compilation errors when building decord with FFmpeg 6+. The changes address deprecated API usage and update to the new FFmpeg 6 APIs while maintaining backward compatibility with older FFmpeg versions.
Changes Made
Audio Reader (
src/audio/audio_reader.cc)->channelswith->ch_layout.nb_channels->channel_layoutwith newAVChannelLayoutAPIavcodec_close()calls (onlyavcodec_free_context()is needed)InitSWR()to useav_opt_set_chlayout()instead ofav_opt_set_channel_layout()Video Reader (
src/video/video_reader.cc)AVCodec *toconst AVCodec *forav_find_best_stream()compatibilityav_stream_get_side_data()withav_packet_side_data_get()FFmpeg Common (
src/video/ffmpeg/ffmpeg_common.h)#include <libavutil/channel_layout.h>for new channel layout API supportCompatibility
All changes are wrapped in version checks (
#if LIBAVCODEC_VERSION_MAJOR >= 59) to maintain backward compatibility with FFmpeg 5 and earlier versions.Testing
Successfully builds with FFmpeg 6+ on macOS with Homebrew-installed FFmpeg.
Related Issues
Fixes compilation errors:
no member named 'channels' in 'AVCodecParameters'no member named 'channel_layout' in 'AVCodecContext'use of undeclared identifier 'avcodec_close'no matching function for call to 'av_find_best_stream'use of undeclared identifier 'av_stream_get_side_data'Pull Request opened by Augment Code with guidance from the PR author