Skip to content

FFmpeg

2 posts with the tag “FFmpeg”

QML-FFmpeg Project Overview and Technical Architecture

🔗 GitLab repository: Utilities/QML-FFmpeg

QML-FFmpeg is a high-performance, multi-threaded video player solution built with Qt Quick/QML, FFmpeg, and SDL2. The project focuses on a smooth migration from the traditional OpenGL/FBO offscreen rendering path to a modern Qt Quick Scene Graph / RHI (Rendering Hardware Interface) compatible rendering pipeline. This reduces the dependency on a specific graphics backend and provides cross-platform hardware-accelerated playback capabilities.

  1. RHI-compatible Scene Graph rendering
    • Replaces the outdated QQuickFramebufferObject path with Qt Quick Scene Graph nodes for video frame rendering, making the player compatible with the Qt 6 RHI rendering architecture.
  2. Decoupled multi-threaded pipeline
    • Separates demuxing, video decoding, and audio playback into independent threads, keeping the UI responsive while preserving smooth playback.
    • Uses SDL2 audio playback as the master clock for AV sync, providing stable audio-video synchronization.
  3. Three-stage smooth hardware acceleration fallback
    • Stage 1 (zero-copy GPU rendering): zero-copy rendering based on Direct3D11 / VA-API, mapping GPU textures directly.
    • Stage 2 (GPU-to-CPU copy rendering): uses av_hwframe_transfer_data() to copy NV12 and other hardware-decoded frames back to system memory, then submits them to the Scene Graph after high-performance color-space conversion. This path has resolved hardware frame pool deadlocks and avfilter filtering issues.
    • Stage 3 (pure CPU software decoding): when hardware acceleration initialization or transfer fails repeatedly, the player reloads within 5 frames and smoothly falls back to CPU decoding, such as YUV420P, without interrupting playback.
  4. Dual integration architecture
    • Supports both direct static integration of the player core in a standalone application and dynamic injection as an independent QML extension plugin.
  5. Ready-to-use deployment and validation
    • Provides CMake presets and automation scripts. On Windows, required FFmpeg/SDL2 DLLs and test videos are copied after build; Linux (Ubuntu) deployment is also designed to remain portable.
QML-FFmpeg (project root)
├── QML-FFmpeg.pro # Main subdirs project file, directly openable in Qt Creator
├── docs/ # Hardware/software validation checklists and technical design notes
├── QMLVideoPlayer-OpenGL/ # Standalone app mode: statically compiled player core and QML HUD
├── VideoPlugin-OpenGL/ # QML plugin module: dynamically loaded C++ plugin with shader resources
├── Video-QML/ # Plugin test shell: pure QML test app importing VideoPlugin 1.0
└── ThirdParty/ # Third-party dependencies: prebuilt FFmpeg & SDL2 binary SDKs via Git LFS

According to the upstream platform_hwa_checklist.md, the current validation status is:

  • Windows (NVIDIA physical machine): Stage 2 (GPU-to-CPU NV12 copy rendering) and Stage 3 software decoding have been fully validated, providing strong stability and fault tolerance. D3D11 zero-copy rendering is still pending final closure.
  • Linux (Ubuntu virtual machine): because there is no GPU passthrough, VA-API hardware decoding is unavailable. The application successfully falls back to Stage 3 pure software decoding, and playback plus the control UI work normally.
  • ARM / embedded platforms: planned work includes Rockchip MPP and Raspberry Pi V4L2 M2M hardware decoding, plus DRM / GLES zero-copy rendering.

[1]. about/index.md

[2]. platform_hwa_checklist.md

FFmpeg Development Environment

Build a FFmpeg developing environment on Ubuntu-22.04-LTS with Qt and SDL.

Update all repositories.

sudo apt update && apt upgrade

Resolved in Ubuntu 22.04.2 LTS

On Video decoding/encoding with FFmpeg

  • x264

    • libavcodec58
      • libavcodec-extra58
    • libavformat58
      • libavformat-extra58
    • libavutil56
    • libc6
    • libffms2-5
    • libgpac11
    • libswscale5
    • libx264-163
  • x265

    • libc6
    • libstdc++6
    • libx265-199
    • libx265-199
  • libx264-dev

    • libx264-163
  • libx265-dev

    • libx265-199
  • libass-dev

    • libass9
    • libfontconfig1-dev
      • libfontconfig-dev
    • libfreetype-dev
    • libfribidi-dev
    • libharfbuzz-dev
  • libfdk-aac-dev

    • libfdk-aac2
    • pkg-config
      • pkg-config:i386
      • pkgconf
  • libfreetype-dev

    • libfreetype6
    • libbrotli-dev
    • libc6-dev
    • libc-dev
      • libc6-dev
    • zlib1g-dev
    • libz-dev
      • zlib1g-dev
  • libmp3lame-dev

    • libmp3lame0
  • libopus-dev

    • libopus0
  • libvorbis-dev

    • libogg-dev
    • libvorbis0a
    • libvorbisenc2
    • libvorbisfile3
  • libvpx-dev

    • libvpx7

On Audio decoding/encoding with SDL2:

  • libsdl2-dev
    • libasound2-dev
    • libdbus-1-dev
    • libdecor-0-dev
    • libdrm-dev
    • libegl1-mesa-dev
    • libgbm-dev
    • libgl-dev
    • libgles-dev
    • libglu1-mesa-dev
    • libibus-1.0-dev
    • libpulse-dev
    • libsdl2-2.0-0
    • libsndio-dev
    • libudev-dev
    • libwayland-dev
    • libx11-dev
    • libxcursor-dev
    • libxext-dev
    • libxfixes-dev
    • libxi-dev
    • libxinerama-dev
    • libxkbcommon-dev
    • libxrandr-dev
    • libxss-dev
    • libxt-dev
    • libxv-dev
    • libxxf86vm-dev
    • libc6
    • libopengl0
    • libx11-6

On configuring FFmpeg:

  • yasm
    • libc6

Install all dependencies with following command:

sudo apt install yasm gcc g++ cmake make \
x264 x265 libx264-dev libx265-dev \
libass-dev libfdk-aac-dev libvorbis-dev \
libfreetype-dev libmp3lame-dev libopus-dev \
libvpx-dev libsdl2-dev

Install Qt with Qt Online Installer.

It’s better to install Qt with USTC’s mirror.

Install with commands: .\qt-unified-windows-x86-online.exe --mirror https://mirrors.ustc.edu.cn/qtproject

DO NOT install Qt with sudo command nor with user ROOT.

If you prefer Qt Online Installer, libxcb-xinerama.so.0 is needed. To install this dependency, run following command sudo apt install libxcb-xinerama0.

It’s possible to install Qt from source. Follow the instruction, and the script is available here.

Download FFmpeg from Offical Web Site, install with compile commands below:

wget http://ffmpeg.org/releases/ffmpeg-4.2.9.tar.xz
tar -xvf ffmpeg-4.2.9.tar.xz
cd ffmpeg-4.2.9
sudo ./configure --enable-gpl --enable-libass --enable-libfdk-aac \
--enable-libfreetype --enable-libmp3lame --enable-libopus \
--enable-libvorbis --enable-libvpx --enable-libx264 \
--enable-libx265 --enable-pic --enable-shared --enable-nonfree \
--prefix=/usr/local/ffmpeg-4.2.9
make -j8
sudo make install

SDL2 has installed with system, headers installed when dependencies installed.

One-key environment installing script is provided:

Qt Framework will be installed via local compile, and downloaded opensource from USTC Mirror.

Qt will be installed in path: /usr/local/qt-5.15.2

  • Add FFmpeg to INCLUDEPATH in .pro file.

    • Add dynamic link -lavfilter -lavformat -lavdevice -lavcodec -lpostproc -lswscale -lavutil -lswresample to LIBS in .pro file for FFmpeg;
  • Add -lSDL2main -lSDL2 for SDL.

[1].https://qt.io

[2].http://mirrors.ustc.edu.cn/help/qtproject.html

[3].http://ffmpeg.org

[4].https://libsdl.org/

[5].https://blog.csdn.net/a1367666195/article/details/126055594

[6].https://askubuntu.com/questions/1298645/shared-library-not-found-for-pyqt5-libxcb-xinerama-so-0-not-found

[7]. Install-Qt-From-Source

[8]. VSCode-C-CPP-Environment