SFML community forums

General => SFML projects => Topic started by: WitchD0ctor on September 08, 2010, 03:19:13 pm

Title: SF Video Player
Post by: WitchD0ctor on September 08, 2010, 03:19:13 pm
I recently Integrated kspes' Theora Playback Library
http://sourceforge.net/projects/libtheoraplayer/

to use SFML images and sprites for cut-scenes in my game, I thought I would share it here for anybody who found it useful. Its not to much more than a simple wrapper, but it works quite well for most situations




with this you can get a video up and playing in about 5 lines,
the test program,
Code: [Select]




//Project files!
#include <iostream>
#include "movie_player.h"




/* Minimal Example */
 int main()
 {

sf::RenderWindow Rendow( sf::VideoMode(800, 600, 32), "Ubar Videoz", 6 );




MoviePlayer movieManager;


//Load and play Cutscenes
std::string vid_location = "resources/demo.ogv";
movieManager.playCutscene(&Rendow, vid_location, sf::Key::Escape, true);



Rendow.Close();

     return EXIT_SUCCESS;
 }//End ov Main!



the
Code: [Select]
playCutscene() is just a utility function to play a full screened video, that can be exited by a button you specify, you can also tell it to let the user control the video or not (seek, pause, etc).

you can also create an instance of MovieClip and control how/when to update/draw your movie, since it inherits from sf::Sprite, you can treat it like any other sprite object. So,

Code: [Select]



MoviePlayer movieManager;


//Load video manually
MovieClip *clip;
clip = movieManager.loadClip( vid_location, TH_RGBA );

//TH_RGBA is an enum for how to load the video pixel data,
//SFML's LoadFromPixel function likes this one

...

//in while loop

//Do silly Sprite things to the video
                clip->SetPosition(30, 50);
clip->Rotate(10);
clip->SetColor( sf::Color(255,255,255,100) );
                clip->Resize(800, 600);



clip->Update( Rendow->GetFrameTime() );

             Rendow->Clear();
                    clip->Draw( &Rendow );
             Rendow->Display();


This would play a movie that sets its position, rotates, resizes,  and is partially transparent, not sure why you would do that, however the option is there!

here it is,

...

Includes the sources, VS2010 project,  dependencies to compile it, and a simple test program,
note I didn't include the debug version of the dependencies, so the test program  will only compile in Release mode. You should be able to fix this if you include it in your game

Let me know what you think of it.


[EDIT] Newer Version: Just updated to include vs2008 project, nothing really new :o
Win. (http://www.blackshark.nukelol.com/video_player/VideoPlayer_002.zip)





PS. I used the OpenAL interface straight from the Theora playback lib examples, if any body wants to make and share an interface using SFML's audio library, I would be most grateful.  

PSS. If you need to convert video into the Theora format, i would suggest Theora Converter.NET if your on windows, Dead simple to use and works quite well.
Title: SF Video Player
Post by: TheMagician on September 08, 2010, 03:25:44 pm
You should also post this to the wiki! http://www.sfml-dev.org/wiki/en/sources
Title: SF Video Player
Post by: WitchD0ctor on September 10, 2010, 06:37:19 pm
don't really know how :o
Title: SF Video Player
Post by: HAWXthy on September 22, 2010, 09:44:40 pm
hi, I have a problem with this libary. Can you explain me how I must link and include it?^^
Title: SF Video Player
Post by: WitchD0ctor on September 23, 2010, 02:28:13 pm
what errors are you getting?

you should include files,
movie_clip.cpp/h
movie_player.cpp/h
and
OpenAL_AudioInterface.cpp/h
in your project,

then link
OpenAL32.lib  
libtheoraplayer_static.lib

in your project,

the 'main.cpp' is just a simplistic example of how to use the lib, you can include that if you want to build the sample program yourself
remember to set your project so it can find the Dependencies' 'include' and 'lib' folders

this is for Visual Studios 2010, you would need a version of libtheoraplayer_static.lib that is compiled on 2008 or what have you compiler to work, (Hate that a lib compiled on 2008 doesn't work in 2010, and vise versa,  crazy bull right there.)


shouldn't be any harder than that. Let me know if you have any other issues
Title: SF Video Player
Post by: WitchD0ctor on September 26, 2010, 08:23:36 am
Updated it to include vs2008 project
Title: SF Video Player
Post by: HAWXthy on September 28, 2010, 08:57:54 am
I think the problem is that it doesn´t work with vs2008. The other one is that I can´t compile my SFML1.6 to the vs2010 version :(
Title: SF Video Player
Post by: WitchD0ctor on September 29, 2010, 12:23:28 am
Did you try the newer version? It has a vs2008 project
Title: SF Video Player
Post by: birk.d on September 29, 2010, 05:37:46 pm
hey i tried this out and it works great!
some ideas:

- could you include binaries for the debug version of theoraplayer/libtheora/openal... as well? i dont have the nerves to download all the sources via my super-slow internet connection(germany sucks...)
- it'ld be great to have acces to the sf::image of the current frame (for creating color masks)
- maybe put the code into sort of a "library" so one doesnt need to include the headers and src-files to their project


anyway, cool work! will use it the next time i need to play video files
Title: SF Video Player
Post by: HAWXthy on October 01, 2010, 10:57:35 pm
Oh, now I know why it doesn´t work^^.
I tried to compile it with the debug version.

@birk.d I have very slow german internet too :(
Title: SF Video Player
Post by: WitchD0ctor on October 05, 2010, 02:39:44 am
Cool,
I'll definitely consider putting it in a library, that way you can just include that, instead of worrying about the dependencies,

I'll see about the image thing, might not work as expected though,
Title: SF Video Player
Post by: zorexx on October 15, 2010, 05:50:18 am
Hi, few days ago I was looking into how to play videos for my game's cutscenes. I found this thread, leading me to libtheoraplayer. I tried to use the OpenAL_AudioInterface but it didn't really work well for me, maybe cause I'm using the dll version for SFML. Hence I built a video playback class and Audio Interface for SFML again from scratch. Writing the Audio Interface for SFML is actually quite simple(at least simpler than I thought it would be). The zip file contains the project file for the example, the source and include files are included as well(all released under the zlib license), read the readme.txt file.

If you're using sfml 1.6, there's a bug with the SoundStream, it's fixed in sfml2, but not in sfml 1.6. I found what the fix was in svn(for sfml2) and fixed it for the sfml 1.6. The fixed libs and source codes are included along in the zip file.

Enjoy.

SFMLTheora.zip (http://www.megaupload.com/?d=HLKIEAMP)
Title: SF Video Player
Post by: roosterkin123 on October 20, 2010, 02:27:36 am
Hi, thanks zorexx for the sfmltheora.
I need help with something
I managed to play ogg files but only the audio is played
after some debugging it turns out its dropped frames
any idea on what to do?
mNumDroppedFrames keeps on incrementing each frame
Title: SF Video Player
Post by: zorexx on October 20, 2010, 09:38:26 am
In the Update(float deltaTime) function, did you use seconds or milliseconds for the delta time? If you're using milliseconds(GetTickCount()?) then you have to divide it by 1000. renderWnd->GetFrameTime() is in seconds so if you're using GetFrameTime(), make sure you don't multiply it by 1000 (to convert it to milliseconds for other uses).
The deltaTime or time_increase accepts the time from last frame to the current frame in seconds.
Title: SF Video Player
Post by: roosterkin123 on October 20, 2010, 06:49:03 pm
I am using GetFrameTime() and not multiplying it by 1000. In fact I am using the example thats provided in the sfmltheora library (main function).

I am using sfml2 btw, any differences in that?

I know that I had an error with not being able to instantiate an abstract class and had to add void OnSeek(float timeOffset){} to class SFMLTheora::AudioInterface :
  public TheoraAudioInterface, TheoraTimer, sf::SoundStream

Because of the fact that there was one more pure virtual function with sfml2.
Title: SF Video Player
Post by: zorexx on October 21, 2010, 03:35:44 am
Try this, instead of void OnSeek(float timeOffset) {}
use:

Code: [Select]
void OnSeek(float timeOffset)
{
  seek(timeOffset);
}
Title: SF Video Player
Post by: roosterkin123 on October 21, 2010, 03:27:53 pm
Now it is not dropping frames :) , but still not displaying any images on the screen.

Do you know if there needs to be some updating to the code since I am using sfml2?

Edit: I did video->GetImage()->SaveToFile("testing.bmp"); halfway through the video and it saved a gorgeous image to the hardrive. I know it works now just not being drawn correctly in my app! help :(
Title: SF Video Player
Post by: zorexx on October 21, 2010, 04:32:18 pm
try this, in the function SFMLTheora::Video::Update from Video.cpp:

replace
Code: [Select]
SetImage(currentFrame_);

with

Code: [Select]
SetImage(currentFrame_, true);
Title: SF Video Player
Post by: roosterkin123 on October 21, 2010, 04:36:53 pm
I actually already tried doing that, spent like half a day trying to fix this.
Still doesnt display any image on the screen. The screen actually goes black instead of showing images.
Title: SF Video Player
Post by: roosterkin123 on October 21, 2010, 05:05:25 pm
Ok I managed to get things to render on screen!  :P

I realised that I had

glEnable(GL_DEPTH_TEST);
glDepthMask(GL_TRUE);
glEnable(GL_BLEND);

somewhere way back in the beggining of my app and that causes things to mess up.

Now I have 2 more problems :(

-Audio sync issues
-How to stretch video to go fullscreen?
video->Resize(ClientWidth, ClientHeight); doesnt work
Title: SF Video Player
Post by: zorexx on October 21, 2010, 05:16:47 pm
For fullscreen, you have to call resize after Update.

What's wrong with the audio sync? Can you explain in detail?
Title: SF Video Player
Post by: roosterkin123 on October 21, 2010, 05:24:46 pm
You are amazing! I put resize after update and it works now! and has no audio sync issues. Before the audio was delayed a second behind the picture.

Amazing library saved me so much time
Title: SF Video Player
Post by: zorexx on October 21, 2010, 05:41:15 pm
Haha, I didn't expect the audio sync to be fixed by that though, I don't use sfml2 so I can't test it out, thanks for using it and helping others to get it to work on sfml2 as well, glad you like it. I'll upload the fixed SFMLTheora that works with sfml2(just added the OnSeek function).

http://www.megaupload.com/?d=HLKIEAMP