Unit1.pas 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. unit Unit1;
  2. interface
  3. uses
  4. Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  5. Dialogs, StdCtrls, ExtCtrls, DSPack;
  6. type
  7. TForm1 = class(TForm)
  8. FilterGraph: TFilterGraph;
  9. VideoWindow: TVideoWindow;
  10. SampleGrabber: TSampleGrabber;
  11. Image: TImage;
  12. OpenPlay: TButton;
  13. Snapshot: TButton;
  14. OpenDialog: TOpenDialog;
  15. CallBack: TCheckBox;
  16. procedure OpenPlayClick(Sender: TObject);
  17. procedure SnapshotClick(Sender: TObject);
  18. procedure FormClose(Sender: TObject; var Action: TCloseAction);
  19. procedure SampleGrabberBuffer(sender: TObject; SampleTime: Double;
  20. pBuffer: Pointer; BufferLen: Integer);
  21. private
  22. { Déclarations privées }
  23. public
  24. { Déclarations publiques }
  25. end;
  26. var
  27. Form1: TForm1;
  28. implementation
  29. {$R *.dfm}
  30. procedure TForm1.OpenPlayClick(Sender: TObject);
  31. begin
  32. if OpenDialog.Execute then
  33. begin
  34. FilterGraph.Active := False;
  35. FilterGraph.Active := true;
  36. FilterGraph.RenderFile(OpenDialog.FileName);
  37. FilterGraph.Play;
  38. end;
  39. end;
  40. procedure TForm1.SnapshotClick(Sender: TObject);
  41. begin
  42. SampleGrabber.GetBitmap(Image.Picture.Bitmap)
  43. end;
  44. procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
  45. begin
  46. CallBack.Checked := false;
  47. FilterGraph.ClearGraph;
  48. FilterGraph.Active := false;
  49. end;
  50. procedure TForm1.SampleGrabberBuffer(sender: TObject; SampleTime: Double;
  51. pBuffer: Pointer; BufferLen: Integer);
  52. begin
  53. if CallBack.Checked then
  54. begin
  55. Image.Canvas.Lock; // to avoid flickering
  56. try
  57. SampleGrabber.GetBitmap(Image.Picture.Bitmap, pBuffer, BufferLen)
  58. finally
  59. Image.Canvas.Unlock;
  60. end;
  61. end;
  62. end;
  63. end.