且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何统一使用网络摄像机捕获视频?

更新时间:2023-01-06 11:12:10

您应该尝试看一下该线程

You should try taking a look at this thread here. Where it goes into detail on how to record a video with HoloLens as well as how to take a photo. Also make sure you have the WebCam and microphone capabilities set. Also if you are trying to save it, make sure you have the Videos Library capability as well.

OnVideoCaptureCreated:

OnVideoCaptureCreated:

void OnVideoCaptureCreated (VideoCapture videoCapture)
{
   if (videoCapture != null)
   {
       m_VideoCapture = videoCapture;

       Resolution cameraResolution = VideoCapture.SupportedResolutions.OrderByDescending((res) => res.width * res.height).First();
       float cameraFramerate = VideoCapture.GetSupportedFrameRatesForResolution(cameraResolution).OrderByDescending((fps) => fps).First();

       CameraParameters cameraParameters = new CameraParameters();
       cameraParameters.hologramOpacity = 0.0f;
       cameraParameters.frameRate = cameraFramerate;
       cameraParameters.cameraResolutionWidth = cameraResolution.width;
       cameraParameters.cameraResolutionHeight = cameraResolution.height;
       cameraParameters.pixelFormat = CapturePixelFormat.BGRA32;

       m_VideoCapture.StartVideoModeAsync(cameraParameters,
                                           VideoCapture.AudioState.None,
                                           OnStartedVideoCaptureMode);
   }
   else
   {
       Debug.LogError("Failed to create VideoCapture Instance!");
   }
}

OnStartVideoCaptureMode:

OnStartVideoCaptureMode:

void OnStartedVideoCaptureMode(VideoCapture.VideoCaptureResult result)
{
   if (result.success)
   {
       string filename = string.Format("MyVideo_{0}.mp4", Time.time);
       string filepath = System.IO.Path.Combine(Application.persistentDataPath, filename);

       m_VideoCapture.StartRecordingAsync(filepath, OnStartedRecordingVideo);
   }
}

OnStartRecordingVideo:

OnStartRecordingVideo:

void OnStartedRecordingVideo(VideoCapture.VideoCaptureResult result)
{
   Debug.Log("Started Recording Video!");
   // We will stop the video from recording via other input such as a timer or a tap, etc.
}

StopRecordingVideo:

StopRecordingVideo:

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

OnStopRecordingVideo:

OnStopRecordingVideo:

void OnStoppedRecordingVideo(VideoCapture.VideoCaptureResult result)
{
   Debug.Log("Stopped Recording Video!");
   m_VideoCapture.StopVideoModeAsync(OnStoppedVideoCaptureMode);
}

void OnStoppedVideoCaptureMode(VideoCapture.VideoCaptureResult result)
{
   m_VideoCapture.Dispose();
   m_VideoCapture = null;
}