Welcome Guest! To enable all features, please Login or Register.

Notification

Icon
Error

Options
View
Last Go to last post Unread Go to first unread post
#1 Posted : Monday, November 11, 2019 2:20:19 PM(UTC)

Amin  
Amin

Groups: Manager, Tech Support
Posts: 367

Was thanked: 1 time(s) in 1 post(s)

File Attachment(s):
CsWpfMm20Dvr.zip (11kb) downloaded 50 time(s).

Attached C# project shows how to continuously capture video using the DVR module of LEADTOOLS Multimedia, then save the user-selected last portion of the video upon stopping.

Here are the main parts of the project:

  • Using our Multimedia Capture control with WPF:
    This is done using the System.Windows.Forms.Integration.WindowsFormsHost control

  • Using a video source:
    Any video capture source can be used such as web cams and frame grabbers, but the project specifically looks for the LEAD Screen Capture filter using this code:
    Code:
    // Device name for the LEAD Screen Capture Filter video source
    string LEADScreenCapture = @"@device:sw:{860BB310-5D01-11D0-BD3B-00A0C911CE86}\{E2B7DE13-38C5-11D5-91F6-00104BDB8FF9}";
    _capturectrl.VideoDevices[LEADScreenCapture].Selected = true;
    

    To use a different video source, select it from the list in CaptureCtrl.VideoDevices.

  • Specifying DVR output and using suitable MPEG2 compression:
    Setting the output DVR format and setting up the circular buffers that will store the video data. Also, to be able to copy the video data at the end and produce a valid MPG file, suitable compression should be used. The code to do both is this:
    Code:
    
    _capturectrl.TargetFormats.DVRTransport.Selected = true;
    string recVideoComp = _capturectrl.TargetFormats.DVRTransport.RecommendedVideoCompressor;
    _capturectrl.TargetFormat = TargetFormatType.DVRTransport;
    if (recVideoComp != string.Empty)
       _capturectrl.VideoCompressors[recVideoComp].Selected = true;
    if (_capturectrl.VideoCompressors.Mpeg2.Selected == true)
    {
       LMMPEG2Encoder mpeg2Encoder = _capturectrl.GetSubObject(CaptureObject.VideoCompressor) as LMMPEG2Encoder;
       if (mpeg2Encoder != null)
       {
          mpeg2Encoder.EncodingThreads = eMpeg2EncodingThreads.MPEG2_THREAD_AUTO;
          mpeg2Encoder.VideoFormat = eMPEG2VIDEOFORMAT.MPEG2_VF_NTSC;
          System.Runtime.InteropServices.Marshal.ReleaseComObject(mpeg2Encoder);
       }
    }
    _capturectrl.TargetFile = @"c:\temp\capture.lbl";
    _capturectrl.ReadyCapture(CaptureMode.Video| CaptureMode.InhibitRun);
    _dvrSink = _capturectrl.GetSubObject(CaptureObject.Sink) as ILMDVRSink;
    if (_dvrSink != null)
    {
       double dBuffSize = 102400000;  // 100 MB 
       int lFileCount = 8;  // 8 buffer files 
       _dvrSink.StartChangingAttributes();
       _dvrSink.FolderCount = 1;
       _dvrSink.set_FolderName(0, @"c:\temp");
       _dvrSink.SetBufferSize(0, lFileCount, dBuffSize);
       _dvrSink.StopChangingAttributes(false);
       string bufferFolder = _dvrSink.BaseName;
    }
    

  • Determining video time to save based on video data size:
    The DVR buffers provide the programmer with amount of data saved in bytes rather than duration of saved video. The project uses a timer to keep track of how much time has passed and obtains the data size using the ILMDVRSink.GetAvailabilityInfo(), then calculates the value:
    Code:
    offsetPerSecond = deltaOffset / deltaTime;

    This is later used to calculate number of seconds requested to be saved as:
    (offsetPerSecond * seconds)

    Note: In order to obtain valid MPEG data, the ILMDVRSink.GetFragmentAlignment() method is used to adjust the requested offsets. This means there could be a small variation between requested number of seconds and actual length of stored video.

  • Unlocking the toolkit:
    Before deploying your code, you need to obtain a valid unlock key from our licensing team to use with the MultimediaSupport.UnlockModule() method.


See also:


Keywords: Multimedia, Video, Screen Capture, DVR, C#, WPF, VS2017

Edited by moderator Monday, November 18, 2019 3:29:15 PM(UTC)  | Reason: Not specified

Amin Dodin

Senior Support Engineer
LEAD Technologies, Inc.
LEAD Logo
 

Try the latest version of LEADTOOLS for free for 60 days by downloading the evaluation: https://www.leadtools.com/downloads

Wanna join the discussion? Login to your LEADTOOLS Support accountor Register a new forum account.

You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.

Powered by YAF.NET | YAF.NET © 2003-2024, Yet Another Forum.NET
This page was generated in 0.077 seconds.