Search Unity

  1. Unity 2019.2 is now released.
    Dismiss Notice

VideoCapture - reenable camera mode after first recording

Discussion in 'Windows Mixed Reality' started by reddo, Jan 1, 2018.

  1. reddo

    reddo

    Joined:
    Jul 1, 2015
    Posts:
    30
    I'm using the script for VideoCapture in the documentation here
    https://developer.microsoft.com/en-us/windows/mixed-reality/locatable_camera_in_unity

    The video captures and saves fine on first recording.
    I'm then trying to reenable the camera to perform another capture calling the below method on tap, which is the same as the
    Start method

    Code (CSharp):
    1. public void RestartCamera()
    2.     {
    3.         VideoCapture.CreateAsync(false, OnVideoCaptureCreated);
    4.     }
    It appears to create another VideoCapture Instance. However, when going to record again the debug log in VS
    states:

    Video Mode has already been started.

    (Filename: C:\buildslave\unity\build\Runtime/VR/HoloLens/WebCam/VideoCapture.cpp Line: 1113)


    The camera is not yet ready. (my own debug log when can't record)

    (Filename: C:\buildslave\unity\build\artifacts/generated/Metro/runtime/DebugBindings.gen.cpp Line: 51)

    It's also the same PhotoCapture where another image can't be taken and thought the issue might be to do with
    https://forums.hololens.com/discuss...-failure-failed-capturing-photo-hr-0x887a0005
    However Spatial Understanding is not enabled in my scene.

    Using Unity 2017.3.0f3
    So, just wondering if the right action is being called to allow more than one video to be recorded.
     
  2. Unity_Wesley

    Unity_Wesley

    Unity Technologies

    Joined:
    Sep 17, 2015
    Posts:
    556
    If you want to use video capture this why you need to call the VideoCapture.CreateAsync(false, OnVideoCaptureCreated) when a tap occurs, then have some sort of check to tell if your recording. Then you need to call the stop method on a tap or after another way.

    // The user has indicated to stop recording
    void StopRecordingVideo()
    {
    m_VideoCapture.StopRecordingAsync(OnStoppedRecordingVideo);
    }

    This will stop the recording and preform the clean up, you can only have one video or photo capture object running at one time
     
  3. reddo

    reddo

    Joined:
    Jul 1, 2015
    Posts:
    30
    Thanks for the info. The recording starts and stops fine on first tap. Clean up is performed as per below
    Code (CSharp):
    1.  public void StopRecording()
    2.     {
    3.             Debug.Log("Stopped Recording Video");
    4.             m_VideoCapture.StopRecordingAsync(OnVideoModeStopped);
    5.     }
    6.  
    7. private void OnVideoModeStopped(VideoCapture.VideoCaptureResult result)
    8.     {
    9.         m_VideoCapture.Dispose();
    10.         m_VideoCapture = null;
    11.  
    12.         Info.text = "Camera off";
    13.     }
    14.  
    It's when calling VideoCapture.CreateAsync(false, OnVideoCaptureCreated) on tap again that the issue occurs where Video Mode still appears to be active according to VS debugging log.
    Am therefore wondering if there's any clean up happening at all. I've tested with and without the Dispose() and null settings and the outcome is the same.
     
  4. akil-active-ai

    akil-active-ai

    Joined:
    Apr 11, 2018
    Posts:
    3
    I had the video capture start and stop to work perfectly fine in a few runs of the build.
    But now, It seems Video capture stop is just not stopping when I call the function. It continues to record and there is no log saying why it cant stop the capture. I didnt change anything on the scripts...
     
  5. kcholmin

    kcholmin

    Joined:
    Feb 25, 2019
    Posts:
    1
    Hope I'm not too late.

    I ran across your question and tried it myself and came up with solution:

    Try
    videocapture.StartVideoModeAsync()

    e.g.
    m_VideoCapture.StartVideoModeAsync(cam, VideoCapture.AudioState.ApplicationAndMicAudio,OnStartedVideoCaptureMode);


    Note that it takes 3 parameters. I would recommend saving camera parameters as global variable in StartVideoCaptureTest() function (function provided in https://docs.unity3d.com/Manual/windowsholographic-videocapture.html ) and call camera parameter value when resuming it.

    Refer to following doc.
    https://docs.unity3d.com/560/Docume....WebCam.VideoCapture.StartVideoModeAsync.html

    Hope this helps