
📺 I Created a Dynamic Library with C++ for the FFmpeg C API to Make Integration Easier and Faster for Graphical Applications.
ffpp
is a dynamic library written inC++ with anAPI for most major tasks usingFFmpeg. Much faster for GUI applications than using processes.
Running onWindows.
Usage onWindows
RequiresClang
Invoke-WebRequest-Uri"https://bit.ly/libffppwin"-OutFile"libffppwin.rar"
Extract the
.rar
Enter the folder:
cd .\libffppwin
- Create a basic code, e.g.,
main.cpp
:
#include"ffpp/ffpp.hpp"#include<memory>intmain(){autoffpp=std::make_unique<FFPP>();std::cout<<"Duration: "<<ffpp->ffpp_info(FFPP_INFO::DURATION,"video.mp4")<<'\n';}
Optional test video:video.mp4
- Compile and run:
# PowerShellpwshbuild.ps1main.cpp# Or more files# Or: Windows [PowerShell](https://terminalroot.com/tags#powershell)powershellbuild.ps1main.cpp# Or more files# Or directly.\build.ps1main.cpp# Or more files
IfWindows Defender blocks execution, allow the script:
pwsh-ExecutionPolicyBypass-Filebuild.ps1main.cpp# Or more files
Thebuild.ps1
script compiles and runs the generated binary. Output example:Duration: 00:00:05
To build thelibffmpeg and compile the DLL from scratch, check:build-win.md
OnGNU/Linux
Dependencies:
OnArch:
sudopacman-S gcc ffmpeg make cmake pkg-config git
OnDebian/Ubuntu/Mint:
sudoaptinstallbuild-essential ffmpeg make cmake pkg-config git
Build and install
Run all the commands below:
git clone https://github.com/terroo/ffppcdffppcmake.-B buildcmake--build buildsudocmake--install build# Important after install# Something like: export LD_LIBRARY_PATH=/usr/local/lib# But system-wide:echo /usr/local/lib |sudo tee /etc/ld.so.conf.d/ffpp.confsudoldconfig
Create a basic code, e.g.,main.cpp
:
#include<ffpp/ffpp.hpp>#include<memory>intmain(){autoffpp=std::make_unique<FFPP>();std::cout<<"Duration: "<<ffpp->ffpp_info(FFPP_INFO::DURATION,"video.mp4")<<'\n';}
Optional test video:video.mp4
Compile and run:
g++ main.cpp-lavformat-lavcodec-lavutil-lswscale-lffpp./a.out
Example output:
Duration: 00:00:05
.
API Examples
Assuming you created the object on the heap (auto ffpp = std::make_unique<FFPP>();
).
01. ConvertMP4
toWMV
:
ffpp->ffpp_convert("video.mp4","new.wmv");
Converts only between these video formats:
.mp4
,.flv
,.wmv
,.mov
02. Extract frames:
ffpp->ffpp_extract_frames("video.mp4","my_frames_dir");
.ppm
images will be created inside the given folder (my_frames_dir/
).
03. Get video information:
std::cout<<"Duration: "<<ffpp->ffpp_info(FFPP_INFO::DURATION,"video.mp4")<<'\n';std::cout<<"Bitrate: "<<ffpp->ffpp_info(FFPP_INFO::BITRATE,"video.mp4")<<'\n';std::cout<<"FPS: "<<ffpp->ffpp_info(FFPP_INFO::FPS,"video.mp4")<<'\n';std::cout<<"Audio Frequency: "<<ffpp->ffpp_info(FFPP_INFO::AUDIO_FREQUENCY,"video.mp4")<<'\n';std::cout<<"Resolution: "<<ffpp->ffpp_info(FFPP_INFO::RESOLUTION,"video.mp4")<<'\n';
04. Cut a video from a time point with specific duration:
ffpp->ffpp_cut("video.mp4","00:00:10",6,"output.mp4");
Cuts the video starting at 10 seconds for a duration of 6 seconds.
📹 Watch the Video
https://youtu.be/3bm84QckF8E
The video is in Brazilian Portuguese, but you can enable YouTube auto-translation or audio track (if available).
👀 See Also
- 👑Learn to Create Your Own Programming Language
- ✅Learn Game Dev with C++ and SFML
- ✅C++ Promotional Package
- ✅Learn C++ and Qt
- ✅Check Out Our Courses
- 🎁All Courses on Udemy
Top comments(0)
For further actions, you may consider blocking this person and/orreporting abuse