https://github.com/yzhong52/openglframebufferasvideo
Save OpenGL Framebuffer As Video With OpenCV
https://github.com/yzhong52/openglframebufferasvideo
Last synced: 6 months ago
JSON representation
Save OpenGL Framebuffer As Video With OpenCV
- Host: GitHub
- URL: https://github.com/yzhong52/openglframebufferasvideo
- Owner: yzhong52
- Created: 2014-01-14T22:22:34.000Z (over 11 years ago)
- Default Branch: master
- Last Pushed: 2017-02-26T13:44:59.000Z (over 8 years ago)
- Last Synced: 2025-03-20T17:01:38.272Z (7 months ago)
- Language: C++
- Size: 1.63 MB
- Stars: 23
- Watchers: 2
- Forks: 7
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
Save OpenGL Framebuffer As Video
================================We can save the OpenGL rendering result to a video using OpenCV buildt-in VideoWriter class. There are three steps:
**Create a video file to write**
- Read OpenGL framebuffer
- Close the video file
- Create a Video File to Write"video.avi" is the name of the file to save, 20.0f is fourcc, width and height are the size of the window. Finally, true indicate that we are saving
cv::VideoWriter outputVideo;
outputVideo.open( "video.avi", -1, 20.0f, cv::Size( width, height ), true);**Read OpenGL framebuffer**
cv::Mat pixels( height, width, CV_8UC3 );
glReadPixels(0, 0, width, height, GL_RGB, GL_UNSIGNED_BYTE, pixels.data );
cv::Mat cv_pixels( height, width, CV_8UC3 );
for( int y=0; y(y,x)[2] = pixels.at(height-y-1,x)[0];
cv_pixels.at(y,x)[1] = pixels.at(height-y-1,x)[1];
cv_pixels.at(y,x)[0] = pixels.at(height-y-1,x)[2];
}
outputVideo << cv_pixels;**Close the video file**
outputVideo.release();
Sample Code On [Github](https://github.com/yzhong52/Save-OpenGL-Framebuffer-As-Video).
This sample code shows how to save OpenGL framebuffer to a video using OpenCV. The openGL code is borrowed from [HeHe Lesson 05](http://nehe.gamedev.net/tutorial/3d_shapes/10035/).
The necessary libs and dlls are included in the project; therefore, you don't need to install OpenCV on your machine if you don't want to.