title: How to read first and last 64kb of a video file in Delphi?
body: <p>I want to use a subtitle API. It requires a md5 hash of first and last 64kb of the video file. I know how to do the md5 part just want to know how will I achieve to get the 128kb of data.</p>
  
  <p>Here is the solution to the problem in Java which I am unable to implement in Delphi. <a href="https://stackoverflow.com/questions/21714356/how-to-read-first-and-last-64kb-of-a-video-file-in-java">How to read first and last 64kb of a video file in Java?</a></p>
  
  <p>My Delphi code so far: </p>
  
  <pre><code>function TSubdbApi.GetHashFromFile(const AFilename: string): string;
  var
    Md5: TIdHashMessageDigest5;
    Filestream: TFileStream;
    Buffer: TByteArray;
  begin
    Md5 := TIdHashMessageDigest5.Create;
    Filestream := TFileStream.Create(AFilename, fmOpenRead, fmShareDenyWrite);
    try
      if Filestream.Size &gt; 0 then begin
        Filestream.Read(Buffer, 1024 * 64);
        Filestream.Seek(64, soFromEnd);
        Filestream.Read(Buffer, 1024 * 64);
        Result := Md5.HashStreamAsHex(Filestream);
      end;
    finally
      Md5.Free;
      Filestream.Free;
    end;
  end;
  </code></pre>
  
  <p>I am not getting the accurate md5 hash as stated by the official API.<a href="http://thesubdb.com/api/" rel="nofollow noreferrer">API url  here</a>. I am using Delphi XE8.</p>