Play a video file in c++

Started by
32 comments, last by MLillowitz 12 years, 1 month ago
Most video codecs will offer you a memory area that represents a frame image in a particular format, most of the time this is something like YUV or YCbCr. These formats are convertible to RGB without a lot of computation, the resulting RGB image can then be stuck in a texture and rendered to any textured area in your game, for FMV's this is usually a viewport covering quad.

This is how most applications show video, even when you use bink or another decoder library you are going to have to deal with the displaying of the resulting image yourself. This is because it gives you the most flexibility in how you want to use the video in your game or application.

Worked on titles: CMR:DiRT2, DiRT 3, DiRT: Showdown, GRID 2, theHunter, theHunter: Primal, Mad Max, Watch Dogs: Legion

Advertisement

[quote name='MattProductions' timestamp='1332882232' post='4925808']
Many thanks for your reply, but unfortunately that's not really what I'm looking for.

I'm looking more for a code that I can paste (and maybe adjust a bit) in my engine to make it work.
Is their something like that available or is it just a weird idea?


Bink video is one of my favorites, but you have to license it (last I checked).
[/quote]+1 for Bink.
Thanks for the many, many replies.

But still, I don't have a clear solution on how to use it in my game.
So, if you could help solving the real issue.

Maybe you guys could focus more on that, rather than comparing technologies with each other.
1. Get a library
2. Call the library functions from your game

Part 1 has been discussed in the thread, part 2 is a case of reading the documentation for whatever library you decide to use.
I've read through them all again, but none of them provide a link to a website with more info/examples.
Using google just redirected me to other forums where people talk about the stuff.
But the issue is that I don't understand most of it and that doesn't help me further, sadly.
Which OS (min/max version)?
How do you intend to display the video (as DIBs, via GPU surface, via some handle, ...)?
What playback requirements - can you just launch mplayer2.exe and set it to full screen?
Which codecs?
How much can you spend on a license, either for implementation or for specific format (such as mpeg)?


There simply isn't a simple one size fits all answer here.
Which game engine are you using if it is not your own? Give us some more information about the tools and software you are using to build your game with and out awnsers can become more specific. Just because there is no video class doesn't immediately mean that your chosen engine doesn't support video playback yet, it might just be called differently. The video playback in the engine I code for on a daily basis doesn't have a video class either it does however support bink video playback in the manner I outlined in my previous post.

Worked on titles: CMR:DiRT2, DiRT 3, DiRT: Showdown, GRID 2, theHunter, theHunter: Primal, Mad Max, Watch Dogs: Legion

Well, let's sum up the specifications.

- C++
- Visual Studio 2010 (Win32 Project)
- It's an engine provided by school (I can modify it, it's just a big .h and .ccp file).

What I want to do

I want to play a movie on the screen and animation a sprite at the left side (on top of the video).
So when the user presses the right arrow key, than then actor will start walking (+ animation).
When the movie is finished, the game will end and the window will close (easy using a GetDuration()) method).

Does that clear things up?

So when the user presses the right arrow key, than then actor will start walking (+ animation).


Pre-render the animation into the movie.

system("mplayer2.exe /play /close mymovie.wmv")

I know, I know, it's not how it's done, etc....

But it's one line of code and doesn't require mucking with most anything. Might have to tweak Z-order or such. Or perhaps try embedding the player control into your window (see MSDN).

The overlay of content is much trickier and not worth the effort here.

Or study through how DirectShow or similar framework works, then render video in background, combine with your animation renderer, sync to media timer.... it would be the "right" way to do, more flexible, but also much more complex. On Windows it's still not rocket science, just a fair amount of gnarly API calls.

It's just that syncing of media content has its own quirks. So movie playback APIs either ignore that aspect completely (give you a blob that plays video) or offer somewhat non-trivial overlay mechanism. Middle ground is sometimes done by overlaying the content, such as having media player in background Z order and rendering a window on top of it. That may work, but can be unreliable for general purpose.

Correct syncing is difficult since it needs to be synchronized to audio (which cannot lag or skew). Even if playing back video alone and combining it with animation, there's issue of sync, what happens if either video or animation is slow.

Flash and similar tools solve this problem by hiding all of that inside the runtime and present everything at fixed time. In C++, you're mostly on your own, having to map these concepts to HWND and whatever else is involved.
Well, if I would just render my animation (walk cycle) into my video, than I could just play a video in a normal media player/
Maybe I should trie to embed a video player into my game and hide the controls (let them draw outside my window).

That might be an option (or not?)

This topic is closed to new replies.

Advertisement