207 lines
5.9 KiB
Plaintext
207 lines
5.9 KiB
Plaintext
unit umain;
|
|
|
|
interface
|
|
|
|
uses
|
|
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, ieview,
|
|
imageenview, Buttons, ComCtrls, ExtCtrls, Menus, hyieutils, hyiedefs, imageenproc, iemmf,
|
|
iexBitmaps, iesettings, iexLayers, iexRulers;
|
|
|
|
type
|
|
Tfmain = class(TForm)
|
|
ImageEnView1: TImageEnView;
|
|
Panel1: TPanel;
|
|
GroupBox1: TGroupBox;
|
|
Label1: TLabel;
|
|
SpeedButton1: TSpeedButton;
|
|
GroupBox2: TGroupBox;
|
|
Label2: TLabel;
|
|
TrackBar1: TTrackBar;
|
|
Button5: TButton;
|
|
EditInputFile: TEdit;
|
|
ButtonOpenDialog: TButton;
|
|
OpenDialog1: TOpenDialog;
|
|
Label7: TLabel;
|
|
ScrollBarPosition: TScrollBar;
|
|
ListBoxTrailers: TListBox;
|
|
Label5: TLabel;
|
|
ListBox1: TListBox;
|
|
CheckBoxRenderAudio: TCheckBox;
|
|
Label8: TLabel;
|
|
procedure SpeedButton1Click(Sender: TObject);
|
|
procedure TrackBar1Change(Sender: TObject);
|
|
procedure Button5Click(Sender: TObject);
|
|
procedure ImageEnView1MediaFoundationNotify(Sender, MediaFoundationObject: TObject; NotifyType: TIEMediaFountationNotifyType);
|
|
procedure ButtonOpenDialogClick(Sender: TObject);
|
|
procedure ScrollBarPositionChange(Sender: TObject);
|
|
procedure ListBoxTrailersClick(Sender: TObject);
|
|
private
|
|
{ Private declarations }
|
|
public
|
|
{ Public declarations }
|
|
end;
|
|
|
|
var
|
|
fmain: Tfmain;
|
|
|
|
implementation
|
|
|
|
|
|
|
|
{$R *.DFM}
|
|
{$R WindowsTheme.res}
|
|
|
|
|
|
// Select a file to open
|
|
procedure Tfmain.ButtonOpenDialogClick(Sender: TObject);
|
|
begin
|
|
if OpenDialog1.Execute() then
|
|
EditInputFile.Text := OpenDialog1.FileName;
|
|
end;
|
|
|
|
|
|
// select a trailer
|
|
procedure Tfmain.ListBoxTrailersClick(Sender: TObject);
|
|
var
|
|
link: string;
|
|
begin
|
|
if ListBoxTrailers.ItemIndex > -1 then
|
|
begin
|
|
link := ListBoxTrailers.Items[ListBoxTrailers.ItemIndex];
|
|
link := copy(link, pos('http', link), length(link));
|
|
EditInputFile.Text := link;
|
|
end;
|
|
end;
|
|
|
|
|
|
|
|
// Capture button
|
|
procedure Tfmain.SpeedButton1Click(Sender: TObject);
|
|
var
|
|
audioStreamIndex: DWORD;
|
|
begin
|
|
if SpeedButton1.Down then
|
|
begin
|
|
// for test purposes only!!
|
|
if EditInputFile.Text = '' then
|
|
EditInputFile.Text := 'C:\immagini\video\NASA Robot.mp4';
|
|
|
|
if ImageEnView1.IO.MediaFoundationSourceReader.SetURLInput(EditInputFile.Text) = False then
|
|
begin
|
|
SpeedButton1.Down := False;
|
|
raise Exception.create( 'Unable to capture URL stream. Is it still available?' );
|
|
end;
|
|
|
|
// start capture
|
|
ScrollBarPosition.Position := 0;
|
|
CheckBoxRenderAudio.Enabled := false;
|
|
|
|
// enable video stream
|
|
ImageEnView1.IO.MediaFoundationSourceReader.SetSelectedStreams(mmf_VIDEO_STREAM, true);
|
|
|
|
// select first media type
|
|
ImageEnView1.IO.MediaFoundationSourceReader.SelectMediaType(mmf_VIDEO_STREAM, 0);
|
|
|
|
// Render Audio? (warn: can be out of synch, this is a grabber not a media-player!)
|
|
if CheckBoxRenderAudio.Checked then
|
|
begin
|
|
audioStreamIndex := ImageEnView1.IO.MediaFoundationSourceReader.IndexOfFirstStream(mmf_AUDIO_STREAM);
|
|
ImageEnView1.IO.MediaFoundationSourceReader.SetSelectedStreams(audioStreamIndex, true);
|
|
ImageEnView1.IO.MediaFoundationSourceReader.SetMediaTypeAudio(audioStreamIndex, mmf_AudioFormat_PCM);
|
|
ImageEnView1.IO.MediaFoundationSourceReader.PushNotifyReceiver( TIEMediaFoundationAudioRenderer.Create(audioStreamIndex) );
|
|
end;
|
|
|
|
// start capture
|
|
ImageEnView1.IO.MediaFoundationSourceReader.StartCapture();
|
|
|
|
// get actual audio/video format
|
|
ListBox1.Clear();
|
|
ListBox1.Items.Add( ImageEnView1.IO.MediaFoundationSourceReader.GetCurrentMediaType(mmf_VIDEO_STREAM).Dump( ieplJSON ) );
|
|
ListBox1.Items.Add( ImageEnView1.IO.MediaFoundationSourceReader.GetCurrentMediaType(mmf_AUDIO_STREAM).Dump( ieplJSON ) );
|
|
|
|
end
|
|
else
|
|
begin
|
|
// stop capture
|
|
ImageEnView1.IO.MediaFoundationSourceReader.StopCapture();
|
|
if CheckBoxRenderAudio.Checked then
|
|
ImageEnView1.IO.MediaFoundationSourceReader.PopNotifyReceiver(); // remove audio renderer
|
|
|
|
CheckBoxRenderAudio.Enabled := true;
|
|
end;
|
|
end;
|
|
|
|
|
|
// Save image
|
|
procedure Tfmain.Button5Click(Sender: TObject);
|
|
begin
|
|
ImageEnView1.IO.SaveToFile(ImageEnView1.IO.ExecuteSaveDialog('', '', false, 1, ''));
|
|
end;
|
|
|
|
|
|
// Zoom
|
|
procedure Tfmain.TrackBar1Change(Sender: TObject);
|
|
begin
|
|
ImageEnView1.Zoom := TrackBar1.Position;
|
|
end;
|
|
|
|
|
|
// frame received
|
|
procedure Tfmain.ImageEnView1MediaFoundationNotify(Sender, MediaFoundationObject: TObject; NotifyType: TIEMediaFountationNotifyType);
|
|
var
|
|
msg: string;
|
|
grabber: TIEMediaFoundationSourceReader;
|
|
sample: TIEMFReceivedSample;
|
|
begin
|
|
case NotifyType of
|
|
|
|
iemfnFRAME:
|
|
begin
|
|
grabber := MediaFoundationObject as TIEMediaFoundationSourceReader;
|
|
sample := grabber.GetNextSample();
|
|
|
|
try
|
|
if sample.StreamType = mmf_VIDEO_STREAM then
|
|
begin
|
|
// process Video sample
|
|
sample.DecodeSample(ImageEnView1.IEBitmap);
|
|
|
|
// draw timings
|
|
msg := Format('%s / %s', [IEMediaFoundationTimeToStr(sample.TimeStamp), IEMediaFoundationTimeToStr(grabber.Duration)]);
|
|
ImageEnView1.IEBitmap.IECanvas.Brush.Style := bsSolid;
|
|
ImageEnView1.IEBitmap.IECanvas.Brush.Color := clYellow;
|
|
ImageEnView1.IEBitmap.IECanvas.Font.Color := clBlue;
|
|
ImageEnView1.IEBitmap.IECanvas.Font.Name := 'Arial';
|
|
ImageEnView1.IEBitmap.IECanvas.Font.Height := 20;
|
|
ImageEnView1.IEBitmap.IECanvas.TextOut(0, ImageEnView1.IEBitmap.Height - 20, msg);
|
|
|
|
ImageEnView1.Update();
|
|
end;
|
|
finally
|
|
sample.Free();
|
|
end;
|
|
end;
|
|
|
|
iemfnENDOFSTREAM:
|
|
begin
|
|
// End of stream, stop capture
|
|
SpeedButton1.Down := false;
|
|
SpeedButton1Click(self);
|
|
end;
|
|
end;
|
|
end;
|
|
|
|
|
|
// set new position
|
|
procedure Tfmain.ScrollBarPositionChange(Sender: TObject);
|
|
var
|
|
duration: int64;
|
|
begin
|
|
duration := ImageEnView1.IO.MediaFoundationSourceReader.Duration;
|
|
ImageEnView1.IO.MediaFoundationSourceReader.SetPosition( trunc(duration / ScrollBarPosition.Max * ScrollBarPosition.Position) );
|
|
end;
|
|
|
|
|
|
|
|
end.
|