我對如何控制MediaCapture視頻的大小有疑問。在MediaCapture記錄中,視頻的默認大小顯示爲屏幕大小。如何根據WinRT中的自定義大小調整視頻大小
例如,當我將CaptureElement的寬度設置爲480,將CaptureElement的高度設置爲320時,我可以看到視頻區域的預覽是480 * 320。但是,當我將它記錄到文件並停止時,文件中視頻的大小就是屏幕的大小(視圖區域爲768 * 1280)。如何獲得文件中的視頻大小爲320 * 240?
主要代碼是:
DeviceInformation cameraDevice = await FindDeviceInfo(panel);
if (cameraDevice == null)
{
return;
}
var mediaInitSettings = new MediaCaptureInitializationSettings { VideoDeviceId = cameraDevice.Id };
_encodingProfile = MediaEncodingProfile.CreateMp4(VideoEncodingQuality.Qvga);
if (_encodingProfile.Video != null)
{
_encodingProfile.Video.PixelAspectRatio.Numerator = 4;
_encodingProfile.Video.PixelAspectRatio.Denominator = 3;
}
var isInitialized = false;
try
{
_mediaCapture.VideoDeviceController.PrimaryUse = CaptureUse.Video;
await _mediaCapture.InitializeAsync(mediaInitSettings);
isInitialized = true;
var formatSelector = new Func<VideoEncodingProperties, bool>(ep => ep.Height * ep.Width == 640 * 480 && string.Equals(ep.Subtype, "nv12", StringComparison.OrdinalIgnoreCase));
var recordFormat = _mediaCapture.VideoDeviceController.GetAvailableMediaStreamProperties(MediaStreamType.VideoRecord).OfType<VideoEncodingProperties>().FirstOrDefault(formatSelector);
var previewFormat = _mediaCapture.VideoDeviceController.GetAvailableMediaStreamProperties(MediaStreamType.VideoPreview).OfType<VideoEncodingProperties>().FirstOrDefault(formatSelector);
if (previewFormat != null)
await
_mediaCapture.VideoDeviceController.SetMediaStreamPropertiesAsync(MediaStreamType.VideoPreview,
previewFormat);
if (recordFormat != null)
await
_mediaCapture.VideoDeviceController.SetMediaStreamPropertiesAsync(MediaStreamType.VideoRecord,
recordFormat);
}
catch (Exception ex)
{
Debug.WriteLine("Exception when initializing MediaCapture with {0}: {1}", cameraDevice.Id, ex.ToString());
}
我試圖用MediaComposition,但沒有關於調整大小的方法,這將有助於我解決問題的信息。我該如何解決它?
鏈接到預覽的圖象是[1]
[1]:http://i.stack.imgur.com/5dnIi.png結果可以看到更多的區域。
我編輯過的語法和段落格式使郵件更容易閱讀和理解。 – paisanco