Movatterモバイル変換


[0]ホーム

URL:


Skip to content
DEV Community
Log in Create account

DEV Community

Cover image for How to use FFmpeg with C++ (Windows and GNU/Linux)
Marcos Oliveira
Marcos Oliveira

Posted on

     

How to use FFmpeg with C++ (Windows and GNU/Linux)

📺 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.

ffpp

Running onWindows.


ffpp

Running onGNU/Linux.


Usage onWindows

RequiresClang

  1. Downloadlibffppwin
Invoke-WebRequest-Uri"https://bit.ly/libffppwin"-OutFile"libffppwin.rar"
Enter fullscreen modeExit fullscreen mode
  1. Extract the.rar

  2. Enter the folder:

cd .\libffppwin
Enter fullscreen modeExit fullscreen mode
  1. 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';}
Enter fullscreen modeExit fullscreen mode

Optional test video:video.mp4

  1. 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
Enter fullscreen modeExit fullscreen mode

IfWindows Defender blocks execution, allow the script:

pwsh-ExecutionPolicyBypass-Filebuild.ps1main.cpp# Or more files
Enter fullscreen modeExit fullscreen mode

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
Enter fullscreen modeExit fullscreen mode

OnDebian/Ubuntu/Mint:

sudoaptinstallbuild-essential ffmpeg make cmake pkg-config git
Enter fullscreen modeExit fullscreen mode

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
Enter fullscreen modeExit fullscreen mode

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';}
Enter fullscreen modeExit fullscreen mode

Optional test video:video.mp4

Compile and run:

g++ main.cpp-lavformat-lavcodec-lavutil-lswscale-lffpp./a.out
Enter fullscreen modeExit fullscreen mode

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");
Enter fullscreen modeExit fullscreen mode

Converts only between these video formats:.mp4,.flv,.wmv,.mov


02. Extract frames:

ffpp->ffpp_extract_frames("video.mp4","my_frames_dir");
Enter fullscreen modeExit fullscreen mode

.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';
Enter fullscreen modeExit fullscreen mode

04. Cut a video from a time point with specific duration:

ffpp->ffpp_cut("video.mp4","00:00:10",6,"output.mp4");
Enter fullscreen modeExit fullscreen mode

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


Top comments(0)

Subscribe
pic
Create template

Templates let you quickly answer FAQs or store snippets for re-use.

Dismiss

Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment'spermalink.

For further actions, you may consider blocking this person and/orreporting abuse

EN: https://terminalroot.com/BR: https://terminalroot.com.br/
  • Location
    Brasil, Paraná
  • Joined

More fromMarcos Oliveira

DEV Community

We're a place where coders share, stay up-to-date and grow their careers.

Log in Create account

[8]ページ先頭

©2009-2025 Movatter.jp