Форум: "WinAPI";
Текущий архив: 2004.11.21;
Скачать: [xml.tar.bz2];
ВнизAVIStreamRead - проблемы Найти похожие ветки
← →
Ozone © (2004-10-11 09:36) [0]Есть такая сабжевая ф-ия - http://msdn.microsoft.com/library/default.asp?url=/library/en-us/multimed/htm/_win32_avistreamread.asp
Хочу буфер в файл сохранить:
AVIStreamRead(AudioStream, 0, AVISTREAMREAD_CONVENIENT, nil, cbBuffer, plBytes, plSamples);
if AVIStreamRead(AudioStream, 0, 0, lpBuffer, cbBuffer, plBytes, plSamples) = 0 then begin
GetMem(lpBuffer, cbBuffer);
AssignFile(f, "C:\temp.bin");
ReWrite(f);
BlockWrite(f,lpBuffer, cbBuffer); // Здесь I/O error 1784
CloseFile(f);
FreeMem(lpBuffer, cbBuffer);
end;
Где я ошибся?
← →
Ozone © (2004-10-11 09:37) [1]косяк...
if AVIStreamRead(AudioStream, 0, plSamples^, lpBuffer, cbBuffer, plBytes, plSamples) = 0 then begin
← →
Ozone © (2004-10-11 09:39) [2]еще косяк...
GetMem(lpBuffer, cbBuffer); - до 2-го вызова
← →
MBo © (2004-10-11 09:41) [3]BlockWrite(f,lpBuffer^, cbBuffer);
(у тебя, правда, не указан тип буфера)
← →
MBo © (2004-10-11 09:44) [4]нужно первый вызов AVIStreamRead сделать с nil вместо lpBuffer,
потом выделить память, и тогда уже считывать данные!
← →
Ozone © (2004-10-11 10:04) [5]По просьбе привожу всё:
TAVIReader = class(TPersistent)
private
VideoStream : IAVISTREAM;
AVIFile : IAVIFILE;
AVIFrame : IGetFrame;
AVIInfo : TAVIStreamInfo;
fFileName : string;
public
AudioStream : IAVISTREAM;
Frames: array of PBITMAPINFOHEADER;
FCount : cardinal;
constructor Create; virtual;
destructor Destroy; override;
function OpenFile(const FileName: string): boolean;
procedure GetFrames;
procedure Close;
end;
function TAVIReader.OpenFile(const FileName: string): boolean;
var
iResult: integer;
begin
Result := false;
Close;
AVIFileInit;
FillChar(AVIInfo,SizeOf(AVIInfo),0);
iResult := AVIFileOpen(AVIFile, pchar(FileName), OF_READ + OF_SHARE_DENY_WRITE, nil);
if iResult <> AVIERR_OK then begin
raise Exception.Create("Cannot open AVI file " + Filename);
exit;
end;
iResult := AVIFileGetStream(AVIFile, VideoStream, streamtypeVideo, 0);
if iResult <> AVIERR_OK then begin
raise Exception.Create("Cannot open video stream for that file");
exit;
end;
iResult := AVIFileGetStream(AVIFile, AudioStream, streamtypeAUDIO, 0);
if iResult <> AVIERR_OK then begin
raise Exception.Create("Cannot open audio stream for that file");
exit;
end;
iResult := AVIStreamInfo(VideoStream, AVIInfo, Sizeof(AVIInfo));
if iResult <> AVIERR_OK then begin
raise Exception.Create("Cannot read stream info");
exit;
end;
AVIFrame := AVIStreamGetFrameOpen(VideoStream, nil);
if not Assigned(AVIFrame) then begin
raise Exception.Create("Cannot find suitable decompressor");
exit;
end;
FCount := AVIInfo.dwLength;
Result := true;
end;
constructor TAVIReader.Create;
begin
inherited Create;
AVIFile := nil;
VideoStream := nil;
AudioStream := nil;
AVIFrame := nil;
AVIFileInit;
end;
destructor TAVIReader.Destroy;
begin
Close;
inherited Destroy;
end;
// собственно вызов
var
AviFile: TAVIReader;
lStart : LONG;
lSamples : LONG;
lpBuffer : PVOID;
cbBuffer : LONG;
plBytes : PLONG;
plSamples : PLONG;
f: file;
begin
AviFile := TAVIReader.Create;
try
AviFile.OpenFile("test.avi");
lpBuffer := nil;
AVIStreamRead(AviFile.AudioStream, 0, AVISTREAMREAD_CONVENIENT, nil, cbBuffer, plBytes, plSamples);
GetMem(lpBuffer, cbBuffer);
if AVIStreamRead(AviFile.AudioStream, 0, AVISTREAMREAD_CONVENIENT, lpBuffer, cbBuffer, plBytes, plSamples) = 0 then begin
AssignFile(f, "C:\temp.bin");
ReWrite(f);
BlockWrite(f,lpBuffer^, cbBuffer);
CloseFile(f);
FreeMem(lpBuffer, cbBuffer);
ShowMessage("END");
end;
finally
AviFile.Free;
end;
Страницы: 1 вся ветка
Форум: "WinAPI";
Текущий архив: 2004.11.21;
Скачать: [xml.tar.bz2];
Память: 0.47 MB
Время: 0.037 c