etruel
22-10-2003, 16:08:56
Hola.
Antes que nada, ME doy la bienvenida en esta magnifica Comunidad de Programadores. Y espero no meter la pata en mi primer post.
He buscado muchisimo por la web y no encontre nada que me lo solucione. Hay multitud de ejemplos, pero andan solo con avi comunes, no con Divx.
Lo que quiero hacer es acceder frame x frame a un Divx y mandarlo a un TBitmap, sin necesidad de reproducirlo.
Esto es para recorrer el video de forma mas rapida que en tiempo real.
Pongo un codigo que "casi" anduvo:
(usando vfw.pas)
AVIFileInit;
// The AVIFileOpen function opens an AVI file
Error := AVIFileOpen(pFile, PChar(FileName), 0, nil);
...
// AVIFileInfo obtains information about an AVI file
if AVIFileInfo(pFile, @AVIINFO, SizeOf(AVIINFO)) <> AVIERR_OK then
...
MediaWidth := AVIINFO.dwWidth;
MediaHeight:= AVIINFO.dwHeight;
MediaFrames:= AVIINFO.dwLength;
MediaScale := AVIINFO.dwScale;
// Open a Stream from the file
Error := AVIFileGetStream(pFile, AVIStream, streamtypeVIDEO, 0);
...
// Prepares to decompress video frames
gapgf := AVIStreamGetFrameOpen(AVIStream, nil);
...
// Read current Frame
// AVIStreamGetFrame Returns the address of a decompressed video frame
lpbi := AVIStreamGetFrame(gapgf, iFrameNum);
...
TmpBmp := TBitmap.Create;
try
TmpBmp.Height := lpbi.biHeight;
TmpBmp.Width := lpbi.biWidth;
bits := Pointer(Integer(lpbi) + SizeOf(TBITMAPINFOHEADER));
DC_Handle := CreateDC('Display', nil, nil, nil);
try
hBmp := CreateDIBitmap(DC_Handle, // handle of device context
lpbi^, // address of bitmap size and format data
CBM_INIT, // initialization flag
bits, // address of initialization data
PBITMAPINFO(lpbi)^, // address of bitmap color-format data
DIB_RGB_COLORS); // color-data usage
finally
DeleteDC(DC_Handle);
end;
TmpBmp.Handle := hBmp;
finally
TmpBmp.Free;
end;
Esto me anda para AVIs comunes pero para videos Divx la linea
gapgf := AVIStreamGetFrameOpen(AVIStream, nil); siempre me devuelve nil, entoces falla el getframe.
Probe tambien el TmediaPlayer y no me reproduce divx.
y probé el DSPack con directshow pero no se como acceder a los frames sin tener que reproducir el video.
¿Alguien me puede dar una mano con esto?
Gracias
Antes que nada, ME doy la bienvenida en esta magnifica Comunidad de Programadores. Y espero no meter la pata en mi primer post.
He buscado muchisimo por la web y no encontre nada que me lo solucione. Hay multitud de ejemplos, pero andan solo con avi comunes, no con Divx.
Lo que quiero hacer es acceder frame x frame a un Divx y mandarlo a un TBitmap, sin necesidad de reproducirlo.
Esto es para recorrer el video de forma mas rapida que en tiempo real.
Pongo un codigo que "casi" anduvo:
(usando vfw.pas)
AVIFileInit;
// The AVIFileOpen function opens an AVI file
Error := AVIFileOpen(pFile, PChar(FileName), 0, nil);
...
// AVIFileInfo obtains information about an AVI file
if AVIFileInfo(pFile, @AVIINFO, SizeOf(AVIINFO)) <> AVIERR_OK then
...
MediaWidth := AVIINFO.dwWidth;
MediaHeight:= AVIINFO.dwHeight;
MediaFrames:= AVIINFO.dwLength;
MediaScale := AVIINFO.dwScale;
// Open a Stream from the file
Error := AVIFileGetStream(pFile, AVIStream, streamtypeVIDEO, 0);
...
// Prepares to decompress video frames
gapgf := AVIStreamGetFrameOpen(AVIStream, nil);
...
// Read current Frame
// AVIStreamGetFrame Returns the address of a decompressed video frame
lpbi := AVIStreamGetFrame(gapgf, iFrameNum);
...
TmpBmp := TBitmap.Create;
try
TmpBmp.Height := lpbi.biHeight;
TmpBmp.Width := lpbi.biWidth;
bits := Pointer(Integer(lpbi) + SizeOf(TBITMAPINFOHEADER));
DC_Handle := CreateDC('Display', nil, nil, nil);
try
hBmp := CreateDIBitmap(DC_Handle, // handle of device context
lpbi^, // address of bitmap size and format data
CBM_INIT, // initialization flag
bits, // address of initialization data
PBITMAPINFO(lpbi)^, // address of bitmap color-format data
DIB_RGB_COLORS); // color-data usage
finally
DeleteDC(DC_Handle);
end;
TmpBmp.Handle := hBmp;
finally
TmpBmp.Free;
end;
Esto me anda para AVIs comunes pero para videos Divx la linea
gapgf := AVIStreamGetFrameOpen(AVIStream, nil); siempre me devuelve nil, entoces falla el getframe.
Probe tambien el TmediaPlayer y no me reproduce divx.
y probé el DSPack con directshow pero no se como acceder a los frames sin tener que reproducir el video.
¿Alguien me puede dar una mano con esto?
Gracias