Главная страница
Top.Mail.Ru    Яндекс.Метрика
Текущий архив: 2004.11.21;
Скачать: CL | DM;

Вниз

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 вся ветка

Текущий архив: 2004.11.21;
Скачать: CL | DM;

Наверх




Память: 0.49 MB
Время: 0.044 c
1-1099924974
Polycom
2004-11-08 17:42
2004.11.21
Listbox и чтение из файла


1-1100122006
SkyNet
2004-11-11 00:26
2004.11.21
Чужая программа и её самовосстанавливающаяся переменная


4-1097321007
TeNY
2004-10-09 15:23
2004.11.21
Как заставить окно с нужных хэндлом заставить поморгать и границу


3-1098194755
Vir
2004-10-19 18:05
2004.11.21
список значений поля


8-1092984946
k-sergey
2004-08-20 10:55
2004.11.21
как в TlistBox изменить цвет полоски выделеного item-а?