从网络摄像头以 1080p 在窗口 IOT 上录制
本文关键字:IOT 窗口 网络 摄像头 1080p | 更新日期: 2024-10-30 19:45:03
在这个例子之后,我注意到视频的分辨率是640 * 480。代码完美运行。我的网络摄像头是 1080p 型号。如何让树莓派以 1080p 保存视频?
这是直接来自示例的相机初始化代码,以及录制视频的代码。我找不到设置分辨率的任何位置。
private async void initVideo_Click(object sender, RoutedEventArgs e)
{
// Disable all buttons until initialization completes
SetInitButtonVisibility(Action.DISABLE);
SetVideoButtonVisibility(Action.DISABLE);
SetAudioButtonVisibility(Action.DISABLE);
try
{
if (mediaCapture != null)
{
// Cleanup MediaCapture object
if (isPreviewing)
{
await mediaCapture.StopPreviewAsync();
captureImage.Source = null;
playbackElement.Source = null;
isPreviewing = false;
}
if (isRecording)
{
await mediaCapture.StopRecordAsync();
isRecording = false;
recordVideo.Content = "Start Video Record";
recordAudio.Content = "Start Audio Record";
}
mediaCapture.Dispose();
mediaCapture = null;
}
status.Text = "Initializing camera to capture audio and video...";
// Use default initialization
mediaCapture = new MediaCapture();
await mediaCapture.InitializeAsync();
// Set callbacks for failure and recording limit exceeded
status.Text = "Device successfully initialized for video recording!";
mediaCapture.Failed += new MediaCaptureFailedEventHandler(mediaCapture_Failed);
mediaCapture.RecordLimitationExceeded += new Windows.Media.Capture.RecordLimitationExceededEventHandler(mediaCapture_RecordLimitExceeded);
// Start Preview
previewElement.Source = mediaCapture;
await mediaCapture.StartPreviewAsync();
isPreviewing = true;
status.Text = "Camera preview succeeded";
// Enable buttons for video and photo capture
SetVideoButtonVisibility(Action.ENABLE);
// Enable Audio Only Init button, leave the video init button disabled
audio_init.IsEnabled = true;
}
catch (Exception ex)
{
status.Text = "Unable to initialize camera for audio/video mode: " + ex.Message;
}
}
private async void recordVideo_Click(object sender, RoutedEventArgs e)
{
try
{
takePhoto.IsEnabled = false;
recordVideo.IsEnabled = false;
playbackElement.Source = null;
if (recordVideo.Content.ToString() == "Start Video Record")
{
takePhoto.IsEnabled = false;
status.Text = "Initialize video recording";
String fileName;
fileName = VIDEO_FILE_NAME;
recordStorageFile = await Windows.Storage.KnownFolders.VideosLibrary.CreateFileAsync(fileName, Windows.Storage.CreationCollisionOption.GenerateUniqueName);
status.Text = "Video storage file preparation successful";
MediaEncodingProfile recordProfile = null;
recordProfile = MediaEncodingProfile.CreateMp4(Windows.Media.MediaProperties.VideoEncodingQuality.Auto);
await mediaCapture.StartRecordToStorageFileAsync(recordProfile, recordStorageFile);
recordVideo.IsEnabled = true;
recordVideo.Content = "Stop Video Record";
isRecording = true;
status.Text = "Video recording in progress... press ''Stop Video Record'' to stop";
}
else
{
takePhoto.IsEnabled = true;
status.Text = "Stopping video recording...";
await mediaCapture.StopRecordAsync();
isRecording = false;
var stream = await recordStorageFile.OpenReadAsync();
playbackElement.AutoPlay = true;
playbackElement.SetSource(stream, recordStorageFile.FileType);
playbackElement.Play();
status.Text = "Playing recorded video" + recordStorageFile.Path;
recordVideo.Content = "Start Video Record";
}
}
catch (Exception ex)
{
if (ex is System.UnauthorizedAccessException)
{
status.Text = "Unable to play recorded video; video recorded successfully to: " + recordStorageFile.Path;
recordVideo.Content = "Start Video Record";
}
else
{
status.Text = ex.Message;
Cleanup();
}
}
finally
{
recordVideo.IsEnabled = true;
}
}
查看"VideoDeviceController.GetAvailableMediaStreamProperties"和"VideoDeviceController.SetMediaStreamPropertiesAsync"以获取可用分辨率并设置视频捕获设备的分辨率。
http://msdn.microsoft.com/en-us/library/windows/apps/windows.media.devices.videodevicecontroller.getavailablemediastreamproperties.aspxhttp://msdn.microsoft.com/en-us/library/windows/apps/windows.media.devices.videodevicecontroller.setmediastreampropertiesasync.aspx