|
1 | | -# ffmpeg-api |
| 1 | +# ffmpeg-api |
| 2 | +A mod that lets developers easily interact with ffmpeg to record raw videos, and mix video and audio files. |
| 3 | + |
| 4 | +## Usage |
| 5 | + |
| 6 | +### Record videos |
| 7 | + |
| 8 | +```cpp |
| 9 | +#include <eclipse.ffmpeg-api/include/recorder.hpp> |
| 10 | + |
| 11 | +void video() { |
| 12 | + ffmpeg::Recorder recorder; |
| 13 | + |
| 14 | + RenderSettings settings; |
| 15 | + |
| 16 | + //ffmpeg-api will automatically handle conversion between the input pixel |
| 17 | + //format and the codec's pixel format |
| 18 | + settings.m_pixelFormat = PixelFormat::RGB0; |
| 19 | + settings.m_codec = "h264_nvenc"; |
| 20 | + settings.m_bitrate = 30000000; |
| 21 | + settings.m_width = 1920; |
| 22 | + settings.m_height = 1080; |
| 23 | + settings.m_fps = 60; |
| 24 | + settings.m_outputFile = "output_video.mp4"; |
| 25 | + |
| 26 | + //insert your raw data here |
| 27 | + std::vector<uint8_t> frame; |
| 28 | + |
| 29 | + recorder.init(settings); |
| 30 | + |
| 31 | + for(int i = 0; i < 60; i++) |
| 32 | + recorder.writeFrame(frame); |
| 33 | + |
| 34 | + recorder.stop(); |
| 35 | +} |
| 36 | +``` |
| 37 | + |
| 38 | +### Mix audio |
| 39 | + |
| 40 | +```cpp |
| 41 | +#include <eclipse.ffmpeg-api/include/audio_mixer.hpp> |
| 42 | + |
| 43 | +void audioFile() { |
| 44 | + ffmpeg::AudioMixer mixer; |
| 45 | + mixer.mixVideoAudio("video.mp4", "audio.mp3", "output_mp3.mp4"); |
| 46 | + mixer.mixVideoAudio("video.mp4", "audio.wav", "output_wav.mp4"); |
| 47 | +} |
| 48 | + |
| 49 | +void audioRaw() { |
| 50 | + ffmpeg::AudioMixer mixer; |
| 51 | + |
| 52 | + //insert your raw data here |
| 53 | + std::vector<float> raw; |
| 54 | + mixer.mixVideoRaw("video.mp4", raw, "output_raw.mp4", 44100); |
| 55 | +} |
| 56 | +``` |
| 57 | + |
| 58 | +## Build instructions |
| 59 | +### Windows |
| 60 | +To get the needed libraries on Windows, you can use vcpkg |
| 61 | +```sh |
| 62 | +vcpkg install ffmpeg[core,avcodec,avformat,avutil,swscale,swresample,amf,x264,x265,nvcodec]:x64-windows-static --recurse |
0 commit comments