• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
MattProductions

Play a video file in c++

33 posts in this topic

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!
0

Share this post


Link to post
Share on other sites
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?
0

Share this post


Link to post
Share on other sites
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 [i]any[/i] 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.
2

Share this post


Link to post
Share on other sites
[quote name='MattProductions' timestamp='1332882232' post='4925808']
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?
[/quote]

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

Share this post


Link to post
Share on other sites
[quote name='DvDmanDT' timestamp='1332891708' post='4925837']
What engine are you using? OpenGL or DirectX?
[/quote]

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

Share this post


Link to post
Share on other sites
[quote name='ApochPiQ' timestamp='1332895938' post='4925844']
[quote name='DvDmanDT' timestamp='1332891708' post='4925837']
What engine are you using? OpenGL or DirectX?
[/quote]

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

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]"?
0

Share this post


Link to post
Share on other sites
[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?
[/quote]

Bink video is one of my favorites, but you have to license it (last I checked).
0

Share this post


Link to post
Share on other sites
[quote name='MattProductions' timestamp='1332874357' post='4925773']
Since there isn't a video class included in the engine, I'm looking for some c++ code to do it for me.[/quote]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.
0

Share this post


Link to post
Share on other sites
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.
0

Share this post


Link to post
Share on other sites
[quote name='Nypyren' timestamp='1332905809' post='4925877']
[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?
[/quote]

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

Share this post


Link to post
Share on other sites
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.
0

Share this post


Link to post
Share on other sites
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.
0

Share this post


Link to post
Share on other sites
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.
0

Share this post


Link to post
Share on other sites
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.
0

Share this post


Link to post
Share on other sites
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.
0

Share this post


Link to post
Share on other sites
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?
0

Share this post


Link to post
Share on other sites
[quote name='MattProductions' timestamp='1332966688' post='4926110']
So when the user presses the right arrow key, than then actor will start walking (+ animation).
[/quote]

Pre-render the animation into the movie.

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

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

Share this post


Link to post
Share on other sites
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?)
0

Share this post


Link to post
Share on other sites
[quote name='Nypyren' timestamp='1332905809' post='4925877']
Bink video is one of my favorites, but you have to license it (last I checked).
[/quote]
[quote name='Evil Steve' timestamp='1332926887' post='4925936']
+1 for Bink.
[/quote]
From your experience, what makes Bink better than other options?
0

Share this post


Link to post
Share on other sites
[quote name='Servant of the Lord' timestamp='1332970873' post='4926132']
[quote name='Nypyren' timestamp='1332905809' post='4925877']
Bink video is one of my favorites, but you have to license it (last I checked).
[/quote]
[quote name='Evil Steve' timestamp='1332926887' post='4925936']
+1 for Bink.
[/quote]
From your experience, what makes Bink better than other options?
[/quote]

I've only ever had to play video in console games, so I've never even *seen* any other options. It's pretty simple and has never caused any headaches for us.

I've also done a bit of video recording/encoding with DirectShow in Windows. It takes a bit to learn how the graphs work, and after that it's just a matter of debugging them when they don't work. Playback sounds easier, though (the graph will be built automatically?!)

On Windows, as long as you have proper codecs, DirectShow is probably the best bet since you can use it for free. I have no idea what's available for Unix-based systems.
0

Share this post


Link to post
Share on other sites
[quote name='Nypyren' timestamp='1332988887' post='4926183']
I have no idea what's available for Unix-based systems.
[/quote]

http://sourceforge.net/apps/mediawiki/libtheoraplayer/index.php?title=Main_Page

you also got libvpx (for VP8) and ffmpeg.

The patent situation is, as always a bit murky with these. (for most of the mpeg formats its pretty clear, someone has to pay, VP8 and Theora is a bit of an unknown, there have been some saber rattling from the MPEG-LA about them but AFAIK noone has been sued yet), If you want to play it safe you can either:

1) Use ffmpeg but don't provide codecs, (not a great idea as many free distros don't provide the codecs either due to the patent issues).

2) Use ffmpeg and pay the necessary patentlicenses for the codecs you need to distribute.

3) and ofcourse, if you want to avoid all the hassle and has the budget for it, use Bink, it works on Win/Mac/Linux and all the modern consoles.
0

Share this post


Link to post
Share on other sites
[quote name='Servant of the Lord' timestamp='1332970873' post='4926132']
From your experience, what makes Bink better than other options?
[/quote]It's got a really nice, clean interface - Bink does rendering into a texture and notifies you when it's ready, it handles all of the timing and audio internally, and you don't need to mess around with codecs, etc as Nypyren mentioned. And it's cross platform, which is especially important for us.
0

Share this post


Link to post
Share on other sites
After some days of trying and failing, I want to change direction a bit.
I'm going to provide you guys the most basic files I have (A working project without any additional code).

You've got the skills to add video support to the engine.
So this is a list what should be done.

- Let a video play on screen (without any controls).
I've included an .avi for testing purposes.
- When the video is finished, the program has to quit
- If it's possible, it would be cool if the video was included in the project (so that I have 1 .exe file to share).

I would be very thankfull if somebody could pull it of for me.

Thanks a 1000x in advance, seriously
0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0