Ogre Video Plugin (using FFmpeg)

A place for users of OGRE to discuss ideas and experiences of utilitising OGRE in their games / demos / applications.
TheSHEEEP
OGRE Retired Team Member
OGRE Retired Team Member
Posts: 972
Joined: Mon Jun 02, 2008 6:52 pm
Location: Berlin
x 65

Ogre Video Plugin (using FFmpeg)

Post by TheSHEEEP »

So, another video player when there already is a (quite good!) one by scrawl?
Yup.

There is nothing inherently wrong with scrawl's video player, but for our project we could not use it for a number of reasons (one being that we don't use SDL for audio).
So I decided to have a shot at my own video player.

And now it is done:
[youtube]1C8I5Ae032g[/youtube]

Dependencies:
  • FFmpeg
  • boost
  • Ogre
Download (and readme):
GitHub!

Features:
  • (Only for those that know FFmpeg) Not based on the outdated and barely readable dranger tutorials!
  • Play a video on any texture unit in your scene -> allows video input in your normal shader pipeline!
  • No audio dependency.
  • Easy to use. Just load the plugin and use the player.
Not featured:
  • Audio playback - the player decodes audio and can give you the frames, but what you do with them is up to you (there is an example in the repo using OpenAL)
So, have fun with it!

We are using the player in our own project, so I might update it when we implement new features. But I will not really maintain this repo on a weekly basis.
If someone wants to improve the player on his own, feel free to tell me, I'd be very happy! Or just fork the repo ;)
My site! - Have a look :)
Also on Twitter - extra fluffy
User avatar
c6burns
Beholder
Posts: 1512
Joined: Fri Feb 22, 2013 4:44 am
Location: Deep behind enemy lines
x 138

Re: Ogre Video Plugin (using FFmpeg)

Post by c6burns »

Coooool, I like it. I have a few updates I'll push back to you later today when I get a moment to fork and do it properly ... just tiny bugfixy stuff so far. Ooo and it requires an audio stream in the file ... I might fix that or just keep it in my local if you aren't interested.

Anyway thanks!
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 Video Plugin (using FFmpeg)

Post by TheSHEEEP »

Ah, yeah, I never tested video files without audio :D

Thanks for the fixes.
My site! - Have a look :)
Also on Twitter - extra fluffy
User avatar
c6burns
Beholder
Posts: 1512
Joined: Fri Feb 22, 2013 4:44 am
Location: Deep behind enemy lines
x 138

Re: Ogre Video Plugin (using FFmpeg)

Post by c6burns »

Oh no problem, thanks for the plugin! It's exactly what I needed :lol: I am terminally lazy and deadline driven so I didn't feel like reworking scrawl's project for my needs. I've been using sequenced image videos and updating a texture unit at a given framerate. But once your artists know you have video support, they will find 900 reasons to play video in 900 different places, so size-on-disk was becoming an issue.

I held back some CMake stuff cuz it's probably specific to my env, like /EHsc not getting set (even though I see it in cflags) and boost options for nonstatic runtime and so on. I'll prob fix the no audio stream issue later. Integrating audio into my pipeline now! :D

Thanks again!!!
User avatar
c6burns
Beholder
Posts: 1512
Joined: Fri Feb 22, 2013 4:44 am
Location: Deep behind enemy lines
x 138

Re: Ogre Video Plugin (using FFmpeg)

Post by c6burns »

At first I thought your audio interface was strange, but I see it makes perfect sense for how you use it. All I needed was a selector so I could work with s16 fmt audio samples, so I made an enum in the video player just to keep from including anything from avcodec outside of the decoder threads. You had a nice separation going there and I'd hate to wreck it. It should default to working exactly how you use it, so nothing should break.

Anyway, feel free to accept or reject ... it won't hurt my feelings. I integrated to cricket audio library very easily :)
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 Video Plugin (using FFmpeg)

Post by TheSHEEEP »

Yeah, it is definitely strange when you first see it.It came from OpenAL sound sources having multiple buffers when streaming (well, you can and should give it multiple buffers). So I thought I'd just make the function fill multiple buffers at once. It has a slight overhead with the vectors and the buffer partitioning, but it seems worth it so far :)
My site! - Have a look :)
Also on Twitter - extra fluffy
User avatar
fixtone
Gnoblar
Posts: 19
Joined: Tue Jan 24, 2012 1:32 pm
Location: Barcelona
x 2

Re: Ogre Video Plugin (using FFmpeg)

Post by fixtone »

Hello, Congratulations, you've done a great job with Ogre Video Plugin.
I have a problem when setting up the project with cmake.

It shows me the following error:
CMake Error at C:/Program Files (x86)/CMake 2.8/share/cmake-2.8/Modules/FindBoost.cmake:1200 (message):
Unable to find the requested Boost libraries.

Boost version: 1.55.0

Boost include path: C:/OgreSDK_vc10_v1-9-0/boost

The following Boost libraries could not be found:

boost_date_time
boost_thread
boost_system
boost_chrono

No Boost libraries were found. You may need to set BOOST_LIBRARYDIR to the
directory containing Boost libraries or BOOST_ROOT to the location of
Boost.
Call Stack (most recent call first):
CMakeLists.txt:57 (find_package)
And this is my configuration:

Image

Thanks in advance :D
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 Video Plugin (using FFmpeg)

Post by TheSHEEEP »

I think you need to build boost yourself and not use the one from Ogre.
The plugin is set to ask for multi-threaded, static boost libs only:

Code: Select all

set(Boost_USE_STATIC_LIBS ON)
set(Boost_USE_MULTITHREADED ON)
set(Boost_USE_STATIC_RUNTIME ON)
I'm not sure if the prebuilt SDKs come with that.
Another possibility would be to remove those Boost_Use... settings from the CMakeLists.txt.
My site! - Have a look :)
Also on Twitter - extra fluffy
User avatar
fixtone
Gnoblar
Posts: 19
Joined: Tue Jan 24, 2012 1:32 pm
Location: Barcelona
x 2

Re: Ogre Video Plugin (using FFmpeg)

Post by fixtone »

Thank you very much for your help.
The solution has been to compile boost 1.55 and everything worked well!

Thanks TheSHEEEP! :D
dudeabot
Gnome
Posts: 334
Joined: Thu Jun 28, 2007 2:12 pm
Location: Brazil
x 5
Contact:

Re: Ogre Video Plugin (using FFmpeg)

Post by dudeabot »

hi nice project!

i keep getting this error though :(
"Could not find stream of type: audio"
User avatar
c6burns
Beholder
Posts: 1512
Joined: Fri Feb 22, 2013 4:44 am
Location: Deep behind enemy lines
x 138

Re: Ogre Video Plugin (using FFmpeg)

Post by c6burns »

Your video file has no audio in it. This is actually discussed above. The library doesn't handle this case yet, but it's pretty easy to implement. Go for it and submit a pull request, or wait for someone else to fix it.
frostbyte
Orc Shaman
Posts: 737
Joined: Fri May 31, 2013 2:28 am
x 65

Re: Ogre Video Plugin (using FFmpeg)

Post by frostbyte »

great work...maybe next evolution for this is just to name a material texture ending with .mpg .ogg .whatever and let ogre do the work...(+:
also it would be a nice performance boost - if ffmpeg will stop decoding when texture is occluded or somthing like that....
on other notes: shoudn't this be on the addons forum topic...?
it seem to me that lots of plugins are mislocated, making it very hard to even know about them...
for example i almost implemented my self a script-catch plugin, when i luckly stumbled upon an amazing existing one in an unrelated topic....
another example is .scene loaders, shiny material system, etc...while its nice to dig in the forum for pearls, i think a well structured forum it will make ogre more friendly for newbees.
is there a reason for this mess? :?:
hope you can forward this issue( not only related to this plugin...) :)
User avatar
c6burns
Beholder
Posts: 1512
Joined: Fri Feb 22, 2013 4:44 am
Location: Deep behind enemy lines
x 138

Re: Ogre Video Plugin (using FFmpeg)

Post by c6burns »

frostbyte wrote:i think a well structured forum it will make ogre more friendly for newbees.
is there a reason for this mess? :?:
There's nothing stopping anyone who thinks this from updating the wiki with new information. I look forward to seeing what you can do to make things better :D
frostbyte
Orc Shaman
Posts: 737
Joined: Fri May 31, 2013 2:28 am
x 65

Re: Ogre Video Plugin (using FFmpeg)

Post by frostbyte »

well, dont hold your breath.... :oops:
i rather contribute in doing code work 8) -and right now i have little spare-time/patience/energy to learn and mess aroung with tiki-wiki....
i was just trying to understand why can't a person add his plugin to the so much out-dated addon forum....
after digging around i found that it has somthing to do with spammers, and that theSHEEP has already tackled this problem...
anyway - if i have some spare-time i'll try doing that...( gather all those lost plugins into one cosy wiki-page... )
sorry for spamming this thread with unrelated issues - so i'll stop now... :mrgreen:
Jrel
Gnoblar
Posts: 1
Joined: Sun Mar 23, 2014 10:21 pm

Re: Ogre Video Plugin (using FFmpeg)

Post by Jrel »

First of all thank you, thank you for writing a new video plugin, my initial search was dumbfounded by absolutely old some of the plugins and even worse, the documentation was.

Sadly I must end up asking for help on this, as I'm completely stumped as to what the issue might be, I think it may have to do with ffmpeg itself, but I hope it's some simple mistake I made along the way. After creating the plugin and library I got everything up and running, unfortunately the system will always crash with an access violation on playing/decoding but only if I have previously set a video name.

Code: Select all

FFMPEG_PLAYER->setMaterialName("VideoMaterial");
	  FFMPEG_PLAYER->setTextureUnitName("VideoTexture");
	  FFMPEG_PLAYER->setBufferTarget(3.0);
	  FFMPEG_PLAYER->setVideoFilename("room.mp4");
Will always crash on playing/decoding but if I were to comment out the setVideoFilename line the program would launch but, obviously nothing would happen. I've tried several different videos/file types and they all end up like this, which leads me to suspect it may be ffmpeg itself. Hopefully not, but there it is. Specifically I get unhandled exception at 0x778215de 0xC0000005 Access violation. The only similar issue with ffmpeg I've been able to find previously is here: http://ffmpeg-users.933282.n4.nabble.co ... 02937.html

Thank you very much for this plugin in general, and thank you to anyone willing to help me find the solution to my problem.


EDIT: After sanity checking the DLL itself it seems to be crashing on _playerCondVar->wait_until(lock, timeOut); inside startDecoding(); However I've confirmed both -playercondVar and lock are not NULL, so I'm still astoundingly confused.

-Jrel
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 Video Plugin (using FFmpeg)

Post by TheSHEEEP »

It doesn't seem to be a deadlock, at least. Afaik, deadlocks don't crash.

First of all, is there anything in the log files?

How big is your video?

Depending on that, 3 seconds of buffer target may be pretty heavy on the memory, as the plugin stores the decoded frames. It is possible that your program simply runs out of memory.
You have to look at it like that:
Memory consumption (at least!) = buffer_seconds * fps * single_frame_size

Now if buffer_seconds is 3, your video has 30 fps and its size is 1280x720, this would be:
3 * 30 * (1280*720*4) = 331776000 bytes = 316MB
And this is video only, so you'll have to add some MB for audio, too. Half a second will also be copied if looping is enabled (to be able to start looping faster).

Also, keep in mind that it will likely store more than 3 seconds of either audio or video.
The plugin will decode until it has filled both audio and video buffers, so if the plugin has decoded 3 seconds of video, but only 2 seconds of audio, it will keep on decoding and storing both until both buffers have at least 3 seconds. This will become ridiculously big if your video does not store its frames interleaved (alternating audio and video frames), but planer (first all audio, then all video frames - or even worse, the other way around).

So, to see if that is your problem, turn down the buffer size to only 1 second (in practice, even half a second should be enough in most cases).

You can use ffprobe to analyze your video ( "ffprobe -i yourvideo.mp4 -show_streams", add "-show_packets" to see if the packets are interleaved ), to see how it stores its data.
The plugin is not made to handle erroneous video files, so if your video files are broken somehow (many video files you find online are broken), this might also lead to a crash.
My site! - Have a look :)
Also on Twitter - extra fluffy
nickG
Greenskin
Posts: 122
Joined: Fri Jan 20, 2012 6:44 pm
Location: Russia,Moscow
x 1

Re: Ogre Video Plugin (using FFmpeg)

Post by nickG »

subscribed
doup
Gnoblar
Posts: 3
Joined: Thu Aug 07, 2014 10:02 am

Re: Ogre Video Plugin (using FFmpeg)

Post by doup »

I use this plugin and It works fine. It's great job, but I have a problem with audio (OPENAL). The audio works fine in OSX but same code is bad in Windows. I used the example videosoundsource code.

Can somebody help me what the problem is?

Video has sound in windows but it is noise in the background and slow.

The streamingFormat = AL_FORMAT_STEREO16 in Windows
The streamingFormat = AL_FORMAT_STEREO_FLOAT32 in OSX
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 Video Plugin (using FFmpeg)

Post by TheSHEEEP »

This is weird.
But I must say I have little to none experience in OSX development, so I don't know if there are any typical pitfalls like that.

What I would try is using AL_FORMAT_STEREO_FLOAT32 also on Windows (and generally play around with these settings on Windows until it works). Why did you change it to begin with?

I assume you use exactly the same video files and versions of OpanAL on both platforms.
My site! - Have a look :)
Also on Twitter - extra fluffy
User avatar
rakeshj
Gnoblar
Posts: 24
Joined: Tue Mar 17, 2009 10:53 am
Location: Benglore - India
x 1

Re: Ogre Video Plugin (using FFmpeg)

Post by rakeshj »

Hi TheSHEEEP,

Really cool....................!
This is exactly what I was looking for. Perfect...!

BTW, I have few questions,

- Does it support more than one video playback ? If yes, how many ?
- Which video formats does it support ?
- Is it free ( also stable ? ) for commercial use.?

Thank you.
rakeshj.
| Lead Graphics Programmer, MPC Film, Technicolor India |
| Game Projects ( Apox, Tryst ) at BlueGiant Interactive |
| Graphics Projects ( Ogre3D based slideshow maker 'picovico : a video maker' ) at Picovico Pvt Ltd. |
| Bengaluru, India |
User avatar
c6burns
Beholder
Posts: 1512
Joined: Fri Feb 22, 2013 4:44 am
Location: Deep behind enemy lines
x 138

Re: Ogre Video Plugin (using FFmpeg)

Post by c6burns »

It should support multiple videos, as FFmpegVideoPlayer is not a true singleton

It supports all the formats of libavformat (pretty much every format), though likely you will wish to choose a non-patented format (eg. *NOT* mpeg4 or h264 and so on)

ffmpeg is licensed under LGPL: https://www.ffmpeg.org/legal.html
OgreVideoPlugin is graciously licensed under MIT
User avatar
fixtone
Gnoblar
Posts: 19
Joined: Tue Jan 24, 2012 1:32 pm
Location: Barcelona
x 2

Re: Ogre Video Plugin (using FFmpeg)

Post by fixtone »

I have a BOOST_INCLUDE_DIR, BOOST_LIBRARYDIR and BOOST_ROOT error when compile Ogre video plugin.

This is the solution :D :
Are you sure you are doing it the correct way? The idea is that CMake sets BOOST_INCLUDE_DIR, BOOST_LIBRARYDIR and BOOST_ROOT automatically. Do something like this in CMakeLists.txt:

FIND_PACKAGE(Boost)
IF (Boost_FOUND)
INCLUDE_DIRECTORIES(${Boost_INCLUDE_DIR})
ADD_DEFINITIONS( "-DHAS_BOOST" )
ENDIF()

if boost is not installed in a default location and can thus not be found by cmake, you can tell cmake where to look for boost like this:

SET(CMAKE_INCLUDE_PATH ${CMAKE_INCLUDE_PATH} "C:/win32libs/boost")
SET(CMAKE_LIBRARY_PATH ${CMAKE_LIBRARY_PATH} "C:/win32libs/boost/lib")

of course those two lines have to be before the FIND_PACKAGE(Boost) in CMakeLists.txt
xrgo
OGRE Expert User
OGRE Expert User
Posts: 1148
Joined: Sat Jul 06, 2013 10:59 pm
Location: Chile
x 168

Re: Ogre Video Plugin (using FFmpeg)

Post by xrgo »

Hi! Thank you so much for this, I have it working with Ogre 2.1.
I just removed material/textureUnits stuffs, added a getTexture() method, and made the texture a 2dArray and its working great
now I have to get sound working

thanks again!!
User avatar
Zeal
Ogre Magi
Posts: 1260
Joined: Mon Aug 07, 2006 6:16 am
Location: Colorado Springs, CO USA

Re: Ogre Video Plugin (using FFmpeg)

Post by Zeal »

Is everyone building ffmpeg from source? Or will one of these pre built packages work...

https://ffmpeg.zeranoe.com/builds/

If so, which one?

Or if we need to build ffmpeg from source, are there any good tutorials out there? I only really have experience with cmake and I didn't see anything for ffmpeg.
User avatar
Zeal
Ogre Magi
Posts: 1260
Joined: Mon Aug 07, 2006 6:16 am
Location: Colorado Springs, CO USA

Re: Ogre Video Plugin (using FFmpeg)

Post by Zeal »

Ok so I downloaded the latest "Dev" package from

https://ffmpeg.zeranoe.com/builds/

It had the headers and libs (no source). Already had boost built, so I ran the cmake, and it worked (after assigning the boost and ogre dirs). Although I got the following messages about plugins (are these needed?).

Code: Select all

Looking for OGRE...
Could NOT find PkgConfig (missing:  PKG_CONFIG_EXECUTABLE) 
Found Ogre Ghadamon (1.9.0)
Found OGRE: C:/SDKs/Ogre/build/lib/Debug/OgreMain_d.lib
Looking for OGRE_Paging...
Could not locate OGRE_Paging
Looking for OGRE_Terrain...
Could not locate OGRE_Terrain
Looking for OGRE_Property...
Could not locate OGRE_Property
Looking for OGRE_RTShaderSystem...
Could not locate OGRE_RTShaderSystem
Looking for OGRE_Volume...
Could not locate OGRE_Volume
Looking for OGRE_Overlay...
Could not locate OGRE_Overlay
Configuring done
Generating done
The sln built ok, so I tried to build and got...

Code: Select all

1>------ Build started: Project: ZERO_CHECK, Configuration: Debug x64 ------
1>  Checking Build System
1>  CMake does not need to re-run because C:/SDKs/OgreVideoPlugin-master/build/CMakeFiles/generate.stamp is up-to-date.
2>------ Build started: Project: OgreVideoPlugin, Configuration: Debug x64 ------
2>  Building Custom Rule C:/SDKs/OgreVideoPlugin-master/CMakeLists.txt
2>  CMake does not need to re-run because C:\SDKs\OgreVideoPlugin-master\build\CMakeFiles\generate.stamp is up-to-date.
2>  FFmpegVideoDecodingThread.cpp
2>C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include\xlocale(341): warning C4530: C++ exception handler used, but unwind semantics are not enabled. Specify /EHsc
2>C:\SDKs\OgreVideoPlugin-master\src\FFmpegVideoDecodingThread.cpp(388): error C2065: 'PIX_FMT_RGBA': undeclared identifier
2>C:\SDKs\OgreVideoPlugin-master\src\FFmpegVideoDecodingThread.cpp(392): error C3861: 'avcodec_alloc_frame': identifier not found
2>C:\SDKs\OgreVideoPlugin-master\src\FFmpegVideoDecodingThread.cpp(393): error C2065: 'PIX_FMT_RGBA': undeclared identifier
2>C:\SDKs\OgreVideoPlugin-master\src\FFmpegVideoDecodingThread.cpp(472): error C3861: 'avcodec_alloc_frame': identifier not found
2>C:\SDKs\OgreVideoPlugin-master\src\FFmpegVideoDecodingThread.cpp(480): error C3861: 'avcodec_get_frame_defaults': identifier not found
2>C:\SDKs\OgreVideoPlugin-master\src\FFmpegVideoDecodingThread.cpp(522): error C3861: 'avcodec_free_frame': identifier not found
2>C:\SDKs\OgreVideoPlugin-master\src\FFmpegVideoDecodingThread.cpp(524): error C3861: 'avcodec_free_frame': identifier not found
2>  FFmpegVideoPlayer.cpp
2>C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include\xlocale(341): warning C4530: C++ exception handler used, but unwind semantics are not enabled. Specify /EHsc
2>C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include\cmath(70): warning C4577: 'noexcept' used with no exception handling mode specified; termination on exception is not guaranteed. Specify /EHsc
2>  FFmpegVideoPlugin.cpp
2>C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include\xlocale(341): warning C4530: C++ exception handler used, but unwind semantics are not enabled. Specify /EHsc
2>C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include\cmath(70): warning C4577: 'noexcept' used with no exception handling mode specified; termination on exception is not guaranteed. Specify /EHsc
2>  FFmpegVideoPluginDLL.cpp
2>C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include\xlocale(341): warning C4530: C++ exception handler used, but unwind semantics are not enabled. Specify /EHsc
2>C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include\cmath(70): warning C4577: 'noexcept' used with no exception handling mode specified; termination on exception is not guaranteed. Specify /EHsc
2>  Generating Code...
3>------ Build started: Project: ALL_BUILD, Configuration: Debug x64 ------
3>  Building Custom Rule C:/SDKs/OgreVideoPlugin-master/CMakeLists.txt
3>  CMake does not need to re-run because C:\SDKs\OgreVideoPlugin-master\build\CMakeFiles\generate.stamp is up-to-date.
4>------ Skipped Build: Project: INSTALL, Configuration: Debug x64 ------
4>Project not selected to build for this solution configuration 
========== Build: 2 succeeded, 1 failed, 0 up-to-date, 1 skipped ==========
So whats the deal with all those "undeclared identifier"s?
Post Reply