### JUCE FFmpeg Build Configuration Source: https://context7.com/c41x/juce-ffmpeg/llms.txt Details the necessary steps to configure a JUCE project to use FFmpeg. This includes defining `JUCE_USE_FFMPEG=1` in the project's configuration and linking against the required FFmpeg libraries (`libavcodec`, `libavformat`, `libavutil`, `libswresample`). CMake example and manual file inclusion steps are provided. ```cpp // In your JUCE module configuration (AppConfig.h or Projucer settings) #define JUCE_USE_FFMPEG 1 // Required FFmpeg libraries for linking: // - libavcodec // - libavformat // - libavutil // - libswresample // Example CMake configuration /* find_package(PkgConfig REQUIRED) pkg_check_modules(FFMPEG REQUIRED libavcodec libavformat libavutil libswresample ) target_include_directories(MyApp PRIVATE ${FFMPEG_INCLUDE_DIRS}) target_link_libraries(MyApp PRIVATE ${FFMPEG_LIBRARIES}) */ // Manual installation steps: // 1. Copy juce_FFmpegAudioFormat.cpp and .h to JUCE/modules/juce_audio_formats/codecs/ // 2. Edit modules/juce_audio_formats/juce_audio_formats.cpp: // #include "codecs/juce_FFmpegAudioFormat.cpp" // 3. Edit modules/juce_audio_formats/juce_audio_formats.h: // #include "codecs/juce_FFmpegAudioFormat.h" ``` -------------------------------- ### Read Audio Files with AudioFormatManager and FFmpeg Source: https://context7.com/c41x/juce-ffmpeg/llms.txt Demonstrates how to use JUCE's `AudioFormatManager` to register and utilize the `FFmpegAudioFormat` for reading audio from various file formats, including loading the entire file into an `AudioBuffer` or seeking to specific positions. It requires the `juce_FFmpegAudioFormat.h` header. ```cpp #include "juce_FFmpegAudioFormat.h" // Set up format manager with FFmpeg support AudioFormatManager formatManager; formatManager.registerBasicFormats(); // Register WAV, AIFF, etc. formatManager.registerFormat(new FFmpegAudioFormat(), false); // Load any supported audio file File mediaFile("/path/to/video.mkv"); // Can be audio or video container std::unique_ptr reader( formatManager.createReaderFor(mediaFile) ); if (reader) { // Read entire file into memory AudioBuffer fileBuffer( reader->numChannels, (int)reader->lengthInSamples ); reader->read( &fileBuffer, 0, // destStartSample (int)reader->lengthInSamples, 0, // sourceStartSample true, // fillLeftoverChannelsWithCopies true // clearExtraChannels ); // Seek and read from specific position int64 seekPosition = reader->lengthInSamples / 2; // Middle of file AudioBuffer seekBuffer(2, 1024); reader->read( seekBuffer.getArrayOfWritePointers(), 2, seekPosition, 1024 ); // Note: Seeking may not be sample-accurate due to FFmpeg limitations } ``` -------------------------------- ### Create AudioReader for FFmpeg-Decodable Files Source: https://context7.com/c41x/juce-ffmpeg/llms.txt This C++ snippet shows how to create an `AudioFormatReader` using `FFmpegAudioFormat` to decode audio from an `InputStream`. It handles format detection, decoder selection, and sample rate conversion, outputting stereo 32-bit float audio. The code also demonstrates how to access metadata and read audio samples into an `AudioBuffer`. ```cpp #include "juce_FFmpegAudioFormat.h" // Create a reader from a file File audioFile("/path/to/audio.mp4"); FileInputStream* fileStream = new FileInputStream(audioFile); FFmpegAudioFormat ffmpegFormat; AudioFormatReader* reader = ffmpegFormat.createReaderFor( fileStream, true // deleteStreamIfOpeningFails - delete stream if format cannot be opened ); if (reader != nullptr) { // Access audio metadata double sampleRate = reader->sampleRate; // e.g., 44100.0 unsigned int numChannels = reader->numChannels; // Always 2 (stereo output) int64 totalSamples = reader->lengthInSamples; // Total sample count int bitsPerSample = reader->bitsPerSample; // 32 (floating point) bool usesFloat = reader->usesFloatingPointData; // true // Read audio samples into a buffer const int numSamplesToRead = 4096; AudioBuffer buffer(2, numSamplesToRead); reader->read( buffer.getArrayOfWritePointers(), // destination buffer 2, // number of channels 0, // start position in file (samples) numSamplesToRead // number of samples to read ); // Process the audio data float* leftChannel = buffer.getWritePointer(0); float* rightChannel = buffer.getWritePointer(1); // Clean up delete reader; } else { // Failed to create reader - unsupported format or corrupted file DBG("Failed to open audio file"); } ``` -------------------------------- ### Register FFmpegAudioFormat with JUCE Source: https://context7.com/c41x/juce-ffmpeg/llms.txt This C++ snippet demonstrates how to register the FFmpegAudioFormat with JUCE's AudioFormatManager. This allows JUCE applications to recognize and utilize FFmpeg for decoding various audio formats. It also shows how to query the supported file extensions, sample rates, bit depths, and channel configurations. ```cpp #include "juce_FFmpegAudioFormat.h" // Register the FFmpeg format with JUCE's AudioFormatManager AudioFormatManager formatManager; formatManager.registerFormat(new FFmpegAudioFormat(), false); // Check supported file extensions FFmpegAudioFormat ffmpegFormat; StringArray extensions = ffmpegFormat.getFileExtensions(); // Returns: .ape, .avi, .caf, .flv, .m4v, .matroska, .webm, .mov, .mp4, .3gp, // .3g2, .mj2, .mpc, .mpc8, .mpeg, .tta, .w64, .xmv, .xwma, .aac, // .ac3, .aif, .aifc, .aiff, .amr, .au, .dts, .m4a, .mka, .mp1, // .mp2, .mp3, .mpa, .ra, .snd, .spx, .wma // Query format capabilities Array sampleRates = ffmpegFormat.getPossibleSampleRates(); // Returns: 8000, 11025, 12000, 16000, 22050, 32000, 44100, 48000, 88200, 96000, 176400, 192000 Array bitDepths = ffmpegFormat.getPossibleBitDepths(); // Returns: 16, 24, 32 bool stereoSupport = ffmpegFormat.canDoStereo(); // true bool monoSupport = ffmpegFormat.canDoMono(); // true bool isCompressed = ffmpegFormat.isCompressed(); // true ``` -------------------------------- ### Audio Playback Control with AudioTransportSource and FFmpeg Source: https://context7.com/c41x/juce-ffmpeg/llms.txt Shows how to integrate FFmpeg-decoded audio into JUCE's `AudioTransportSource` for playback control. This class manages play, pause, and seeking functionalities, requiring the `juce_FFmpegAudioFormat.h` header and implementing the `AudioSource` interface. ```cpp #include "juce_FFmpegAudioFormat.h" class AudioPlayer : public AudioSource { public: AudioPlayer() { formatManager.registerBasicFormats(); formatManager.registerFormat(new FFmpegAudioFormat(), false); } void loadFile(const File& file) { auto* reader = formatManager.createReaderFor(file); if (reader != nullptr) { readerSource.reset(new AudioFormatReaderSource(reader, true)); transportSource.setSource( readerSource.get(), 0, // readAheadBufferSize (0 = default) nullptr, // readAheadThread reader->sampleRate, // sourceSampleRate 2 // numChannels ); } } void play() { transportSource.start(); } void stop() { transportSource.stop(); } void setPosition(double positionInSeconds) { transportSource.setPosition(positionInSeconds); } double getLengthInSeconds() const { return transportSource.getLengthInSeconds(); } // AudioSource implementation void prepareToPlay(int samplesPerBlockExpected, double sampleRate) override { transportSource.prepareToPlay(samplesPerBlockExpected, sampleRate); } void releaseResources() override { transportSource.releaseResources(); } void getNextAudioBlock(const AudioSourceChannelInfo& bufferToFill) override { transportSource.getNextAudioBlock(bufferToFill); } private: AudioFormatManager formatManager; std::unique_ptr readerSource; AudioTransportSource transportSource; }; ``` -------------------------------- ### Include FFmpeg Headers in JUCE Source: https://github.com/c41x/juce-ffmpeg/blob/master/README.md This snippet shows how to include the necessary FFmpeg audio format reader files into the JUCE source code. It requires adding both the .cpp and .h files to the JUCE build system. ```c++ #include "codecs/juce_FFmpegAudioFormat.cpp" #include "codecs/juce_FFmpegAudioFormat.h" ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.