-
Notifications
You must be signed in to change notification settings - Fork 598
Fix FFmpeg 7.x compatibility issues #1494
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
xaviliz
wants to merge
16
commits into
MTG:master
Choose a base branch
from
xaviliz:fix/FFmpeg-7x-compatibility
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Conversation
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
- Remove deprecated av_register_all() calls - Update AudioContext to use modern FFmpeg APIs: - Replace AVStream->codec with AVStream->codecpar - Use AVCodecContext->ch_layout instead of channels - Update encoding API to avcodec_send_frame() + avcodec_receive_packet() - Fix packet handling with av_packet_unref() - Update AudioLoader to use modern decoding API: - Replace avcodec_decode_audio4() with avcodec_send_packet() + avcodec_receive_frame() - Fix codec context creation and management - Update channel layout API usage - Fix type declarations for const pointers - Successfully builds and imports with FFmpeg 7.1.1 Resolves GitHub issue MTG#1248: Support ffmpeg version 5
- Fix decode_audio_frame() to properly handle flush packets (empty packets) - Handle AVERROR_EOF as expected response when flushing, not as error - Return correct values for modern send_packet/receive_frame API - Successfully tested with WAV, MP3, and FLAC formats - No more decoding warnings or runtime errors The AudioLoader now works perfectly with FFmpeg 7.1.1
- Document complete resolution of FFmpeg 5.x compatibility issues - Add testing results for WAV, MP3, and FLAC formats - Confirm no more warnings or runtime errors - Mark all phases as completed successfully
- Migrate from avresample to swresample flags - Update sdl to sld2 flags - Small clean
- Small clean - Apply 2-white space tab indentation
- Small clean. - In process() - Set _dataSize to number of bytes written without mutating _packet.data and _packet.size - Assess the buffer has been written before to copy FFmpeg output. - In flushPacket() - Support for Receive_result errors (AVERROR(EAGAIN) and AVERROR_EOF) - Fix how to get frames and update _dataSize - In decodePacket() - Redefined with modern safe API - Avoid mutating _packet_data /_packet.size to decode one frame - In copyFFmpegOutput() - Use of _buffer as float pointer with an explicit cast. - In process() - Ensures that it reads a single packet and outputs at most one output fragment per call. - In flushPacket() guarantees it only flush once-per-frame.
… between byte counts and sample counts and prevent accidental overruns. - Fix buffer initialization.
- In configure() - Set AV log level to AV_LOG_QUIET - In AudioContext() - Initialize _pts to 0 by default. - In create() - Find encoder before to create audio stream - Create audio stream and pass the codec to help FFmpeg initialize defaults - Create codec context - Define channel layout - Open codec - Ensure stream is marked as audio and set a sensible time_base for muxer - Determine frame_size fallback for PCM codecs (some PCM codecs do not set frame_size) - Allocate input audio FLT buffer sized for codecCtx->frame_size samples - Guarantees configure sample format conversion - In open() - Open the output IO and check errors - Write header in a safe way. - In close() - Close output IO with the modern safe API - Use modern API for codec context cleanup - Free input buffer, swresample context and context. - In encodePacket() - Prepare conversion buffers (bufferFmt[ch]) and linesize[ch] - Perform sample format conversion - Allocate frame - Copy converted audio into AVFrame - Send frame to encoder - Receive packets and write them (may be 0..N packets) - Update cleanup
- Initialize _pts to 0 by default
- Remove semicolons - Fix numpy compatibility by replacing assertEquals with assertEqual
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.
Fix FFmpeg compatibility issues
Problem
Essentia fails to build/import on systems with FFmpeg 5.x+ due to deprecated and removed APIs, causing undefined symbol: avcodec_decode_audio4 errors.
Loading and writing algorithms like AudioLoader, Monoloader, EqloudLoader, EasyLoader, MonoWriter and AudioWriter, and any example or extractor that reuse those algorithms are affected by this failure.
Solution
#1481 Extended
Updated AudioLoader and AudioContext to use modern FFmpeg APIs:
avcodec_decode_audio4()withavcodec_send_packet()+avcodec_receive_frame()avcodec_encode_audio2()withavcodec_send_frame()+avcodec_receive_packet()av_register_all()callsAVStream->codectoAVStream->codecparAVCodecContext->channelswithAVCodecContext->ch_layoutflushPacket()to properly handleAVERROR_EOFfloat*buffer with a byte-oriented bufferUpdated
build_config.shto upgrade FFmpeg from 2.8.12 to 7.1.1:avresampletoswresampleflagssdltosld2flagsUpdate unit tests for AudioLoader, EasyLoader, EqLoudLoader and MonoLoader:
shimfor Python < 3.12 style assert_test_audioloader_streaming.py,test_easyloader_streaming.py,test_eqloudloader_streaming.pyandtest_monoloader.pynumpycompatibility by replacing assertEquals with assertEqualPrerequisites
Testing
Closes
How to test
Tested with ffmpeg version 7.1.1 compiled from the source code https://ffmpeg.org/releases/ffmpeg-7.1.1.tar.gz
in:
How to build FFmpeg
After installing Essentia dependencies in a virtual environment, install cmake
Then we'll run the building script:
How to build Essentia
MacOS
Linux
How to unittest