View Full Version : How get Bitmap from frame
ruanova
27th June 2005, 11:57
Hi ...
Calling directly AviSynth.dll functions ..., after frame = GetFrame(..,..)
How can I get a HBITMAP from frame ...?
Thanks....
IanB
28th June 2005, 15:26
@ruanova,
Short answer is you can't get a HBITMAP. However you could blit (load) the frame data into a pre-created bitmap. Note, most windows picture (bitmap)operations are very slow, this is why avisynth does most things directly even resorting to assembler with MMX/SSE to get the needed speed. frame=child->GetFrame(n, env); // load frame N
pitch=frame->GetPitch(); // distance in byte from 1 line to the next
rowsize=frame->GetRowSize(); // number of active bytes in a line
height=frame->GetHeight(); // number of lines
data=frame->GetReadPtr(); // beginning of picture data
// Some knowledge of pixel format.
// for RGB32 format, data[0] is blue byte, data[1] is green,
// data[2]is red & data[3] is alpha for the bottom left pixel.
// RGB data is stored left to right, bottom up to top.
// RGB24 has 3 bytes per pixel and has no alpha channel.
// YUV formats start at the top left corner and go down.
for (int y=height-1;y>=0;y--) {
for (int x=0;x<rowsize;x+=4) {
blue=data[x];
green=data[x+1];
red=data[x+2];
alpha=data[x+3]; // probably not needed
// use pixel data as appropriate
}
data += pitch; // advance up 1 line
}This of course is a slow way of accessing the data but clarity is more important when explaining.
Take a look at the source level.cpp for examples of manipulating pixel data.
IanB
ruanova
4th July 2005, 12:55
Sorry .. I'm a few days out ...
I made a mistake ... really my question are some like this:
"How can I 'display' a frame in the screen, if the Frame are in YUV12 color format ...?. With the DirectX functions....?"
Actualy, I only know using RGB color format...
Thanks
mg262
4th July 2005, 13:16
You can convert the video to RGB before you pass it into whatever you are writing... or you can call Invoke with "ConvertToRGB32" (or 24) inside the program. @IanB's example code is RGB32.
What are you aiming to do?
ruanova
5th July 2005, 16:14
Thanks mg262 ...
OK, month's ago, I write a program in Borland C++ Builder that shows 2 timeline for 2 .avs scripts .... to 'syncronyze' a DVB capture and a .avi video file ...
I'm use VFW interface to AviSynth.dll, but I think that is little slow. Then I'm writing a .dll in Visual Studio .NET 2003 that is a 'warpper' to Borland C++ Builder 6 from AviSynth.dll and I need a way to 'show' in screen frames in YUV12 format from the frame buffer in PVideoFrame*
Thanks
Okay, YV12 memory layout from a GetFrame() call is not compatible due to the MMX favourable pitch alignment used. Most implementations want 4 byte alignment with packed UV planes. To have any success with the various direct display calls you will have to blit the 3 planes into the appropriate format. See the code for CAVIStreamSynth::ReadFrame() about line 750 in core\main.cpp for an example. You can use env->BitBlt() to access the fast internal blitter engine.
Many direct/overlay YV12 implementation are broken, you will have an easier life if you convert to RGB or YUY2 format before displaying.
IanB
ruanova
6th July 2005, 07:26
Thanks IanB ...
I'll try it today ....
Thanks again.
vBulletin® v3.8.11, Copyright ©2000-2026, vBulletin Solutions Inc.