include video files in OpenGL...

Started by
3 comments, last by Lastblow 5 years, 9 months ago

Hi, first post here!

Been reading png files in SDL and using them as textures...

Now, would like to include in my game 2 short videos made in Blender, in dvi and mp4 formats.

Went over NeHe lesson 35 but when I try to read the dvi file, it gives null pointer for lpbi, see below.

Is it possible to include video files in OpenGL and how, please? ;-)))

 


void GrabAVIFrame(int frame)									// Grabs A Frame From The Stream
{
	LPBITMAPINFOHEADER lpbi;									// Holds The Bitmap Header Information
	lpbi = (LPBITMAPINFOHEADER)AVIStreamGetFrame(pgf, frame);	// Grab Data From The AVI Stream
	pdata=(char *)lpbi+lpbi->biSize+lpbi->biClrUsed * sizeof(RGBQUAD);	// Pointer To Data Returned By AVIStreamGetFrame

	// Convert Data To Requested Bitmap Format
	DrawDibDraw (hdd, hdc, 0, 0, 256, 256, lpbi, pdata, 0, 0, width, height, 0);

	flipIt(data);												// Swap The Red And Blue Bytes (GL Compatability)

	// Update The Texture
	glTexSubImage2D (GL_TEXTURE_2D, 0, 0, 0, 256, 256, GL_RGB, GL_UNSIGNED_BYTE, data);
}

 

Advertisement
3 hours ago, Lastblow said:

Hi, first post here!

Been reading png files in SDL and using them as textures...

Now, would like to include in my game 2 short videos made in Blender, in dvi and mp4 formats.

Went over NeHe lesson 35 but when I try to read the dvi file, it gives null pointer for lpbi, see below.

Is it possible to include video files in OpenGL and how, please? ;-)))

 



void GrabAVIFrame(int frame)									// Grabs A Frame From The Stream
{
	LPBITMAPINFOHEADER lpbi;									// Holds The Bitmap Header Information
	lpbi = (LPBITMAPINFOHEADER)AVIStreamGetFrame(pgf, frame);	// Grab Data From The AVI Stream
	pdata=(char *)lpbi+lpbi->biSize+lpbi->biClrUsed * sizeof(RGBQUAD);	// Pointer To Data Returned By AVIStreamGetFrame

	// Convert Data To Requested Bitmap Format
	DrawDibDraw (hdd, hdc, 0, 0, 256, 256, lpbi, pdata, 0, 0, width, height, 0);

	flipIt(data);												// Swap The Red And Blue Bytes (GL Compatability)

	// Update The Texture
	glTexSubImage2D (GL_TEXTURE_2D, 0, 0, 0, 256, 256, GL_RGB, GL_UNSIGNED_BYTE, data);
}

 

You can use the FFmpeg library to read/decode almost any video file format. FFmpeg is fast and very stable, but it is a pure low level api, so you dont get any high level functions like -> PlayVideo or GetPicture.

You have to manage packet/frame queuing/decoding yourself, but its not that hard if you know how to properly code multi-threaded queues and stuff. The hard part is to syncronize audio/video properly, but even 

 

There is a wonderful tutorial out there, which explain everything you need to know how to play a video - including sound: http://dranger.com/ffmpeg/

 

To get started, grap the shared libraries as well as the development package for version 4.0 from: https://ffmpeg.zeranoe.com/builds/

 

Also i have written a short video player using pure FFmpeg 4.0 based on my platform abstraction library. You can find the demo here.

Thank you for your quick reply, Finalspace! Will look into it and keep you updated. ;-)))

In fact, was trying to avoid extra dependencies but FFmpeg may be the way to go for my software to remain cross-platform, per a similar post on stackoverflow. Also posted in NeHe Productions forum concerning the null pointer in their tutorial.

Copy both links here below for reference.

https://stackoverflow.com/questions/39059959/vfw-avistreamgetframeopen-returns-null

https://www.gamedev.net/forums/topic/697579-avistreamgetframeopen-returns-nullptr/

As promised, video.cpp here attached plays a mp4 video whose codecs appear below.

Based on http://dranger.com/ffmpeg/, running Windows x64, Visual Studio 2015, SDL2, ffmpeg 4.0 and C++.

Hope it helps!

 

Input #0, mov,mp4,m4a,3gp,3g2,mj2, from ‘crawl.mp4’:
Metadata:
major_brand : isom
minor_version : 512
compatible_brands: isomiso2avc1mp41
creation_time : 1970-01-01T00:00:00.000000Z
Duration: 00:00:29.00, start: 0.000000, bitrate: 689 kb/s
Stream #0:0(und): Video: h264 (Constrained Baseline) (avc1 / 0x31637661), yuv420p, 1344x680, 612 kb/s, 10 fps, 10 tbr, 10 tbn, 20 tbc (default)
Metadata:
creation_time : 1970-01-01T00:00:00.000000Z
handler_name : VideoHandler
Stream #0:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, mono, fltp, 75 kb/s (default)
Metadata:
creation_time : 1970-01-01T00:00:00.000000Z
handler_name : SoundHandler
screen final size: 1344x680

video.cpp

This topic is closed to new replies.

Advertisement