Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: SF Video Player  (Read 17310 times)

0 Members and 1 Guest are viewing this topic.

WitchD0ctor

  • Full Member
  • ***
  • Posts: 100
    • View Profile
    • http://www.teleforce-blogspot.com
SF Video Player
« 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.





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.
John Carmack can Divide by zer0.

TheMagician

  • Newbie
  • *
  • Posts: 7
    • View Profile
SF Video Player
« Reply #1 on: September 08, 2010, 03:25:44 pm »
You should also post this to the wiki! http://www.sfml-dev.org/wiki/en/sources

WitchD0ctor

  • Full Member
  • ***
  • Posts: 100
    • View Profile
    • http://www.teleforce-blogspot.com
SF Video Player
« Reply #2 on: September 10, 2010, 06:37:19 pm »
don't really know how :o
John Carmack can Divide by zer0.

HAWXthy

  • Newbie
  • *
  • Posts: 3
    • View Profile
SF Video Player
« Reply #3 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?^^

WitchD0ctor

  • Full Member
  • ***
  • Posts: 100
    • View Profile
    • http://www.teleforce-blogspot.com
SF Video Player
« Reply #4 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
John Carmack can Divide by zer0.

WitchD0ctor

  • Full Member
  • ***
  • Posts: 100
    • View Profile
    • http://www.teleforce-blogspot.com
SF Video Player
« Reply #5 on: September 26, 2010, 08:23:36 am »
Updated it to include vs2008 project
John Carmack can Divide by zer0.

HAWXthy

  • Newbie
  • *
  • Posts: 3
    • View Profile
SF Video Player
« Reply #6 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 :(

WitchD0ctor

  • Full Member
  • ***
  • Posts: 100
    • View Profile
    • http://www.teleforce-blogspot.com
SF Video Player
« Reply #7 on: September 29, 2010, 12:23:28 am »
Did you try the newer version? It has a vs2008 project
John Carmack can Divide by zer0.

birk.d

  • Newbie
  • *
  • Posts: 1
    • View Profile
SF Video Player
« Reply #8 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

HAWXthy

  • Newbie
  • *
  • Posts: 3
    • View Profile
SF Video Player
« Reply #9 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 :(

WitchD0ctor

  • Full Member
  • ***
  • Posts: 100
    • View Profile
    • http://www.teleforce-blogspot.com
SF Video Player
« Reply #10 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,
John Carmack can Divide by zer0.

zorexx

  • Full Member
  • ***
  • Posts: 109
    • View Profile
    • zorexx@site
SF Video Player
« Reply #11 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

roosterkin123

  • Newbie
  • *
  • Posts: 43
    • MSN Messenger - rogerboy@hotmail.co.uk
    • View Profile
SF Video Player
« Reply #12 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

zorexx

  • Full Member
  • ***
  • Posts: 109
    • View Profile
    • zorexx@site
SF Video Player
« Reply #13 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.

roosterkin123

  • Newbie
  • *
  • Posts: 43
    • MSN Messenger - rogerboy@hotmail.co.uk
    • View Profile
SF Video Player
« Reply #14 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.

 

anything