⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mainform.pas

📁 TVideoGrabber 7.5 TVideoGrabber 7.5 TVideoGrabber 7.5
💻 PAS
📖 第 1 页 / 共 5 页
字号:
    FSnapImage: TImage;

    FFreeHandMouseDrawing: array[0..FreeHandMouseMax] of TRect;
    FFreeHandMouseDrawingEnabled: boolean;
    FiFreeHandMouseDrawing: LongInt;

    FPickupTransparentColor_MustGetRGBPixel: Boolean;
    FPickupTransparentColor_LastRGBPixelValueAtMousePosition: LongInt;
    FPickupTransparentColor_MouseXVideoPosition: LongInt;
    FPickupTransparentColor_MouseYVideoPosition: LongInt;

    FSearchBmpFiles: TSearchRec;
    FSearchBmpFilesOpened: Boolean;
    FSearchBmpPath: String;

    FOldVideoSignalState: Boolean;

    procedure ShowFormAboveVideo(Form: TForm);
    procedure RefreshDeviceControls;
    procedure RefreshDisplayOptions;
  end;

var
  frmMainForm: TfrmMainForm;

implementation

uses
   miscVideoQuality,
   miscCameraControl,
   miscVideoControl, miscSpecialControls;

const
   OPEN_MEDIA_FILES = '*.mpg;*.mpeg;*.vro;*.avi;*.wav;*.mp3;*.asf;*.wmv;*.vob';
   OPEN_MEDIA_FILES_EXTENDED = OPEN_MEDIA_FILES + ';*.jpg;*.bmp;*.gif';
   OPEN_IMAGE_FILES = '*.bmp;*.jpg;*.gif;*.png;*.tif;*.tiff;*.wmf;*.emf;*.exf;*.jpe;*.jpeg';
{$R *.DFM}

procedure AssignListToComboBox (ComboBox: TComboBox; List: String; Index: integer);
begin
   ComboBox.Items.Text := List;
   if (ComboBox.Items.Count > 0) and (Index >= 0) then begin
      ComboBox.ItemIndex := Index;
   end;
end;

procedure TfrmMainForm.FormCreate(Sender: TObject);
begin
   FFreeHandMouseDrawingEnabled:= False; // used for free-hand mouse drawing
   FiFreeHandMouseDrawing:= 0;           // used for free-hand mouse drawing
   FSearchBmpFilesOpened := False;       // used for the "video from bitmaps" in the VideoGrabberVideoFromBitmaps_NextFrameNeeded event

   // used in the image overlay sample, to pickup a transparent color on the video frame at the last mouse click location
   FPickupTransparentColor_MustGetRGBPixel := false;
   FPickupTransparentColor_LastRGBPixelValueAtMousePosition := -1;
   FPickupTransparentColor_MouseXVideoPosition := 0;
   FPickupTransparentColor_MouseYVideoPosition := 0;

   FStartupWidth := Width;
   FStartupHeight := Height;

   FOldVideoSignalState := False;

   // - controls using global TVideoGrabber properties, e.g. like the VideoDevices list, are updated from the FormCreate event
   // - controls that depend of the current video device are set in the VideoDeviceSelected event
   // - controls that depend of the current audio device are set in the AudioDeviceSelected event

   ///////////////////////// Controls on main form
   edtStoragePath.Text := VideoGrabber.StoragePath;

   ///////////////////////// Video source tab
   AssignListToComboBox (cboVideoSource, VideoGrabber.VideoSources, Integer (VideoGrabber.VideoSource));
   btnAutoRefreshPreview.Checked := VideoGrabber.AutoRefreshPreview;
   cboVideoSource.ItemIndex := Integer (VideoGrabber.VideoSource);
   chkScreenRecordingWithCursor.Checked := VideoGrabber.ScreenRecordingWithCursor;
   edtMonitorNumber.Text := IntToStr (VideoGrabber.ScreenRecordingMonitor);
   chkMultiplexedInputEmulation.Checked := VideoGrabber.MultiplexedInputEmulation;
   VideoGrabber.VideoSource_FileOrUrl := edtVideoSourceFileOrUrl.Text;

   ///////////////////////// Audio tab
   chkRenderAudioDevice.Checked := VideoGrabber.AudioDeviceRendering;
   chkMuteAudioRendering.Checked := VideoGrabber.MuteAudioRendering;
   rdgVUMeters.ItemIndex := Integer (VideoGrabber.VUMeter);

   ///////////////////////// RECORDING tab
   rdgRecordingMethod.ItemIndex := Integer (VideoGrabber.RecordingMethod);
   rdgRecordingSize.ItemIndex := Integer (VideoGrabber.RecordingSize);
   edtPreallocSize.Text := IntToStr (VideoGrabber.PreallocCapFileSizeInMB);
   AssignListToComboBox (cboAudioFormats, VideoGrabber.AudioFormats, integer (VideoGrabber.AudioFormat));
   chkRecordingCanPause.Checked := VideoGrabber.RecordingCanPause;
   chkRecordingPauseCreatesNewFile.Checked := VideoGrabber.RecordingPauseCreatesNewFile;
   chkPreallocFile.Checked := VideoGrabber.PreallocCapFileEnabled;
   chkOpenDML.Checked := VideoGrabber.AVIFormatOpenDML;
   chkPreserveNativeFormat.Checked := VideoGrabber.RecordingInNativeFormat;

   rdgCompressType.ItemIndex := integer (VideoGrabber.CompressionType);
   rdgCompressMode.ItemIndex := integer (VideoGrabber.CompressionMode);
   chkAudioRecording.Checked := VideoGrabber.AudioRecording;
   AssignListToComboBox (cboVideoCompressors, VideoCompressors, VideoGrabber.VideoCompressor);
   AssignListToComboBox (cboAudioCompressors, AudioCompressors, VideoGrabber.AudioCompressor);

   ///////////////////////// network Streaming tab

   rdgNetworkStreaming.ItemIndex := Integer (VideoGrabber.NetworkStreaming);
   rdgNetworkStreamingType.ItemIndex := Integer (VideoGrabber.NetworkStreamingType);
   rdgNetworkStreamingType.Enabled := VideoGrabber.NetworkStreaming <> ns_Disabled;
   edtPublishingPoint.Text := VideoGrabber.ASFMediaServerPublishingPoint;
   edtNetworkPort.Text := IntToStr (VideoGrabber.ASFNetworkPort);
   edtNetworkMaxUsers.Text := IntToStr (VideoGrabber.ASFNetworkMaxUsers);

   rdgProfileVersion.ItemIndex := Integer (VideoGrabber.ASFProfileVersion);
   if VideoGrabber.ASFProfileFromCustomFile <> '' then begin
      edtWM9Profile.Text := VideoGrabber.ASFProfileFromCustomFile;
   end;
   edtASFVideoWidth.Text := IntToStr (VideoGrabber.ASFVideoWidth);
   edtASFVideoHeight.Text := IntToStr (VideoGrabber.ASFVideoHeight);
   edtASFVideoBitRate.Text := IntToStr (VideoGrabber.ASFVideoBitRate);
   edtASFVideoMaxKeyFrameSpacing.Text := IntToStr (VideoGrabber.ASFVideoMaxKeyFrameSpacing);
   edtASFVideoQuality.Text := IntToStr (VideoGrabber.ASFVideoQuality);
   edtASFAudioChannels.Text := IntToStr (VideoGrabber.ASFAudioChannels);
   chkASFFixedFrameRate.Checked := VideoGrabber.ASFFixedFrameRate;
   cmbASFDeinterlaceMode.ItemIndex := Integer (VideoGrabber.ASFDeinterlaceMode);

   edtProfileIndex.Text := IntToStr (VideoGrabber.ASFProfile);

   ///////////////////////// Player tab
   updPlayerSpeedRatio.Position := Trunc (VideoGrabber.PlayerSpeedRatio * 1000);
   edtPlayerSpeedRatio.Text := FormatFloat ('0.0', VideoGrabber.PlayerSpeedRatio);

   updPlayerFastSeekSpeed.Position := VideoGrabber.PlayerFastSeekSpeedRatio;
   edtPlayerFastSeekSpeed.Text := IntToStr (VideoGrabber.PlayerFastSeekSpeedRatio);

   btnAutoPlay.Checked := VideoGrabber.AutoStartPlayer;
   chkPlayerAudioRendering.Checked := VideoGrabber.PlayerAudioRendering;
   chkUseClock.Checked := VideoGrabber.UseClock;
   chkRefreshPausedDisplay.Checked := VideoGrabber.PlayerRefreshPausedDisplay;

   ///////////////////////// Frame grabber tab
   edtAVIAutoFilePrefix.Text := VideoGrabber.AutoFilePrefix;
   rgdFrameGrabberFormat.ItemIndex := Integer (VideoGrabber.FrameGrabberRGBFormat);
   rgdFrameGrabber.ItemIndex := integer (VideoGrabber.FrameGrabber);
   rdgAutoFileName.ItemIndex := integer (VideoGrabber.AutoFileName);
   edtFrameCaptureWidth.Text := IntToStr (VideoGrabber.FrameCaptureWidth);
   edtFrameCaptureHeight.Text := IntToStr (VideoGrabber.FrameCaptureHeight);

   ///////////////////////// Frame capture tab
   edtBurstCount.Text := IntToStr (VideoGrabber.BurstCount);
   edtBurstInterval.Text := IntToStr (VideoGrabber.BurstInterval);
   tbrCaptureZoomSize.Position := VideoGrabber.FrameCaptureZoomSize;

   ///////////////////////// Motion detection tab

   chkMotionDetectionEnabled.Checked := Videograbber.MotionDetector_Enabled;
   chkCompareRed.Checked := VideoGrabber.MotionDetector_CompareRed;
   chkCompareGreen.Checked := VideoGrabber.MotionDetector_CompareGreen;
   chkCompareBlue.Checked := VideoGrabber.MotionDetector_CompareBlue;
   chk_GreyScale.Checked := VideoGrabber.MotionDetector_GreyScale;
   chkReduceVideoNoise.Checked := VideoGrabber.MotionDetector_ReduceVideoNoise;
   edtGrid.Text := VideoGrabber.MotionDetector_Grid;
   mmoSensitivityGrid.Text := VideoGrabber.MotionDetector_Get2DTextGrid;
   edtGridColCount.Text := IntToStr (VideoGrabber.MotionDetector_GridXCount);
   edtGridRowCount.Text := IntToStr (VideoGrabber.MotionDetector_GridYCount);
   chkTriggered.Checked := VideoGrabber.MotionDetector_Triggered;

   ///////////////////////// TV Tuner tab
   rdgTunerMode.ItemIndex := Integer (VideoGrabber.TunerMode);
   rdgTunerInputType.ItemIndex := Integer (VideoGrabber.TVTunerInputType);
   edtCountryCode.Text := IntToStr (VideoGrabber.TVCountryCode);
   edtTVChannel.Text := IntToStr (VideoGrabber.TVChannel);
   chkEnableFrequencyOverrides.Checked := VideoGrabber.TVUseFrequencyOverrides;

   ///////////////////////// Overlay tab
   rdgImageOverlaySelector.ItemIndex := VideoGrabber.ImageOverlaySelector;
   rdgImageOverlaySelectorClick (Self);

   rdgTextOverlaySelector.ItemIndex := VideoGrabber.TextOverlay_Selector;
   rdgTextOverlaySelectorClick (Self);

   ///////////////////////// Video processing tab
   rdgVideoRotation.ItemIndex := Integer (VideoGrabber.VideoProcessing_Rotation);
   tbrBrightness.Position := - VideoGrabber.VideoProcessing_Brightness;
   tbrConstrast.Position := - VideoGrabber.VideoProcessing_Contrast;
   tbrSaturation.Position := - VideoGrabber.VideoProcessing_Saturation;
   tbrHue.Position := VideoGrabber.VideoProcessing_Hue;
   edtCustomRotationAngle.Text := FormatFloat ('0.00', VideoGrabber.VideoProcessing_RotationCustomAngle);

   rdgDeinterlacing.ItemIndex := Integer (VideoGrabber.VideoProcessing_Deinterlacing);
   chkGreyScale.Checked := VideoGrabber.VideoProcessing_GrayScale;
   chkInvertColors.Checked := VideoGrabber.VideoProcessing_InvertColors;
   chkFlipVertical.Checked := VideoGrabber.VideoProcessing_FlipVertical;
   chkFlipHorizontal.Checked := VideoGrabber.VideoProcessing_FlipHorizontal;

   chkCroppingEnabled.Checked := VideoGrabber.Cropping_Enabled;
   chkCroppingOutbounds.Checked := VideoGrabber.Cropping_Outbounds;
   edtCroppingWidth.Text := IntToStr (VideoGrabber.Cropping_Width);
   edtCroppingHeight.Text := IntToStr (VideoGrabber.Cropping_Height);
   trkCroppingZoom.Position := Round (VideoGrabber.Cropping_Zoom * 100);

   // trkCroppingX.Max and trkCroppingY.Max are will be set from the OnResizeVideo event
   trkCroppingY.Position := VideoGrabber.Cropping_Y;
   trkCroppingX.Position := VideoGrabber.Cropping_X;

   ///////////////////////// Display tab
   chkVideoVisibleWhenStopped.Checked := VideoGrabber.VideoVisibleWhenStopped;
   chkBorder.Checked := VideoGrabber.BorderStyle = bsSingle;
   chkTransparency.Checked := VideoGrabber.ColorKeyEnabled;
   rdgVideoRenderer.ItemIndex := Integer (VideoGrabber.VideoRenderer);
   RefreshDisplayOptions;

   ///////////////////////// reencoding tab
   chkWMVOutput.Checked := VideoGrabber.Reencoding_WMVOutput;
   chkIncludeVideoStream.Checked := VideoGrabber.Reencoding_IncludeVideoStream;
   chkIncludeAudioStream.Checked := VideoGrabber.Reencoding_IncludeAudioStream ;
   chkUseFrameGrabber.Checked := VideoGrabber.Reencoding_UseFrameGrabber;
   chkUseCurrentVideoCompressor.Checked := VideoGrabber.Reencoding_UseVideoCompressor;
   chkUseCurrentAudioCompressor.Checked := VideoGrabber.Reencoding_UseAudioCompressor;
   edtReencStartTime.Text := IntToStr (VideoGrabber.Reencoding_StartTime);
   edtReencStopTime.Text := IntToStr (VideoGrabber.Reencoding_StopTime);
   edtReencStartFrame.Text := IntToStr (VideoGrabber.Reencoding_StartFrame);
   edtReencStopFrame.Text := IntToStr (VideoGrabber.Reencoding_StopFrame);
   rdgReencodingMethod.ItemIndex := Integer (VideoGrabber.Reencoding_Method);

end;

////////////////////////////////////////////////////////////////////////////////
//                            VIDEO DEVICE TAB
////////////////////////////////////////////////////////////////////////////////

procedure TfrmMainForm.VideoGrabberVideoDeviceSelected(Sender: TObject);
begin
   // from this event update the properties that depend of the current video capture device.
   // This event occurs when you assign a new value to the VideoDevice property.

   AssignListToComboBox (cboAnalogVideoStandard, VideoGrabber.AnalogVideoStandards, integer (VideoGrabber.AnalogVideoStandard));
   AssignListToComboBox (cboVideoSizes, VideoGrabber.VideoSizes, VideoGrabber.VideoSize);
   AssignListToComboBox (cboVideoSubtypes, VideoGrabber.VideoSubtypes, VideoGrabber.VideoSubtype);
   AssignListToComboBox (cboVideoInputs, VideoGrabber.VideoInputs, integer (VideoGrabber.VideoInput));

   RefreshDeviceControls;
   RefreshDisplayOptions;
end;

procedure TfrmMainForm.cboVideoSourceChange(Sender: TObject);
begin
  case cboVideoSource.ItemIndex of
     0: VideoGrabber.VideoSource := vs_VideoCaptureDevice;
     1: VideoGrabber.VideoSource := vs_ScreenRecording;
     2: VideoGrabber.VideoSource := vs_VideoFileOrURL;
     3: VideoGrabber.VideoSource := vs_JPEGsOrBitmaps;
     4: VideoGrabber.VideoSource := vs_IPCamera;
  else
     mmoLog.Lines.Add ('this option is not demonstrated in this demo');
  end;
end;

procedure TfrmMainForm.cboVideoDevicesChange(Sender: TObject);
begin
   VideoGrabber.VideoDevice := cboVideoDevices.ItemIndex;
   // when selecting another video capture device, the OnVideoDeviceSelected event occurs.
   // be sure to refresh all your device-dependent controls from the OnVideoDeviceSelected event.
end;

procedure TfrmMainForm.btnStartPreviewClick(Sender: TObject);
begin
   VideoGrabber.StartPreview;
end;

procedure TfrmMainForm.btnStopPreviewClick(Sender: TObject);
begin
   VideoGrabber.StopPreview;
end;

procedure TfrmMainForm.btnAutoRefreshPreviewClick(Sender: TObject);
begin
   VideoGrabber.AutoRefreshPreview := btnAutoRefreshpreview.Checked;
end;

procedure TfrmMainForm.cboVideoInputsChange(Sender: TObject);
begin
   VideoGrabber.VideoInput := cboVideoInputs.ItemIndex;
end;

procedure TfrmMainForm.cboVideoSizesChange(Sender: TObject);
begin
   VideoGrabber.VideoSize := cboVideoSizes.ItemIndex;
end;

procedure TfrmMainForm.cboVideoSubtypesChange(Sender: TObject);
begin
   VideoGrabber.VideoSubtype := cboVideoSubtypes.ItemIndex;
end;

procedure TfrmMainForm.cboAnalogVideoStandardChange(Sender: TObject);
begin
   VideoGrabber.AnalogVideoStandard := cboAnalogVideoStandard.ItemIndex;
end;

procedure TfrmMainForm.chkSetLogoClick(Sender: TObject);
begin
   if ChkSetLogo.Checked then begin
      ImgLogo.Visible := False;
      VideoGrabber.SetLogoFromTImage (ImgLogo);
      VideoGrabber.LogoLayout := lg_Stretched;
      VideoGrabber.LogoDisplayed := True;
   end
   else begin
      VideoGrabber.LogoDisplayed := False;
   end;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -