Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Question about avi file

Dear All

I have a Question about Working with avi file.I need to transmit an avi file from the LPT port.
I want to send exactly 30 frames per sec into LPT port. I used "VFW.pas" for reading a avi file , but my
Prbolem is that I couldn't read 30 frames/sec from the file (cause of low speed of hard disk Speed).
I need an algorithm for implementation this work.
How to accomplish that with delphi programming, I need samples of the codes to do so ... thanks.

Comments

  • zibadianzibadian Member Posts: 6,349
    : Dear All
    :
    : I have a Question about Working with avi file.I need to transmit an avi file from the LPT port.
    : I want to send exactly 30 frames per sec into LPT port. I used "VFW.pas" for reading a avi file , but my
    : Prbolem is that I couldn't read 30 frames/sec from the file (cause of low speed of hard disk Speed).
    : I need an algorithm for implementation this work.
    : How to accomplish that with delphi programming, I need samples of the codes to do so ... thanks.
    :
    Would you please not ask the same question on all boards! Many of us check most boards, and probably dislike (I do for one) seeing the same question over and over again.
  • MasterijnMasterijn Member Posts: 188
    [b][red]This message was edited by Masterijn at 2003-12-29 15:51:43[/red][/b][hr]
    : Dear All
    :
    : I have a Question about Working with avi file.I need to transmit an avi file from the LPT port.
    : I want to send exactly 30 frames per sec into LPT port. I used "VFW.pas" for reading a avi file , but my
    : Prbolem is that I couldn't read 30 frames/sec from the file (cause of low speed of hard disk Speed).
    : I need an algorithm for implementation this work.
    : How to accomplish that with delphi programming, I need samples of the codes to do so ... thanks.
    :
    I bet it's not the harddrive you need worrying about. But any way, try using double (or more) buffered asynchronous file reading.
    Such as this pseudo stuff:
    [code]
    AsyncRead(buf[0]) // => ReadFile
    AsyncRead(buf[1])
    BufIndex := 0;
    repeat
    WaitForReadBuf(BufIndex) => GetOverlappedResult
    AsyncRead(buf[BufIndex])
    SendBufToLPT(buf[BufIndex])
    BufIndex := (BufIndex + 1) and 1;
    until Finnished
    [/code]
    I' found some overlapped file comparing routine I once wrote. Great for comparing 2 files from different devices, up to 2 times as fast.
    [code]
    procedure TfrmMain.ONRun(var Message: TMessage);
    begin
    FEventArray[0] := 0;
    FEventArray[1] := 0;
    try
    GetMem(FBuffer1, MaxBufSize);
    GetMem(FBuffer2, MaxBufSize);
    FEventArray[0] := CreateEvent(nil, False, False, nil);
    FEventArray[1] := CreateEvent(nil, False, False, nil);
    FOverlapped1.hEvent := FEventArray[0];
    FOverlapped2.hEvent := FEventArray[1];
    if FOverlapped1.hEvent = 0 then
    RaiseLastOSError;
    if FOverlapped2.hEvent = 0 then
    RaiseLastOSError;
    CompareFiles;
    finally
    if FEventArray[0] <> 0 then
    CloseHandle(FEventArray[0]);
    if FEventArray[1] <> 0 then
    CloseHandle(FEventArray[1]);
    StatusBar.Panels[0].Text := 'Done';
    end;
    end;

    function TfrmMain.CompareFile(Filename1, Filename2: string): Boolean;
    var
    FileHandle1 : THandle;
    FileHandle2 : THandle;
    BufSize : Cardinal;
    SizeLeft : Cardinal;
    High1 : Cardinal;
    High2 : Cardinal;
    Dummy : Cardinal;
    begin
    FileHandle1 := 0;
    FileHandle2 := 0;
    FOverlapped1.Offset := 0;
    FOverlapped1.OffsetHigh := 0;
    FOverlapped2.Offset := 0;
    FOverlapped2.OffsetHigh := 0;
    try
    FileHandle1 := CreateFile(PChar(FileName1), GENERIC_READ, FILE_SHARE_READ + FILE_SHARE_WRITE, nil, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL or FILE_FLAG_SEQUENTIAL_SCAN or FILE_FLAG_OVERLAPPED, 0);
    if FileHandle1 = INVALID_HANDLE_VALUE then
    RaiseLastOSError;
    FileHandle2 := CreateFile(PChar(FileName2), GENERIC_READ, FILE_SHARE_READ + FILE_SHARE_WRITE, nil, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL or FILE_FLAG_SEQUENTIAL_SCAN or FILE_FLAG_OVERLAPPED, 0);
    if FileHandle2 = INVALID_HANDLE_VALUE then
    RaiseLastOSError;
    SizeLeft := GetFileSize(FileHandle1, @High1);
    Result := (SizeLeft = GetFileSize(FileHandle2, @High2)) and (High1 = High2);
    if Result then
    begin
    BufSize := SizeLeft;
    if BufSize > MaxBufSize then
    BufSize := MaxBufSize;
    while SizeLeft > 0 do
    begin
    if BufSize > SizeLeft then
    BufSize := SizeLeft;

    if not ReadFile(FileHandle1, FBuffer1^, BufSize, Dummy, @FOverlapped1) and (GetLastError <> ERROR_IO_PENDING) then
    RaiseLastOSError;
    if not ReadFile(FileHandle2, FBuffer2^, BufSize, Dummy, @FOverlapped2) and (GetLastError <> ERROR_IO_PENDING) then
    RaiseLastOSError;

    Win32Check(GetOverlappedResult(FileHandle1, FOverlapped1, Dummy, True));
    if Dummy <> BufSize then
    raise Exception.Create('Readerror');
    Win32Check(GetOverlappedResult(FileHandle2, FOverlapped2, Dummy, True));
    if Dummy <> BufSize then
    raise Exception.Create('Readerror');
    Result := CompareMem(FBuffer1, FBuffer2, BufSize);
    if not Result then
    Break;
    Inc(FOverlapped1.Offset, BufSize);
    Inc(FOverlapped2.Offset, BufSize);
    Dec(SizeLeft, BufSize);
    end;
    end;
    finally
    if (FileHandle1 <> 0) and (FileHandle1 <> INVALID_HANDLE_VALUE) then
    CloseHandle(FileHandle1);
    if (FileHandle2 <> 0) and (FileHandle2 <> INVALID_HANDLE_VALUE) then
    CloseHandle(FileHandle2);
    end;
    end;
    [/code]

    This will read data from your drive while sending to the lpt.
    I suggest you do it the event (CreateEvent; GetOverlappedResult) way, but it can also be done by a callback mechanism. (The best solution would be probably to let the lpt callback on you, while keeping nice full buffers.)
    BTW. can you watch movies on your printer?



Sign In or Register to comment.