GithubHelp home page GithubHelp logo

demo_ffmpeg_vaapi_gl's Introduction

demo_ffmpeg_vaapi_gl

This is a demo project for demonstrate integration of hardware decoding and rendering via VAAPI ( libva ) to OpenGL texture and recording at the same time. It is based of the use of EGLImage that act as an handle between memory space of different api on the gpu, and in this case opengl and vaapi. This result as an zero copy procedure, if we exclude the conversion to RGBA ( that simplify shader dev ). Rapid explanation of how it works below.

Demo

Configuration

You may to change the following defines in config.h :

#define RECORD_FILENAME         "/tmp/video_%02d.mp4"

#define VIDEO_0                 "/home/fmor/video/lipsync2.mp4"
#define VIDEO_1                 "/home/fmor/video/savon.mp4"
#define VIDEO_2                 "/home/fmor/video/star_trek.mp4"
#define VIDEO_3                 "/home/fmor/video/prologue.mkv"
#define VIDEO_4                 "/home/fmor/video/titan.mp4"
#define VIDEO_5                 "/home/fmor/video/loups.mp4"

Control

  • Arrow keys for moving, mouse for camera
  • R to start and stop recording, recorded video will be named according RECORD_FILENAME. The video file will have a h264 video stream and a mp3 audio stream.
  • A/Q to quit
  • ESC to focus/unfocus mouse

How it works

Setup:

  • Initialize the libva lib with /dev/dri/renderDxxx device.
  • Create a ffmpeg HW device context for vaapi
  • Set the ffmpeg HW device vaapi created with the the va display obtainned by vaGetDisplayDRM
  • Create and EGL context

Decode and render to texture :

  • Create an AVCodecContext that and set the hw device context
  • Create a va surface of pixel format BGRX
  • Create an egl image with the va_surface as target ( util.c )
  • Create a GL_TEXTURE_2D and bind it with the EGL Image
  • Create a va postprocess pipeline in order convert ( H264 -> GL_RGBA )
  • when a ffmpeg AVCodecContext decode a frame use postprocess pipeline to render to the va_surface BGRX
  • Your GL_RGBA texture is ready to be used.

Encode GL window :

  • Create a va surface of pixel format BGRX
  • Create an egl image with the va_surface as target ( util.c )
  • Create a GL_TEXTURE_2D and bind it with the EGL Image
  • Create a dst FrameBuffer and attach it the texture as color attachment
  • Create an pool of hw frame context from the hw device context
  • Create an AVCodecContext and set the hw device context and the pool of hw frame
  • Create a va postprocess pipeline GL_RGBA -> H264/NV12
  • for each frame you want to add to the video, pass the source framebuffer you want to render
  • Blit the source framebuffer to the dst framebuffer
  • Pick a hw frame and render the va surface of the texture to the va surface of the picked avframe using postprocess va pipeline
  • Your H264 frame is ready to be send to the encoder.

Preriquisitorites

  • Video file with a least one H264 video stream
  • Intel processor that support H264 hardware decoding/encoding
  • Linux based operating system
  • Ffmpeg must support vaapi en mp3 encoding

Libraries used

demo_ffmpeg_vaapi_gl's People

Contributors

fmor avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

demo_ffmpeg_vaapi_gl's Issues

eglCreateImage return EGL_NO_IMAGE

code:
egl_image = eglCreateImage( eglGetCurrentDisplay(), EGL_NO_CONTEXT, EGL_LINUX_DMA_BUF_EXT, NULL, egl_img_attributes );

system:
admin1@admin1:~/test/demo_ffmpeg_vaapi_gl/build$ uname -a
Linux admin1 5.4.18-53-generic #42-KYLINOS SMP Fri Mar 4 03:34:54 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux

When I refer to obs error handling, the message printed is:
"Arguments are inconsistent (for example, a valid context requires buffers not supplied by a valid surface).";

Do not know how to solve。

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.