|
|
VB Code to Display Mpeg2Dec frame Aspect Ratio, Resizing, Cropping
New version now includes support for the new 'DGDecode.dll'. But it has a special version of the DLL that is compatible with the VB6 IDE Development (see This Doom9 Topic for more details). I recompiled the DLL with wrapper function for VB6, this version of the DLL IS NOT FOR RE-DISTRIBUTION but only to allow VB programmers develop with the IDE. So please no included this DLL in any releases, use the normal one.
New Link: SampleD2V_DG.rar
-----
Edit 26 June 2004
** This file now includes the fix for the playback problem **
I’ve updated the code for the last time… Well I think so… coz I know this version will be fast enough for everybody!!!
I’ve completely changed how the pixels are drawn to the screen; I’ve removed the api_SetPixelV as this is what’s really slowing down the process, and am using a direct memory write to the DC.hDC. This means no time is lost on silly unneeded function calls. The only thing slowing this version down is a loop to swap the R and B of the RGB as they are in the reverse order, other then that it should all be VERY fast!!!
Link is the good old reliable… SampleD2V.Zip
-----
Edit 2003-9-19Okay one more update, I hope you like it!
This new version now includes Aspect ratio correction, resizing, and cropping. So should do almost everything anybody could want. If you have any ideas on other functions you would like let me know. I’m not promising anything, but I’ll try to add it if it’s a good idea.
The file is at the same old link.
-----
Edit 2003-4-7
I've changed the code to make it run a bit faster. If your interested you should download the zip again, as I've updated the Zip file same link below.
Alain_French was right about the loops, I had a bug which I didn't notice so I added code to fix the problem, which lead to the slowing down of the code by adding more loop.
------
Edit 2003-4-6
Here is some code that uses VB and Mpeg2Dec.dll to get information about a D2V file. It will retrieve the Video information and display a selected frame from the D2V file to a VB PictureBox control. It’s a bit slow at the moment, as it’s almost 100% VB code.
SampleD2V.Zip (fixed link)
Note: (SP3 of the VB is needed)
All feedback welcome!
There is a small problem with your link. It points to a .zip.zip file.
Thanks for this. It comes at the exact time when I need it. Except maybe that it should be in C++, but can't get everything...
Hy,
I tested your program and thats true this is very slow
I think, this is a problem with VB langage, because you do a loop 1.000.000 with the pixelV function. Somebody may make test with C++.
If not, perharps the news dll mpeg2dec3.dll is faster than the other.
I already try to make this function with the windowmediaplayer control. I can select the frame that i want, but i can't show it !
If, you know how show a selected frame with this OCX, please tell me
Bye
Alain
I've tried to use similar code to call vidframe.dll (see this thread), but I had no success. Can anyone adapt this code to be used with vidframe.dll? With this dll more video file types can be opened, not only D2V.
I've changed the code to make it run a bit faster. If your interested you should download the zip again, as I've updated the Zip file same link below.
Alain_French was right about the loops, I had a bug which I didn't notice so I added code to fix the problem, which lead to the slowing down of the code by adding more loop.
PS. I've added this info to my original posting.
Originally posted by NiTroGen
I've tried to use similar code to call vidframe.dll (see this thread), but I had no success. Can anyone adapt this code to be used with vidframe.dll? With this dll more video file types can be opened, not only D2V.
I found the problem is with VB it only returns LONG types form an DLL calls. That's why I use the LONG returned as a Point in memory to copy over my user Type with the code:Code:
Private mTVideoInfo As TVideoInfo
'Open the Video, and copy into Type Def
api_CopyMemory ByVal VarPtr(mTVideoInfo), ByVal dll_OpenMPEG(mFileName), mTVideoInfoSize
This will copy mTVideoInfoSize number of byte from the DLL dll_OpenMPEG return LONG which is a mem pointer, to the VB VarPtr of my Type TVideoInfo variable called mTVideoInfo.
Also I don't know what by of format your Function returns, as the GetFrame from Mpeg2Dec.dll was YUV 4:2:2, which needs to be convered into RGB, which is what the GetFrameRGB takes care of.
AH yes !
Thank you for this correction... Now your code is fast
I will use it in my little program !
Thanks
Alain
Okay one more update, I hope you like it!
This new version now includes Aspect ratio correction, resizing, and cropping. So should do almost everything anybody could want. If you have any ideas on other functions you would like let me know. I’m not promising anything, but I’ll try to add it if it’s a good idea.
The file is at the same old link.
Hy,
Thank you for your update
I think there is a problem with aspect ratio function.
You put 1.094 for 4:3 format. But i think that it is 1.368... My 4:3 sources don't have the good aspect.
The 16:9 seems to be good. But if the 4:3 is not ok, it will not be good too. Perhaps this is 1.823 for 16:9 sources. I haven't 16:9 source to test this morning.If not, for the speed is better. 1second against 3s before you last last update. Do you think you can do this faster ?
I dont know what it will be impoved.
Bye
Alain
Yeah! The Aspect ratios are a little off, I’ve only used a NTSC 16:9 for testing. From what I can see there are slightly different values based of the format (PAL/NTSC) and the resolution of the source video (720x576/768x576/there are lots more), I’m going by GKnot’s list. But the cropping and resizing do stay close to the aspect ratio used, so it’s purely an aspect ration problem.
But the VB Class should work fine, as the variable mAspectRatio can be set to whatever value is required by the programmer using it. So can the ‘const’ that store the default values for 16:9 and 4:3. I’m going to have to read up on it to find out for sure, and then I’ll update the VB Class, I’ll post it as soon as I make the changes.
As for the speed, I don’t know. I’ve being reading up on different ways to write into the picture box control. I might have to find a different control if I want it to run faster. Currently it’s almost fast enough for what I need the Class to do, so I don’t know if I’ll be looking at making it run faster anytime soon, it all depends on what I can find out about how picture box works. The perfect solution would be a straight memory copy from the DLL to the Box, but so far anytime I’ve tried this it crashes VB.
Hi,
After a few month, i retested this code. Yes for the speed, this is always a problem... But i don't know new method. Perhaps make de new external dll. I must do test to see where are the low sequence. (GKnot is so quick but not in VB)
Another thing, the picturebox borderstyle must be in 0-size if not we can t see the whole frame and it s a problem to crop properly
I made few test for the speed and this is the quot;GetFramequot; fonction which take the time. It makes 1000ms.
This is normal : For yLoop = 0 To mTVideoInfo.Height CurByte = mTVideoInfo.Width * 3 * yLoop For xLoop = 0 To mTVideoInfo.WidthXout = CurByte + (xLoop * 3)'Display Pixelapi_SetPixelV myDC.hDC, xLoop, mTVideoInfo.Height - yLoop, RGB(Abs(frameByte(Xout)), Abs(frameByte(Xout + 1)), Abs(frameByte(Xout + 2))) Next xLoop Next yLoop
There is 420000 loops so we can t improve it... (in VB).
The only solution is making a dll in C++ for this function but we can t have a picture in resultat or argument... I have no idea...( AMD 3000000000+ ?)
Hi Alain_French,
I’ve updated the code for the last time… Well I think so… coz I know this version will be fast enough for everybody!!!
I’ve completely changed how the pixels are drawn to the screen; I’ve removed the api_SetPixelV as this is what’s really slowing down the process, and am using a direct memory write to the DC.hDC. This means no time is lost on silly unneeded function calls. The only thing slowing this version down is a loop to swap the R and B of the RGB as they are in the reverse order, other then that it should all be VERY fast!!!
Link is the good old reliable… See the first post off this topic
Yes, the execution is down by 5 ! This is a great improvement
In my code, i put a play feature so i quot;getframequot; in a loop. But in the 175th frame, display are not ok. The picturebox seems to be dead. I must restart VB to have new images...
Have you got an idea ? If not, this is not very important for me, the normal display is very good
Thanks you for this release.
Doh! Sorry about that, I didn’t test it to play a long series of frames, I did only a couple of seeks. I’ve updated the program again… you know the link.
I should have been deleting the hBMP -gt; CreateDIBitmap. So that’s been fixed it was a two liner!
See the GetFrame function and added the DeleteObject API call to the defs.
Yes, it works now
Thank you very much for this program.
New version now includes support for the new 'DGDecode.dll'. But it has a special version of the DLL that is compatible with the VB6 IDE Development (see This Doom9 Topic for more details). I recompiled the DLL with wrapper function for VB6, this version of the DLL IS NOT FOR RE-DISTRIBUTION but only to allow VB programmers develop with the IDE. So please no included this DLL in any releases, use the normal one.
New Link: SampleD2V_DG.rar
Hi thank you again for your stuff. I tried to use dgdecode and i have the same problem that you explain in your thread quot;Using DGDecode.dll with VB6quot;.
However i can t download your file, is the link down ?
Alain
If I can help by adding code to DGMPGDec to avoid you needing to modify it, I'd be willing to consider it. Please advise.
I ll be happy if you can add this modification but i don t know exactly what DoC hEx did.
So please come back Doc hEx |
|