(Code Snippet) Video reproduction using DirectShow

Discussion area about developing or extending OGRE, adding plugins for it or building applications on it. No newbie questions please, use the Help forum for that.

Postby hmoraldo » Thu Mar 22, 2007 4:43 am

Loockas wrote:Hey,
I've got the runtime error while trying to run my app. I've used the simplest code from wiki and it compiles fine though there was a problem with missing ddraw.h file but after installing directx sdk all went well. Anyone has encountered that issue with runtime error?


Please post details on the error (error message, stack trace), and the log file, otherwise we can't tell much about the problem.
H. Hernan Moraldo
Personal website
User avatar
hmoraldo
OGRE Expert User
OGRE Expert User
 
Posts: 517
Kudos: 0
Joined: 07 Mar 2006
Location: Buenos Aires, Argentina

Postby futnuh » Thu Mar 22, 2007 8:01 am

Hopefully it isn't considered poor taste to offer a small bounty for what should be a very small amount of work? If it is, I apologize and promise not to do it again. If you aren't offended however, feel free to read http://www.ogre3d.org/phpBB2addons/viewtopic.php?p=22182

The task will take me 2-3 hours tomorrow so the price seems reasonable given that the result benefits the (python) Ogre community. If you're interested, please read the thread carefully - I'll pay only if it passes muster by the python-ogre guys. If I (or they) have to start mucking around with your submission, it defeats the purpose of offering a bounty. If you're going to do it, post a message in the thread - no use a slew of people recreating the proverbial wheel.
futnuh
Goblin
 
Posts: 225
Kudos: 1
Joined: 25 Sep 2005
Location: Calgary, Alberta

Postby hmoraldo » Thu Mar 22, 2007 2:17 pm

Hmmm, I can't do that, I'm busy these days.
H. Hernan Moraldo
Personal website
User avatar
hmoraldo
OGRE Expert User
OGRE Expert User
 
Posts: 517
Kudos: 0
Joined: 07 Mar 2006
Location: Buenos Aires, Argentina

Postby Loockas » Thu Mar 22, 2007 3:43 pm

hmoraldo wrote:
Loockas wrote:Hey,
I've got the runtime error while trying to run my app. I've used the simplest code from wiki and it compiles fine though there was a problem with missing ddraw.h file but after installing directx sdk all went well. Anyone has encountered that issue with runtime error?


Please post details on the error (error message, stack trace), and the log file, otherwise we can't tell much about the problem.

I've noticed that my app crashes just after the loadmovie function.

I've got this error:
Image

And my log file ends with this:
Code: Select all
15:32:44: [DSHOW] Creating texture with dimensions 640x480.
15:32:44: [DSHOW] Loading movie named 'C:/test_movie.avi'.


EDIT: OK it was something wrong with my video file... with other ones it's working fine! :D Thanks a lot for this great plugin hmoraldo! :D
Umm just one question. How can I load my video not from specified path but from my media folder just like a resource?
Oh, and one more thing. :oops: How to set fullscreen? I can't use the setUV function because there is no PanelOverlayElement class...
User avatar
Loockas
Kobold
 
Posts: 28
Kudos: 0
Joined: 02 Aug 2006
Location: Poland

Postby independentCreations » Tue Mar 27, 2007 3:19 am

@Loockas i have the same crashing problem as yours, i have used directshow before and come across this but i forget how i resolved the issue. My audio works, but i get a crash and i dont see any visual. is there any codec that i should be using????

:Edit: fixed first, material error

Also has any one come across and got around the debugger detected message with visual studio??

:Edit: To find a movie and its relative path using ogre

Code: Select all
Ogre::String path;
Ogre::FileInfoListPtr results =  Ogre::ResourceGroupManager::getSingleton().findResourceFileInfo("General", "*.avi");
Ogre::FileInfoList::iterator itr = results->begin();
while(itr != results->end())
{
   if((*itr).filename == "Cova_Marketing.avi")
   {
      path = (*itr).archive->getName() + "/" + (*itr).filename;
      m_clip->loadMovie(path);
      m_clip->playMovie();
      //and so on
      break;
   }
   itr ++;
}
Final Creations - Tech Leader For 'The Broken'
v2i - Tech Leader For Architectual Sim.
Ogre Enthusiast
User avatar
independentCreations
Greenskin
 
Posts: 121
Kudos: 0
Joined: 07 Jan 2006
Location: Gold Coast - Australia

Postby MickeMicke » Sun Apr 01, 2007 5:25 pm

Hi! I've got this error when I'm running Visual Studio and using DirectShow, otherwise not:
Image

Any suggestions?
MickeMicke
Gnoblar
 
Posts: 6
Kudos: 0
Joined: 01 Apr 2007

Postby mako » Thu Apr 05, 2007 1:38 pm

I'm getting this error too MickeMicke. just after loading a movie, I've tryed with an avi and a mpg video that I downloaded from gamespot.
I'll try with other movies, cause I guess this is a video codec problem.
User avatar
mako
Greenskin
 
Posts: 145
Kudos: 0
Joined: 14 Mar 2007
Location: Brazil

Postby mako » Thu Apr 05, 2007 6:34 pm

the problem is in this line

hr=dsdata->pGraph->RenderFile(filepath, NULL);

filepath seems alright to me.

using ogre 1.4 and directx February 2007 SDK.
User avatar
mako
Greenskin
 
Posts: 145
Kudos: 0
Joined: 14 Mar 2007
Location: Brazil

Postby syedhs » Wed May 30, 2007 11:45 am

ahmedali wrote:I solved the xvid problem by turning the compatibility option on in its decoder properties. But the mpeg2 problem remains.



Sorry to revive this thread - but I faced the same problem as Ahmedali's. Not sure you are still having this problem, but I get this solved by manually setting the subtype & formattype. Originally it was this:-
Code: Select all
mt.subtype = MEDIASUBTYPE_RGB24;
mt.formattype = FORMAT_VideoInfo;

I have it changed to this:-
Code: Select all
mt.subtype = MEDIASUBTYPE_MPEG2_VIDEO;
mt.formattype = FORMAT_MPEG2Video;


I think there could be better solution (eg smart detection) but this is suffice for my problem.

Thanks hmoraldo! :)

Edit: Opss premature solution.. there video doesn't get displayed :?
User avatar
syedhs
Silver Sponsor
Silver Sponsor
 
Posts: 2626
Kudos: 42
Joined: 29 Aug 2005
Location: Kuala Lumpur, Malaysia

Postby syedhs » Thu May 31, 2007 11:26 am

Yay.. 80% done! MPEG2 get displayed although DIVX still dont get displayed. I think it should get displayed because the modification to make it work is based on this: http://www.codeproject.com/audio/VideoAnaFramework.asp?df=100&forumid=321477&exp=0&select=1797483
and the binary downloaded from there is able to display all files. The remaining 20% job is
1) to get the frames synched with audio (now the frames are displayed as fast as possible).
2) COMs object cleanup.
3) getting the video synched with audio,

To those interested, below is my modification:-
loadMovie
Code: Select all
hr=dsdata->pGrabber->SetMediaType(&mt);
if (FAILED(hr)) throw("[DSHOW] Error in setting sample grabber media type");

//---------------Starts here
IBaseFilter* srcFilter;
WCHAR* filepath = util_convertCStringToWString(moviePath.c_str());   
hr = dsdata->pGraph->AddSourceFilter(filepath, L"Source", &srcFilter);
if(FAILED(hr)) throw ("[DSHOW] Unsupported media type!");

// Connect the src and grabber
hr = ConnectFilters(dsdata->pGraph, srcFilter, dsdata->pGrabberF);
if(FAILED(hr)) throw ("[DSHOW] Unsupported media type!");
//---------------End here

// open the file!
hr=dsdata->pGraph->RenderFile(filepath, NULL);
if (FAILED(hr)) throw("[DSHOW] Error opening video file!");

and the supporting functions...
Code: Select all
HRESULT DirectShowMovieTexture::ConnectFilters(IGraphBuilder *pGraph, IBaseFilter *pFirst, IBaseFilter *pSecond)
{
   IPin *pOut = NULL, *pIn = NULL;
   HRESULT hr = GetPin(pSecond, PINDIR_INPUT, &pIn);
   if (FAILED(hr)) return hr;
   // The previous filter may have multiple outputs, so try each one!
   IEnumPins  *pEnum;
   pFirst->EnumPins(&pEnum);
   while(pEnum->Next(1, &pOut, 0) == S_OK)
   {
      PIN_DIRECTION PinDirThis;
      pOut->QueryDirection(&PinDirThis);
      if (PINDIR_OUTPUT == PinDirThis)
      {
         hr = pGraph->Connect(pOut, pIn);
         if(!FAILED(hr))
         {
            break;
         }
      }
   }
   pEnum->Release();
   pIn->Release();
   pOut->Release();
   return hr;
}

// Helper functions:
HRESULT DirectShowMovieTexture::GetPin(IBaseFilter *pFilter, _PinDirection PinDir, IPin **ppPin)
{
   IEnumPins  *pEnum;
   IPin       *pPin;
   pFilter->EnumPins(&pEnum);
   while(pEnum->Next(1, &pPin, 0) == S_OK)
   {
      PIN_DIRECTION PinDirThis;
      pPin->QueryDirection(&PinDirThis);
      if (PinDir == PinDirThis)
      {
         pEnum->Release();
         *ppPin = pPin;
         return S_OK;
      }
      pPin->Release();
   }
   pEnum->Release();
   return E_FAIL; 
}
User avatar
syedhs
Silver Sponsor
Silver Sponsor
 
Posts: 2626
Kudos: 42
Joined: 29 Aug 2005
Location: Kuala Lumpur, Malaysia

Postby manowar » Thu Jun 07, 2007 3:05 pm

This is a great piece of code ! How difficult would it be to retrieve and use the actual dimensions of the movie (read from the file) to create the texture ? I find it about annoying to have to specify the dimensions for each movie.

Thanks
User avatar
manowar
Orc
 
Posts: 419
Kudos: 0
Joined: 07 Apr 2005
Location: UK

Postby manowar » Fri Jun 08, 2007 11:30 am

I had a look on the code, and the Ogre::Texture is created before the movie is loaded. Why not loading the movie and then create the Ogre::Texture using the actual movie dimensions (dsdata->videoWidth, dsdata->videoHeight) ? I quickly hacked the code and moved the texture creation after the movie is loaded and it seems to work fine.
Is there anything wrong with doing that ? I do not have to modify the uvs which is not always simple when videos are applied on parts of models exported from modeling tools.
User avatar
manowar
Orc
 
Posts: 419
Kudos: 0
Joined: 07 Apr 2005
Location: UK

Postby hmoraldo » Mon Jun 18, 2007 10:34 pm

Hi. First of all, this code snippet is meant to be a simple class that deals with videos, so I'm not giving it full features but rather keeping simple enough so that any interested user can just modify the code to make it fits his/her needs. (Different and more complex versions of the code, to be published in neighbour pages on the wiki are welcome too)

The reason why I'm not using the video size to create the texture is that I'm rather trying to use a single texture to fit all videos that are going to be played in an application. And as only the user (and not the app) can know what the maximum size of a video to be played by the application is going to be, I'm keeping the selection of the texture size in hands of the programmer.

It's a personal choice, and of course there are plenty of alternatives. I could have coded it to create a new texture only when the newest video is bigger than the previous ones, or I could have coded it so that each video opened uses a different texture. In this case I chose the option explained above, as it was best fit for the use I was giving this resource and also as it was also appealingly simple. But by no means I say this is the best of all options, or that it should be best for all users or uses.

Thanks for your comments :)
H. Hernan Moraldo
Personal website
User avatar
hmoraldo
OGRE Expert User
OGRE Expert User
 
Posts: 517
Kudos: 0
Joined: 07 Mar 2006
Location: Buenos Aires, Argentina

Postby rluck » Wed Jun 20, 2007 7:18 pm

so I'm having the same issue KungFooMasta did, the video playing in the upper left hand corner. I used his setUV call, and it made the movie smaller, and it gets reproduced multiple times over the panel. Any ideas?

Image
The video size is 640x480, screen resolution is 1152x864.

edit: Fixed, always the stupid errors.
rluck
Kobold
 
Posts: 29
Kudos: 1
Joined: 08 Jun 2007

Postby jona vark » Fri Jun 22, 2007 8:11 pm

I have been able to compile this under VS2005 but I am having a problem with Coinitialize()

Code: Select all
   hr=CoInitialize(NULL);
      if (FAILED(hr))
      {
         throw("[DSHOW] Error in co initialize");

      }


hr is returnd as RPC_E_CHANGED_MODE

Which I guess means that some form of Coinititalize() was already called?

So should I check for this value and bypass Coinitialize() in that case?



thanks Jona

Edit:
I see you've all been dealing with the same sort of issues in this thread. When I posted this I had not seen the entire thread. I will review it. Meanwhile any insight is indeed helpful.
User avatar
jona vark
Gold Sponsor
Gold Sponsor
 
Posts: 83
Kudos: 0
Joined: 01 May 2007

Postby ricardo_arango » Fri Jun 22, 2007 9:43 pm

Are there any license issues when using this?

Let's say for example to play an avi with a cinepak radius codec4?
ricardo_arango
Gremlin
 
Posts: 158
Kudos: 0
Joined: 17 Jan 2006

Postby jona vark » Fri Jun 22, 2007 10:01 pm

As far as I can tell after only a couple of hours into it. You have to setup the MEDIASUBTYPE and other parms for the SampleGrabber code. So your video file and those parms have to match. See earlier parts of this thread.

Seems to be an issue with DV though that I am working out. I am trying to determine how you find the MEDIASUBTYPE of a file.

edit:

I was not able to get this puppy to work for me. Seems like any file type I tried failed. I was able to play the AUDIO of a DV_25 file with the MEDIASUBTYPE_DV25 and MEDIASUBTYPE_Avi but never got imagery with a wmv file or a MS Video1 avi file.

Purging on.
User avatar
jona vark
Gold Sponsor
Gold Sponsor
 
Posts: 83
Kudos: 0
Joined: 01 May 2007

Postby hmoraldo » Sat Jun 23, 2007 1:28 am

ricardo_arango wrote:Are there any license issues when using this?

Let's say for example to play an avi with a cinepak radius codec4?


The code is under the zLib license. Apart from a few details, you can do with this what you could do anyway without this: so I guess what you can or you cannot do with such code rather depends on the license of that codec. But, as far as I know, as you are not using the codec directly, but through DirectShow, your program doesn't depend that much on the codec's license as in DirectShow's.

But I'm not an attorney so I can't really say for sure. Does anyone know better?

Jona Vark: sorry, I don't know why you are having these problems (I guess they require some additional directshow programming to get them working, but I have no time to check that). I can recommend you to try with other video formats? Mpeg has always worked fine for me, and anyway you could try converting some video to a few popular video formats to find those that work.

I'm sorry I couldn't give you more useful answers...

Best regards,
H. Hernan Moraldo
Personal website
User avatar
hmoraldo
OGRE Expert User
OGRE Expert User
 
Posts: 517
Kudos: 0
Joined: 07 Mar 2006
Location: Buenos Aires, Argentina

Postby jona vark » Sat Jun 23, 2007 1:43 am

>>I'm sorry I couldn't give you more useful answers...

Giving us the code was enough. I'll eventually figure it out.

Thanks
User avatar
jona vark
Gold Sponsor
Gold Sponsor
 
Posts: 83
Kudos: 0
Joined: 01 May 2007

Postby hmoraldo » Sat Jun 23, 2007 2:58 pm

Thank you!

By the way, it's strange you aren't getting any visuals. Maybe the texture is being updated but you aren't seeing it? That you are getting the sound is generally the sign that you are very nearly making it work.

Regards!
H. Hernan Moraldo
Personal website
User avatar
hmoraldo
OGRE Expert User
OGRE Expert User
 
Posts: 517
Kudos: 0
Joined: 07 Mar 2006
Location: Buenos Aires, Argentina

Postby jona vark » Sat Jun 23, 2007 3:08 pm

Yes. I am working on it this morning and the first thing I am trying to get past is the fact that CoInitialize() failes. Even if I try to do it prior to any Ogre Init. I keep getting the RPC_E_CHANGED_MODE response.

I was able to play audio though, depending on the file type. I have created avi, dv, mpeg2 and wmv files to try and I have changed the MEDIASUBTYPE from _DV25 to _Avi and back to the RGB24 it was originally.

I am starting to wade through DirectShow doc but there isn't much there on what to do with the RPC_E_CHANGED_MODE result. From what I can tell it indicates that :
A previous call to CoInitializeEx specified a different concurrency model for the calling thread, or the thread that called CoInitializeEx currently belongs to the neutral threaded apartment.


Doh! I have little idea where that previous call could have come from.

This did not fail though:
.
Code: Select all
  HRESULT hr;
   hr = CoInitializeEx(NULL, COINIT_MULTITHREADED);
   if(FAILED(hr))
    {
        throw("[DSHOW] Error in co initialize");
       
     }


hr is always returned as S_FALSE. Oddly all of the other calls to CoCreateInstance and AddFilter, etc return hr=0; So they seem fine. Like somthing else has called CoInitialize.

However. With most file types I get :
First-chance exception at 0x0862a8ed in daac.exe: 0xC0000005: Access violation writing location 0x00000000.


When calling
Code: Select all
hr=dsdata->pGraph->RenderFile(filepath, NULL);


On we go. My target is to have live video on Ogre Textures at some point

EDIT

Whew.. ok.. CoInitialize is the thread starter for COM? This is apparently another Rabbit Hole that would suck up my entire weekend. Even when CoInitialize is the first thing my app does it returns other than S_OK.

But this is a DShow problem. Not an Ogre problem.
User avatar
jona vark
Gold Sponsor
Gold Sponsor
 
Posts: 83
Kudos: 0
Joined: 01 May 2007

Postby jona vark » Sat Jun 23, 2007 8:52 pm

MickeMicke wrote:Hi! I've got this error when I'm running Visual Studio and using DirectShow, otherwise not:
Image

Any suggestions?



If you get back to this thread .. I wanted to ask you. DO YOU Have NERO6 installed on your machine?

see this:http://www.hitlabnz.org/forum/showthread.php?t=70

UPDATE!

THIS WAS THE PROBLEM WITH MY MACHINE RUNNING THIS DEMO!

Yesterday , just to make sure I wasn't crazy I installed the latest Platform SDK, OgreSDK on another machine and rebuilt my entire project.

At the end of the day I had a wmv file playing in one of my textures on a plane.

So I took that project back to the main workstation and built it. Again I got the warning MessageBox shown above. The next thing I did was to uninstall Nero6 and ran again. Without rebuilding. I didn't bother to find out why but it's clearly a part of a protection scheme.

It worked.

That program is gone forever from my machine. Anyone trying to use the DShow features which use video codecs should not have Nero6 on their machine.
User avatar
jona vark
Gold Sponsor
Gold Sponsor
 
Posts: 83
Kudos: 0
Joined: 01 May 2007

Postby hmoraldo » Tue Jun 26, 2007 1:33 am

I'm glad to know you could solve it, thanks for telling us how you did it!
H. Hernan Moraldo
Personal website
User avatar
hmoraldo
OGRE Expert User
OGRE Expert User
 
Posts: 517
Kudos: 0
Joined: 07 Mar 2006
Location: Buenos Aires, Argentina

Postby jona vark » Tue Jun 26, 2007 2:05 am

you're welcome.. meanwhile. If you see any good examples like this which use live video.. I am trying to comprehend the CaptureTex9 sample from the old DX SDK and see if I can held the two together.
User avatar
jona vark
Gold Sponsor
Gold Sponsor
 
Posts: 83
Kudos: 0
Joined: 01 May 2007

Postby ricardo_arango » Tue Jun 26, 2007 8:04 am

I am trying to watch a video encoded with XVid. I checked the video in media player and it played fine.

When I tried to load it with the code it crashed in
Code: Select all
if (FAILED(hr)) throw("[DSHOW] Error getting connected media type info");


returning hr=0x80040209, which means:
An interface has too many methods to fire events from

If i try setting "compatibility renderer" in the Decoder Options dialog for Xvid, as someone recommended in a previous post, I get the "Protection Error, Debugger Detected error dialog", which is supposed to have something to do with Nero, but there is no way to deny a user from having Nero installed..

So, anyone got XVid working?
ricardo_arango
Gremlin
 
Posts: 158
Kudos: 0
Joined: 17 Jan 2006

PreviousNext

Return to Developer talk

Who is online

Users browsing this forum: No registered users and 2 guests