H264/HEVC Video Encoder for OpenGL
Shao Voon Wong - 26/Jul/2020
Shao Voon Wong - 26/Jul/2020
[SHOWTOGROUPS=4,20,22]
H264/HEVC Video Encoder for recording OpenGL rendering
H264/HEVC Video Encoder for OpenGL with h/w acceleration
Though this long article has more lines than the encoder library itself, this is a very simple and easy to read and understand article. If you have read my other articles before, you will be comfortable to know I do not write complicated stuff.
Table of Contents
Video Encoder
Introduction
I worked on this video encoder while writing my Windows Store App, Mandy Frenzy, a photo slideshow app for ladies. Right now, I am feeling burnt out so I am taking a short hiatus. Meanwhile, I am writing a series of short articles as a way to document this app. This video encoder is a header file only (H264Writer.h), based on Microsoft Media Foundation, not the old DirectShow as Microsoft did not expose the H264 and HEVC codec on DirectShow. It is tested on Windows 10. It should work fine on Windows 7/8 as well. Do let me know if you encounter any problem on those OSes. Windows 10 used to come bundled with HEVC codec. For unknown reasons, MS has taken it out in Windows 10 Fall Creators Update for the **new** Windows 10 installation and Для просмотра ссылки Войдиили Зарегистрируйся for $1.50 in the Microsoft Store. In the section below, some screenshots will show encoding artifacts present in MS HEVC video. HEVC quality issues are fixed with hardware acceleration.
What Are the Pros and Cons of This Encoder Over FFmpeg?
Для просмотра ссылки Войдиили Зарегистрируйся is GPL and so you may not concerned if you just want to encode the output of your personal renderer. For my freemium app, I prefer to steer clear of the licensing issues. How hobbyists usually encode their frames with FFmpeg is to save all the frames in HDD first which limits the number of frames and also directly impacted video duration that can be saved depending on the free HDD space. The extra step of saving and opening the files has negative impact of the encoding speed. Of course, tight integration with FFmpeg code may eliminate the frame saving part. On the other hand, this encoder reads RGB values from the framebuffer provided. The downside is it is not portable and only works on Windows 7/8/10.
3 Rendering Modes
The same OpenGL renderer can be compiled into 3 modes: normal OpenGL display mode, Video Encoder mode and Emscripten mode. The latter two's code sections are respectively guarded by VIDEO_ENCODER and EMSCRIPTEN macros. You can, by all means, use your own renderer with the video encoder. The default OpenGL renderer is just provided to show a working demo.
The documentation is divided into 3 main sections. The first section is get the demo up and running and on how to modify the parameters. The second section is on how to integrate it with your OpenGL framework. The demo uses a renderer framework taught in Для просмотра ссылки Войдиили Зарегистрируйся. The Для просмотра ссылки Войди или Зарегистрируйся used GLFW and is based on OpenGL 4.4: I converted his framework to use SDL and downgrade to OpenGL 2.0. The decision is based on the lowest denominator of what WebGL and Emscripten can support. A tutorial on how to integrate with DirectX will come later. In theory, this video encoder should integrate well with other graphics API like Vulkan, afterall, all it needs to be supplied with a video buffer and some synchronization in tandem to perform its work. The third section is on the explanation of the internals of the video encoder which you can skip if you are not into the encoder internals and implementation. And the last section explains the Emscripten part required to compile into asm.js or Webassembly.
Running the Demo
Spaceship Video
Для просмотра ссылки Войдиили Зарегистрируйся
[/SHOWTOGROUPS]
H264/HEVC Video Encoder for recording OpenGL rendering
H264/HEVC Video Encoder for OpenGL with h/w acceleration
Though this long article has more lines than the encoder library itself, this is a very simple and easy to read and understand article. If you have read my other articles before, you will be comfortable to know I do not write complicated stuff.
Table of Contents
- Introduction
- Running the Demo
- HEVC Artifacts
- Integration with your OpenGL Framework
- How Is Video Encoder Written
- Running as asm.js on Web Browser
- Hardware Acceleration
- Quality parameters in Constructor in v1.0.4
- Reference Book
- History
Video Encoder
- Visual C++ 2015/2017
- Windows 7/8/10
- SDL2
- SDL2 Image
- GLEW
- GLM
- Tiny OBJ loader
- Zlib
Introduction
I worked on this video encoder while writing my Windows Store App, Mandy Frenzy, a photo slideshow app for ladies. Right now, I am feeling burnt out so I am taking a short hiatus. Meanwhile, I am writing a series of short articles as a way to document this app. This video encoder is a header file only (H264Writer.h), based on Microsoft Media Foundation, not the old DirectShow as Microsoft did not expose the H264 and HEVC codec on DirectShow. It is tested on Windows 10. It should work fine on Windows 7/8 as well. Do let me know if you encounter any problem on those OSes. Windows 10 used to come bundled with HEVC codec. For unknown reasons, MS has taken it out in Windows 10 Fall Creators Update for the **new** Windows 10 installation and Для просмотра ссылки Войди
What Are the Pros and Cons of This Encoder Over FFmpeg?
Для просмотра ссылки Войди
3 Rendering Modes
The same OpenGL renderer can be compiled into 3 modes: normal OpenGL display mode, Video Encoder mode and Emscripten mode. The latter two's code sections are respectively guarded by VIDEO_ENCODER and EMSCRIPTEN macros. You can, by all means, use your own renderer with the video encoder. The default OpenGL renderer is just provided to show a working demo.
The documentation is divided into 3 main sections. The first section is get the demo up and running and on how to modify the parameters. The second section is on how to integrate it with your OpenGL framework. The demo uses a renderer framework taught in Для просмотра ссылки Войди
Running the Demo
Spaceship Video
Для просмотра ссылки Войди
[/SHOWTOGROUPS]