Jump to content

  • Log In with Google      Sign In   
  • Create Account


Play a video file in c++


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
33 replies to this topic

#1 MattProductions   Members   -  Reputation: 832

Like
0Likes
Like

Posted 27 March 2012 - 12:52 PM

Hi guys


I'm coding a small game atm (using a game engine) and I want to implement a video.
Since there isn't a video class included in the engine, I'm looking for some c++ code to do it for me.

I've been looking all over the internet for a few hours now, without any succes.
Most of them have dead links or talk about a win32 form (and not an application, which I use).

So hopefully anybody of you guys can help me solve this problem (I need it pretty quick).


Thanks in advance!

Sponsor:

#2 Adam Elston-Jones   Members   -  Reputation: 103

Like
1Likes
Like

Posted 27 March 2012 - 01:58 PM

You could try http://fobs.sourceforge.net/

#3 MattProductions   Members   -  Reputation: 832

Like
0Likes
Like

Posted 27 March 2012 - 03:03 PM

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?

#4 ApochPiQ   Moderators   -  Reputation: 14890

Like
2Likes
Like

Posted 27 March 2012 - 03:23 PM

Virtually nothing is truly copy-and-paste in the programming world, unless you're doing it wrong.

You'll have to live with at least a modicum of adjustment and customization for almost any system, especially one as large and complex as video rendering. Sometimes you must bend your code to fit the tool, and sometimes (for the better tools) you can bend the tool to fit your code.

#5 Antheus   Members   -  Reputation: 2397

Like
0Likes
Like

Posted 27 March 2012 - 04:24 PM

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?


Sure. '<embed src="www.youtube.com/..../>

But if working in C++, then no...

Reason for that is somewhat convoluted and not entirely technical.
a) you use proprietary codec, which comes with proprietary encoding and playback tools. How well they mesh with your way of doing graphics is down to luck
b) you use one of standard codecs, in which case third-party implementations aren't licensed for distribution (patents, IP, copyrights, etc.), so they're either reference implementations or long abandoned projects before this became a major issue
c) you use whatever OS provides. Unfortunately, most OSes come with quirks, so unless you want to encode same content for different formats, you need to redistribute the media frameworks (such as DX or DirectShow or similar). Most of these again come with various restrictions so they are not convenient to use by design.

Media is just a legal mess, it's also a reason why Java gave up on JMF and why browser vendors are having all those debates about what the content should look like.

#6 DvDmanDT   Members   -  Reputation: 847

Like
0Likes
Like

Posted 27 March 2012 - 05:41 PM

What engine are you using? OpenGL or DirectX?

#7 ApochPiQ   Moderators   -  Reputation: 14890

Like
1Likes
Like

Posted 27 March 2012 - 06:52 PM

What engine are you using? OpenGL or DirectX?


Neither OpenGL nor DirectX (nor, more pedantically, Direct3D) is an "engine." OGL and D3D are graphics APIs, which sit below the level of an engine.

#8 DvDmanDT   Members   -  Reputation: 847

Like
0Likes
Like

Posted 27 March 2012 - 07:03 PM


What engine are you using? OpenGL or DirectX?


Neither OpenGL nor DirectX (nor, more pedantically, Direct3D) is an "engine." OGL and D3D are graphics APIs, which sit below the level of an engine.


Ahh, yes, ofcourse. I should probably consume my caffeine before I post. What I mean was "Are you using an engine, if so, which one? Or have you rolled your own? Does the engine use OpenGL or Direct[2D|3D|Draw]"?

#9 Nypyren   Crossbones+   -  Reputation: 4104

Like
0Likes
Like

Posted 27 March 2012 - 09:36 PM

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).

#10 Krohm   Crossbones+   -  Reputation: 3040

Like
0Likes
Like

Posted 28 March 2012 - 01:02 AM

Since there isn't a video class included in the engine, I'm looking for some c++ code to do it for me.

I have successfully streamed webcam input to a D3D9 surface using DirectShow in the past. DirectShow is old and perhaps deprecated by now but I'm fairly sure it would happily decode anything you'd throw at it.
If you are really desperate, I could look for the code but it was a project thrown together with no plan of maintaining it so the code is old. And not so nice to look at.

#11 NightCreature83   Crossbones+   -  Reputation: 2734

Like
0Likes
Like

Posted 28 March 2012 - 03:11 AM

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, Mad Max

#12 Evil Steve   Members   -  Reputation: 1959

Like
0Likes
Like

Posted 28 March 2012 - 03:28 AM


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).

+1 for Bink.

Steve Macpherson
Senior programmer, Firebrand Games


#13 MattProductions   Members   -  Reputation: 832

Like
0Likes
Like

Posted 28 March 2012 - 04:02 AM

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.

#14 Evil Steve   Members   -  Reputation: 1959

Like
0Likes
Like

Posted 28 March 2012 - 04:23 AM

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.

Steve Macpherson
Senior programmer, Firebrand Games


#15 MattProductions   Members   -  Reputation: 832

Like
0Likes
Like

Posted 28 March 2012 - 11:28 AM

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.

#16 Antheus   Members   -  Reputation: 2397

Like
0Likes
Like

Posted 28 March 2012 - 11:37 AM

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.

#17 NightCreature83   Crossbones+   -  Reputation: 2734

Like
0Likes
Like

Posted 28 March 2012 - 12:47 PM

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, Mad Max

#18 MattProductions   Members   -  Reputation: 832

Like
0Likes
Like

Posted 28 March 2012 - 02:31 PM

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?

#19 Antheus   Members   -  Reputation: 2397

Like
0Likes
Like

Posted 28 March 2012 - 02:57 PM

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.

#20 MattProductions   Members   -  Reputation: 832

Like
0Likes
Like

Posted 28 March 2012 - 03:21 PM

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?)




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS