ffpp
is a dynamic library written in C++ with an API for most major tasks using FFmpeg. Much faster for GUI applications than using processes.
Requires Clang
Invoke-WebRequest -Uri "https://bit.ly/libffppwin" -OutFile "libffppwin.rar"
Extract the .rar
Enter the folder:
cd .\libffppwin
main.cpp
:#include "ffpp/ffpp.hpp"
#include <memory>
int main(){
auto ffpp = std::make_unique<FFPP>();
std::cout << "Duration: "
<< ffpp->ffpp_info(FFPP_INFO::DURATION, "video.mp4") << '\n';
}
Optional test video: video.mp4
# PowerShell
pwsh build.ps1 main.cpp # Or more files
# Or: Windows [PowerShell](https://terminalroot.com/tags#powershell)
powershell build.ps1 main.cpp # Or more files
# Or directly
.\build.ps1 main.cpp # Or more files
If Windows Defender blocks execution, allow the script:
pwsh -ExecutionPolicy Bypass -File build.ps1 main.cpp # Or more files
The build.ps1
script compiles and runs the generated binary. Output example: Duration: 00:00:05
To build the libffmpeg and compile the DLL from scratch, check: build-win.md
Dependencies:
sudo pacman -S gcc ffmpeg make cmake pkg-config git
sudo apt install build-essential ffmpeg make cmake pkg-config git
Run all the commands below:
git clone https://github.com/terroo/ffpp
cd ffpp
cmake . -B build
cmake --build build
sudo cmake --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.conf
sudo ldconfig
Create a basic code, e.g., main.cpp
:
#include <ffpp/ffpp.hpp>
#include <memory>
int main(){
auto ffpp = 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
.
Assuming you created the object on the heap (auto ffpp = std::make_unique<FFPP>();
).
MP4
to WMV
:ffpp->ffpp_convert("video.mp4", "new.wmv");
Converts only between these video formats:
.mp4
,.flv
,.wmv
,.mov
ffpp->ffpp_extract_frames("video.mp4", "my_frames_dir");
.ppm
images will be created inside the given folder (my_frames_dir/
).
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';
ffpp->ffpp_cut("video.mp4", "00:00:10", 6, "output.mp4");
Cuts the video starting at 10 seconds for a duration of 6 seconds.
The video is in Brazilian Portuguese, but you can enable YouTube auto-translation or audio track (if available).