anewhobby at May 3rd, 2012 04:56 — #1
I am making a simple game for fun and learning using SFML for 2D stuff. The game is rather simple.. I loath to say it is a HoG (hidden object game) but I guess that would be a way to get my point across quickly. Basically I am using SFML to load and display 2D still art and capture mouse events.
Anyway... I would like to add video clips to my project. All the art is rendered and for example.. if my image is of a park with a fountain, I would like to have a looping video of the water running so the image has some life even though it is just a still.
All I need is the ability to play videos in the window, preferably compatible with sfml but I am in the planning projects I can swap to something else if needed. The project will have a set resolution (not scalable) and I just want to load the video and play them at a certain pixel location in x,y. So if I have a 1200x720 image I play a 100x100 pixel video on loop at a certain location to make the water of the fountain move.
Now then I am thinking I can just load 2D sprites onto of the video matching the background image to do simple masking. There are some formats like quicktime that can embed an alpha channel directly into the video and if that is supported awesome.. but some planning in the set design should mean that is not really needed. Though if that was supported more options open in set design.
I am pretty good with video as I am a 3D animator by profession, new to programming as a learning hobby. So the format and container of the video is not really an issue though I have been working with OGV a lot recently.
What I see as it needing is
- Load multiple videos at once
- Play with out any boarders or anything
- Play at specific locations in a window.
- loop seamlessly
- Allow zdepth so I can place sprites onto of it
Dose anyone know were I would go to start looking into this? It seams like something that could possibly be a library I could use? Preferably an open source one as this is just a for fun project nothing commercial.
Thanks in advance for any ideas you may have.
david_gallagher at May 4th, 2012 01:05 — #2
stainless at May 4th, 2012 06:44 — #3
Most people use Bink video for this, not sure if you can get a casual game licence though.
Doing video without a well designed tool chain is a nightmare.
It is easy to find decoders for some file formats, then find your video editor doesn't support that format. So you grab a converter, and find that it uses a variant codec which the code cannot handle.
It can be done, as long as you are prepared to fiddle with your tool chain.
Probably the easiest way is to pick a file format your tools can handle, then go looking for a decoder.
thenut at May 5th, 2012 07:03 — #4
Another option is DirectShow. There's a tutorial about it here. The only drawback here is that your users will require any special codecs installed on their machine before they can view your videos. If you stick to WMV, you should be fine.
I'm not sure how far you'll get with alpha channel videos. I don't think such a format would be hardware accelerated or even a widely supported feature since most videos are encoded using YUV. I would sooner implement animated RGBA sprites instead of a video. A typical sprite sheet can house a dozen images. It loads fast and you can take advantage of hardware accelerated rendering.
mariusz at May 18th, 2012 04:58 — #5
If you are interested in the topic connected with C++ technology we can help You, you can download the teaser of new Game Coder Magazine in which there are tutorial about the topic I've mentioned.
vilem_otte at May 18th, 2012 05:59 — #6
You can use ffmpeg to do all the stuff needed - here is one tutorial how to use ffmpeg with C - http://dranger.com/ffmpeg/
I also know that OpenCV can stream from some file-formats, but I've used it just for webcam, so I don't know whether there is any tutorial on it.
And I'm sure there is a lot of other libraries to do this stuff - you can also try making your own (reading raw avis is brain-dead simple, compressed ... well... a bit harder, but still possible).
stainless at May 20th, 2012 06:45 — #7
Have a think about how many frames of animation you really need.
The example of flowing water is a good one, (ignoring procedural generation) the most common way of handling animated water is to simply have a set of 2d textures and swap between them over time.
Rather than spending lot's of time getting a video decoder working, you might take the KISS approach and just have a sprite sheet