Advertisement

smpeg to opengl

Started by December 17, 2004 03:29 PM
11 comments, last by Khaos Dragon 19 years, 9 months ago
I was wondering if anybody knows how with the smpeg library (a library intended to be used with sdl) to load a frame of an mpeg into an sdl surface so that it could be converted to an opengl texture object?
Ok here is how (seems kind of complicated but it works!). I hope this is what you are looking for. You can load a frame from smpeg into a SDL_Surface, than use that surface to convert to a OpenGL texture. If you need anymore help feel free to ask!

Advertisement
Hmm, well what I needed specifically was a way to extract a frame from an mpeg into an sdl surface.
Ohhh! I know of a tutorial that shows how to do it via an avi, but not a mpeg. Sorry about the mpeg, I'll take a look at that smpeg library's docs for any info.
Well after looking at the source code, theres no direct way to do it, but heres an idea I got after analyzing the source:

/* Set the destination surface for MPEG video playback   'surfLock' is a mutex used to synchronize access to 'dst', and can be NULL.   'callback' is a function called when an area of 'dst' needs to be updated.   If 'callback' is NULL, the default function (SDL_UpdateRect) will be used.*/extern DECLSPEC void SMPEG_setdisplay(SMPEG* mpeg, SDL_Surface* dst, SDL_mutex* surfLock, SMPEG_DisplayCallback callback);/* Render a particular frame in the MPEG video   API CHANGE: This function no longer takes a target surface and position.               Use SMPEG_setdisplay() and SMPEG_move() to set this information.*/extern DECLSPEC void SMPEG_renderFrame( SMPEG* mpeg, int framenum );


What you should try doing is this:

1. Create a SDL_Surface to where you want to save the frame to
2. Make a call to SMPEG_setdisplay, use the mpeg variable you have of the movie, and set the next parameter to the surface you want to render it to. For the remaining paramters, use 0.
3. Call SMPEG_renderFrame with the movie you are using and the frame you want to save.
4. Now that the surface has the data to it, use that tutorial I posted earlier to convert it into a OpenGL texture.
5. Now you have the OpenGL texture [wink]

I hope this helps! Give it a try and let me know. I havent had time to try out al these concepts, but they made sense in my head when I was reading the source. Goodluck

Hmmm, that does seem to make sense. Currently I am at my parent's house so won't be able to implement this right away, but this certainly steers me in the right direction. Thanks!
Advertisement
I found smpeg to be a big pain to use in OpenGL. The library does come with a demo for OpenGL video.

However, all my attempts at getting smpeg to work on windows have failed, it runs fine on linux though.

Finally i gave up and extracted the frames with VirtualDub, converted them all to JPEG and converted the soundtrack to OGG. Then i just render the frames myself (JPEG decoder from DevIL) and play the OGG file. I get a healthy 40FPS with a ~300x~300 video.
Quote: Original post by Ilici
I found smpeg to be a big pain to use in OpenGL. The library does come with a demo for OpenGL video.

However, all my attempts at getting smpeg to work on windows have failed, it runs fine on linux though.

Finally i gave up and extracted the frames with VirtualDub, converted them all to JPEG and converted the soundtrack to OGG. Then i just render the frames myself (JPEG decoder from DevIL) and play the OGG file. I get a healthy 40FPS with a ~300x~300 video.


What I would do is just re-encode to an avi, and use avi-playback. NeHe has a great tutorial on .avi. [wink]
Are you sure his avi player is stable? I have downloaded that tutorial before and tried replacing the avi it came with with other ones's (by simply renaming the file) and it would crash for about 90% of avi's I tried.
Quote: Original post by Khaos Dragon
Are you sure his avi player is stable? I have downloaded that tutorial before and tried replacing the avi it came with with other ones's (by simply renaming the file) and it would crash for about 90% of avi's I tried.


Hmmm, I haven't extensivly tried out that tutorial, but when I added its concepts to a test program and used my own avi, it worked. There was no audio b/c it doesn't tell how to do an avi with audio, but i bet you could easily add it in. But there is a nice article that the tutorial was based off of here. He also says:
Quote: With that said, I feel it is important to note that my code may not be the BEST way to play an AVI file. It may not even be the correct way to play an AVI file, but it does work, and it's easy to use.
.

Well I think you should just try the smpeg whenever you get the chance. But this is a big rason people use Bink videos for their video content. Take a look at it here. Not only does it do it fast and easy, it makes it a lot smaller as well. These are professional tools, but I think there are free versions as well.

[edit] I have spent over 1 hour trying to get the SMPEG libary to work, but I cannot. I do not know if it is the Mpeg file or if I am doing something wrong. All I do know is that the library is lacking on tutorials (couldn't find a one) and it is impossible to just figure out what to do. So I am abadoning SMPEG, goodluck with your program.

[Edited by - Drew_Benton on December 19, 2004 7:10:17 PM]

This topic is closed to new replies.

Advertisement