Note: This library is in beta. Your feedback and support in enhancing its quality are greatly appreciated!
raylib-media is a clean and user-friendly extension for raylib that adds seamless audio and video streaming support via the FFmpeg libav* libraries. It enables easy integration of multimedia content into raylib applications, providing direct access to video textures and audio streams, with support for seeking and looping.
- Portable code: successfully tested on Windows, Linux, MacOS.
- Simple yet effective, with customizable options
- Direct access to video
Texture
andAudioStream
for efficient media handling - Optimized memory usage: no direct allocations are made outside the
LoadMedia
function. - Synchronized audio and video playback
- Supports media seeking and looping
- Supports loading media from custom streams, enabling flexible input sources like archives, online streams, or encrypted resource packs
- Compatible with formats supported by the codecs in the linked FFmpeg build
These 3-4 lines of code show the minimal code needed to play a video with raylib-media
:
#include <raymedia.h>
MediaStream media = LoadMedia("path/to/your_file.mp4"); // Load the media
while (...) { // Begin your main loop
...
UpdateMedia(&media); // Update the media stream according to frame time
...
DrawTexture(media.videoTexture, 0, 0, WHITE); // Draw the video frame
...
}
UnloadMedia(&media); // Unload media when done
Description: Demonstrates how to play a video on the screen and loop it continuously.
Description: A simple media player illustrating how to control playback speed, seek, pause, loop, adjust audio volume, and apply real-time shader effects to the video.
Description: A 3D demo scene demonstrating multiple video streams with synchronized audio that dynamically adjusts based on cursor proximity.
Description: Demonstrates how to use
LoadMediaFromStream
with custom callbacks for reading media.
This example simulates a custom stream using a memory buffer, showcasing the flexibility of the API. Real-world use cases include:
- Reading from compressed archives
- Streaming over a network
- Accessing custom data formats or encrypted resources
raylib-media
depends on the following files and libraries (a build system is not yet available, contributions are welcomed!):
E.g. with GCC:
gcc ... rmedia.c -lraylib -lavcodec -lavformat -lavutil -lswresample -lswscale
-
src/raymedia.h
andsrc/rmedia.c
- You can include them directly in your project or compile
rmedia.c
and use the compiled library.
- You can include them directly in your project or compile
-
- Since raylib-media is an extension of raylib, it's assumed you are already using it and know how to compile it. This can easily be done using CMake or one of the available project files.
-
The following subset of libav* libraries from FFmpeg:
libavcodec
libavformat
libavutil
libswresample
libswscale
You may want to start by using precompiled libraries and later compile your own version, if needed:
-
Linux: Install via your package manager (e.g.,
sudo apt install libavcodec-dev libavformat-dev libavutil-dev libswresample-dev libswscale-dev
). -
macOS: Use Homebrew (
brew install ffmpeg
). -
Windows: Download compiled libraries from sources like FFmpeg Builds by BtbN:
ffmpeg-n7.1-latest-win64-lgpl-shared-7.1.zip
FFmpeg is available in two versions:
- The complete version under a GPL license.
- A more permissive version without certain proprietary codecs under an LGPL license.
What does this mean for you?
- LGPL Version: If you prefer more flexibility in licensing your own code, choose the LGPL version. By linking LGPL libav* libraries dynamically, you're free to license your code as you wish without additional obligations.
- GPL Version: Using the GPL version requires that your code also be released under the GPL license, which mandates that the source code be made available under the same terms.
This project is licensed under the Zlib License - see the LICENSE file for details.
Special thanks to the following resources:
- FFmpeg Libav Tutorial - This resource was invaluable in helping me start to dive into FFmpeg and Libav.
- FFmpeg Builds by BtbN - For providing compiled dependencies that are easy and straightforward to use, perfect for immediately starting to use raylib-media in a "portable" way.
- Blender Open Movie projects - These movies are not just very cool, but they have been a precious resource for testing my code.