Ogre-FFmpeg-Videoplayer 1.0 released

A place for users of OGRE to discuss ideas and experiences of utilitising OGRE in their games / demos / applications.
scrawl
OGRE Expert User
OGRE Expert User
Posts: 1119
Joined: Sat Jan 01, 2011 7:57 pm
x 217

Ogre-FFmpeg-Videoplayer 1.0 released

Post by scrawl »

Hi guys,

you might remember the basic ffmpeg video player that I did two years ago. Thanks to a sponsor, I finally got around to updating it. A massive amount of fixes, general improvements and new features have been added. I will not bother listing a changelog, because it would be way too huge. Instead, take a look at the full list of features below!

The repository is at: https://github.com/scrawl/ogre-ffmpeg-videoplayer. Pull requests are welcome!

Special thanks to Chris Robinson (of OpenAL Soft fame!) for his help.

License change:

Due to popular demand, the video player is now licensed under the MIT license (same as Ogre itself).

Features:

- Uses Ogre's resource system to open the video file, so it could be coming from an archive, or a network resource, etc.
- Writes the video to an Ogre texture, which can be used however you want (on an overlay, or somewhere in the scene, etc)
- Complete A/V sync solution.
- Multithreaded decoding.
- Basic playback control support: play/pause, seeking.
- Works with a variety of FFmpeg versions, including the Libav fork.
- Audio resampling support (using ffmpeg's swresample / libav's avresample library): can convert audio to the user's desired sample rate, sample format and channel layout.
- No audio library dependency. Audio is handled by a MovieAudioFactory, which can be implemented by the user. If no MovieAudioFactory is given, videos are played without sound. An example MovieAudioFactory using SDL_audio is included in the demo.
- Fun fact: Also works with audio-only files, so you can use it as a streaming audio player, if you want.

Dependencies

Video player engine dependencies:

- FFmpeg
- Ogre 1.9+
- boost_thread

Dependencies for the demo:

- SDL2 for audio output
- OIS for keyboard controls

Building

The demo can be built the usual cmake way:

Code: Select all

mkdir build
cd build
cmake ..
make
Running

Place your video files in the build folder, then run the demo using a filename as argument:

./ogre-ffmpeg-videoplayer-demo big_buck_bunny.avi

Demo playback controls:
- Space: Play/Pause
- Left/Right: Seek by 5 seconds.
- Down/Up: Seek by 30 seconds.
TheSHEEEP
OGRE Retired Team Member
OGRE Retired Team Member
Posts: 972
Joined: Mon Jun 02, 2008 6:52 pm
Location: Berlin
x 65

Re: Ogre-FFmpeg-Videoplayer 1.0 released

Post by TheSHEEEP »

Hah, I remember the times when there were no usable video players at all available for Ogre.
That certainly changed ;)
My site! - Have a look :)
Also on Twitter - extra fluffy
User avatar
Kojack
OGRE Moderator
OGRE Moderator
Posts: 7157
Joined: Sun Jan 25, 2004 7:35 am
Location: Brisbane, Australia
x 535

Re: Ogre-FFmpeg-Videoplayer 1.0 released

Post by Kojack »

Cool, just got it working in my framework with very little effort. I'm about to start on a simple game that needs video support, this looks good.

(Although I need to do a build of ffmpeg myself, the windows binaries on the net are GPL, I want only the LGPL part)
scrawl
OGRE Expert User
OGRE Expert User
Posts: 1119
Joined: Sat Jan 01, 2011 7:57 pm
x 217

Re: Ogre-FFmpeg-Videoplayer 1.0 released

Post by scrawl »

Thanks Kojack! Your praise means a lot :)
User avatar
lonewolff
Ogre Magi
Posts: 1207
Joined: Wed Dec 28, 2005 12:58 am
x 6

Re: Ogre-FFmpeg-Videoplayer 1.0 released

Post by lonewolff »

Nice job, will check this out when I get a chance 8)

What sort of frame rate do you get for an average video (for example 720 x 405)?

I managed to make a video player for game maker studio (the first and only one in existence), I tried to multithread it to see if I could boost performance as large video dimensions cap out a single channel on the GPU bus, but turns out that GM:S is not thread safe.

Still it is good fun pushing the limits of an engine. :D
frostbyte
Orc Shaman
Posts: 737
Joined: Fri May 31, 2013 2:28 am
x 65

Re: Ogre-FFmpeg-Videoplayer 1.0 released

Post by frostbyte »

hi, this is my nightly build experience - if you are interested...
status: failed( success in building, crush on running )
os: windows xp - x86
ide: visual studio 2010
ffmpeg: binaries downloaded from here http://ffmpeg.zeranoe.com/
added msinttypes from here https://code.google.com/p/msinttypes/

first problem - the cmake part is not very clear( which fields belongs to libav and which belongs to ffmpeg? ) any way i managed to build a vs project

then i defined HAVE_SWRESAMPLE...
had problems with VS accessing wrong <time.h> ( one is in ms headers and one in ffmpeg ), so i fixed the conflict by defining a full path
then for some strange reason compiler complained about "unresolved external symbol av_gettime(void)"
fixed the problem by creating:
fftimer.h with method bv_gettime()
fftimer.cpp implementing bv_gettime() {return av_gettime(); } with all ffmpeg headers in "extern "c"{...}"
replaced all references to av_gettime() with bv_gettime()

now all was build ok...

try running...weird crush( unsolved ) so i located the problem using primative logging...( i just don't like debugging )
the second videoState is created- program just crush- even when i change its constructor to be empty( no parameter init and no method calls )
if i remove videoState creating line - program will continue its flow....
so for now i'm giving up( have no clue - what's the problem )...hope this info will help somehow...
btw: did you try/manage to build this with visual studio?
anyway thanks i'll probably just scavenge some code from my dead-ms-build...
the woods are lovely dark and deep
but i have promises to keep
and miles to code before i sleep
and miles to code before i sleep..

coolest videos link( two minutes paper )...
https://www.youtube.com/user/keeroyz/videos
scrawl
OGRE Expert User
OGRE Expert User
Posts: 1119
Joined: Sat Jan 01, 2011 7:57 pm
x 217

Re: Ogre-FFmpeg-Videoplayer 1.0 released

Post by scrawl »

btw: did you try/manage to build this with visual studio?
Yes, all this code is used in production in OpenMW, which is built by various developers on VS and has a nightly Windows build as well.
first problem - the cmake part is not very clear( which fields belongs to libav and which belongs to ffmpeg? ) any way i managed to build a vs project
The only differences are that ffmpeg has "libswresample" and libav has the "libavresample" equivalent, which are API incompatible. All the other libraries are interchangeable, e.g. libavcodec looks the same to the video player whether you are using ffmpeg or libav.
then i defined HAVE_SWRESAMPLE...
Do not do this! The cmake script should take care of doing this if necessary. If you've bypassed CMake, then I can not help you.
frostbyte
Orc Shaman
Posts: 737
Joined: Fri May 31, 2013 2:28 am
x 65

Re: Ogre-FFmpeg-Videoplayer 1.0 released

Post by frostbyte »

thanks for your answer...
i guess i did somthing wrong with cmake...
now that i know its been done before i'm going to try again( your code looks so good, i realy dont want to give up on it... )
thanks again... :D
the woods are lovely dark and deep
but i have promises to keep
and miles to code before i sleep
and miles to code before i sleep..

coolest videos link( two minutes paper )...
https://www.youtube.com/user/keeroyz/videos
User avatar
lonewolff
Ogre Magi
Posts: 1207
Joined: Wed Dec 28, 2005 12:58 am
x 6

Re: Ogre-FFmpeg-Videoplayer 1.0 released

Post by lonewolff »

Still wondering what the framerate is like with this under Ogre :)
frostbyte
Orc Shaman
Posts: 737
Joined: Fri May 31, 2013 2:28 am
x 65

Re: Ogre-FFmpeg-Videoplayer 1.0 released

Post by frostbyte »

Still wondering what the framerate is like with this under Ogre
guess you'll have to check youself, or in ffmpeg related forum - there is no difference in frame rate - with/without ogre...
and any way it realy depends on container /format / codec / quality / cpu you are using...
it is common practice to encode video targeting a specific hardware and sacrifice some quality so frame-rate/cpu load requirments will be furfilled... so i woul'dnt worry about that...

Edit: you can use ffplay command-line app( comes with ffmpeg ) - it will show you all kind of statistics...
Last edited by frostbyte on Mon Nov 10, 2014 8:23 pm, edited 2 times in total.
the woods are lovely dark and deep
but i have promises to keep
and miles to code before i sleep
and miles to code before i sleep..

coolest videos link( two minutes paper )...
https://www.youtube.com/user/keeroyz/videos
User avatar
c6burns
Beholder
Posts: 1512
Joined: Fri Feb 22, 2013 4:44 am
Location: Deep behind enemy lines
x 139

Re: Ogre-FFmpeg-Videoplayer 1.0 released

Post by c6burns »

It doesn't even really depend on which codecs you use, because decode and yuv to rgb and scaling is done in a background thread. All the render thread is doing is blitFromMemory into a texture. I've only take a quick look through this plugin, but I have a lot of experience with ffmpeg and associated libs. This is quite nicely done!
frostbyte
Orc Shaman
Posts: 737
Joined: Fri May 31, 2013 2:28 am
x 65

Re: Ogre-FFmpeg-Videoplayer 1.0 released

Post by frostbyte »

got it working on visual-studio....yeah... best ffmpeg plugin up to date.... :)
it was a nightly-mare - guess karma hit me back...http://www.ogre3d.org/forums/viewtopic.php?f=16&t=81984 )
any way the solution was
the linker optimization option to be set to "References: Keep Unreferenced Data (/OPT:NOREF)"
as i found at the buttom of this thread http://stackoverflow.com/questions/1184 ... on-windows
thanks man - worked like a charm... :D
the woods are lovely dark and deep
but i have promises to keep
and miles to code before i sleep
and miles to code before i sleep..

coolest videos link( two minutes paper )...
https://www.youtube.com/user/keeroyz/videos
scrawl
OGRE Expert User
OGRE Expert User
Posts: 1119
Joined: Sat Jan 01, 2011 7:57 pm
x 217

Re: Ogre-FFmpeg-Videoplayer 1.0 released

Post by scrawl »

Glad you got it working and thanks for posting the solution!
jorgose
Gnoblar
Posts: 4
Joined: Mon Nov 24, 2014 4:58 pm

Re: Ogre-FFmpeg-Videoplayer 1.0 released

Post by jorgose »

Hi,

thanks for the plugin, I'd like to build ffmpeg using to VS2012 compiler in order to use the plugin with the rest of my projects, what do I need to build? static or dynamic libs or just the exe?
Thanks again!
Last edited by jorgose on Mon Nov 24, 2014 5:57 pm, edited 1 time in total.
User avatar
c6burns
Beholder
Posts: 1512
Joined: Fri Feb 22, 2013 4:44 am
Location: Deep behind enemy lines
x 139

Re: Ogre-FFmpeg-Videoplayer 1.0 released

Post by c6burns »

The example looks like a console app based on the tutorial framework that plays whatever filename you pass in as an argument. Do a cursory look through the code in the demo folder and you will see.
jorgose
Gnoblar
Posts: 4
Joined: Mon Nov 24, 2014 4:58 pm

Re: Ogre-FFmpeg-Videoplayer 1.0 released

Post by jorgose »

yes, sorry, I was stupidly looking at the code of the other fffmpeg video player from the sheep wich I also downloaded. :oops:
frostbyte
Orc Shaman
Posts: 737
Joined: Fri May 31, 2013 2:28 am
x 65

Re: Ogre-FFmpeg-Videoplayer 1.0 released

Post by frostbyte »

have a look at my posts above in regards to building with VS - might save you some pain... :wink:
the woods are lovely dark and deep
but i have promises to keep
and miles to code before i sleep
and miles to code before i sleep..

coolest videos link( two minutes paper )...
https://www.youtube.com/user/keeroyz/videos
jorgose
Gnoblar
Posts: 4
Joined: Mon Nov 24, 2014 4:58 pm

Re: Ogre-FFmpeg-Videoplayer 1.0 released

Post by jorgose »

thanks for the tip, fortunately there seems to be some guides on the web on how to build and link ffmpeg this way. For example the pr.exe binary has to be manually copied in mingw since it isn't part of the ditribution anymore but is required during config.
jorgose
Gnoblar
Posts: 4
Joined: Mon Nov 24, 2014 4:58 pm

Re: Ogre-FFmpeg-Videoplayer 1.0 released

Post by jorgose »

well, after some suffering I got it to work in visual studio 64 bit. I had some issues linking ffmpeg so In case it helps someone this is what worked for me:
- get ffmpeg from Zeranoe's builds (google it)
- Zeranoe's libs are compiled with gcc using mingw so you need to convert the libs with VS lib utility in order to use them in VS. Using visual studio's dev console of you have to do something like:

Code: Select all

lib /machine:x64 /def:avcodec-54.def   /out:pathToStore/avcodec-54.lib
- as mentioned before by frostbyte, linker optimization set to /OPT:NOREF
- set the VS project include paths, library paths and lib names
- add the following in libavutil/common.h

Code: Select all

#ifndef INT64_C
	#define INT64_C(c) (c ## LL)
	#define UINT64_C(c) (c ## ULL)
#endif
the plugin is worth the effort ;)
User avatar
Zeal
Ogre Magi
Posts: 1260
Joined: Mon Aug 07, 2006 6:16 am
Location: Colorado Springs, CO USA

Re: Ogre-FFmpeg-Videoplayer 1.0 released

Post by Zeal »

Does this support 3d/and or 360 video files?

Also, would it be possible to get it to run on android/ios?
User avatar
c6burns
Beholder
Posts: 1512
Joined: Fri Feb 22, 2013 4:44 am
Location: Deep behind enemy lines
x 139

Re: Ogre-FFmpeg-Videoplayer 1.0 released

Post by c6burns »

It supports anything that ffmpeg supports (via libavformat), though you should be aware that most video codecs are patented technology and not royalty free. Yes it works on mobile.
User avatar
Zeal
Ogre Magi
Posts: 1260
Joined: Mon Aug 07, 2006 6:16 am
Location: Colorado Springs, CO USA

Re: Ogre-FFmpeg-Videoplayer 1.0 released

Post by Zeal »

Can anyone point me towards some material on 360/3d videos? Would they be loaded the same way as a normal video (into a single ogre texture)?

*I am assuming 3d video would just be one ogre texture per frame, each eye side by side. And 360 video would also be one ogre texture per frame, just needing to be mapped to a sphere mesh? Or am I way off...
User avatar
c6burns
Beholder
Posts: 1512
Joined: Fri Feb 22, 2013 4:44 am
Location: Deep behind enemy lines
x 139

Re: Ogre-FFmpeg-Videoplayer 1.0 released

Post by c6burns »

Oh I assumed you knew the first thing about 3d content, but apparently not. I don't either :D

I doubt you can use any modern techniques without display support (and by modern I mean post 1950s :lol:). AFAIK movie theatre type content uses light polarization and passive glasses with polarizing filters. I don't see how this could work without a special display or projection screen. nvidia 3dvision uses some other method completely, which has special active glasses which sync with the display. The nintendo 3ds uses autostereoscopy and requires a special display. And then there is the oldschool red/blue passive glasses which should work on any display, since my understanding is it just uses color to control what goes in each eye. I assume the latter is what you will be using, but I don't know. I've seen some weird ass enclosures where it turns your mobile phone into an oculus type headset, which obviously just controls what goes into each eye by blocking 1/2 the screen from the other eye.
User avatar
Zeal
Ogre Magi
Posts: 1260
Joined: Mon Aug 07, 2006 6:16 am
Location: Colorado Springs, CO USA

Re: Ogre-FFmpeg-Videoplayer 1.0 released

Post by Zeal »

Home (tv/computer) 3d doesn't use polarized light, there is one frame for each eye, which alternates (via active shutter glasses).

So the question is, when I import a 3d video texture into Ogre, am I going to see one texture with both left/right frames side by side? Or is there some funky format that 3d movies use. And still same question for 360, I assume it will be just one giant warped texture per frame, then its our job to map it to a sphere mesh?
User avatar
c6burns
Beholder
Posts: 1512
Joined: Fri Feb 22, 2013 4:44 am
Location: Deep behind enemy lines
x 139

Re: Ogre-FFmpeg-Videoplayer 1.0 released

Post by c6burns »

Good questions. You should research the answers to these before trying to render the videos

PS - My guess for active shutter content would be a frame sequential format. Isn't that the format for bluray dvd? You should investigate your content and see