public async Task StartRecordingAsync() { _randomAccessStream = new InMemoryRandomAccessStream(); _mediaRecording = await MediaCapture.PrepareLowLagRecordToStreamAsync(MediaEncodingProfile.CreateMp4(VideoEncodingQuality.HD720p), _randomAccessStream); await _mediaRecording.StartAsync(); }
private async void TakeVideoAsync() { mediaCapture = new MediaCapture(); await mediaCapture.InitializeAsync(); if (isVideoStarted == false) { var myVideos = await Windows.Storage.StorageLibrary.GetLibraryAsync(Windows.Storage.KnownLibraryId.Videos); StorageFile file = await myVideos.SaveFolder.CreateFileAsync("video.mp4", CreationCollisionOption.GenerateUniqueName); _mediaRecording = await mediaCapture.PrepareLowLagRecordToStorageFileAsync( MediaEncodingProfile.CreateMp4(VideoEncodingQuality.Auto), file); await _mediaRecording.StartAsync(); isVideoStarted = true; } else { await _mediaRecording.StopAsync(); await _mediaRecording.FinishAsync(); } }
public async Task StartAsync() { m_isRecording = true; if (m_isVideo) { var profile = MediaEncodingProfile.CreateMp4(VideoEncodingQuality.Auto); var rotationAngle = CameraRotationHelper.ConvertSimpleOrientationToClockwiseDegrees(_rotationHelper.GetCameraCaptureOrientation()); profile.Video.Properties.Add(new Guid("C380465D-2271-428C-9B83-ECEA3B4A85C1"), PropertyValue.CreateInt32(rotationAngle)); m_lowLag = await m_mediaCapture.PrepareLowLagRecordToStorageFileAsync(profile, m_file); await m_lowLag.StartAsync(); } else { var wavEncodingProfile = MediaEncodingProfile.CreateWav(AudioEncodingQuality.High); wavEncodingProfile.Audio.BitsPerSample = 16; wavEncodingProfile.Audio.SampleRate = 48000; wavEncodingProfile.Audio.ChannelCount = 1; m_opusSink = await OpusCodec.CreateMediaSinkAsync(m_file); await m_mediaCapture.StartRecordToCustomSinkAsync(wavEncodingProfile, m_opusSink); } }
private async Task RecStart() { var myVideos = await Windows.Storage.StorageLibrary.GetLibraryAsync(Windows.Storage.KnownLibraryId.Videos); StorageFile file = await myVideos.SaveFolder.CreateFileAsync("video.mp4", CreationCollisionOption.GenerateUniqueName); _mediaRecording = await mediaCapture.PrepareLowLagRecordToStorageFileAsync( MediaEncodingProfile.CreateMp4(VideoEncodingQuality.Auto), file); await _mediaRecording.StartAsync(); }
private async void btnPublish_Checked(object sender, RoutedEventArgs e) { try { await ApplyTargetChannels(); //RTMP Publish specific Code var inputprof = _deviceManager.GetInputProfile(); _publishsession = new RTMPPublishSession(_deviceManager.PublishProfiles); //handle events (if needed) _publishsession.PublishFailed += OnPublishFailed; _publishsession.SessionClosed += OnSessionClosed; //get the sink var sink = await _publishsession.GetCaptureSinkAsync(); if (_deviceManager.EnableLowLatency) { _lowlagCapture = await _deviceManager.CurrentCapture.PrepareLowLagRecordToCustomSinkAsync(inputprof, sink); await _lowlagCapture.StartAsync(); } else { await _deviceManager.CurrentCapture.StartRecordToCustomSinkAsync(inputprof, sink); } if (_displayRequest == null) { _displayRequest = new DisplayRequest(); _displayRequest.RequestActive(); } _deviceManager.IsPublishing = true; sessionduration = TimeSpan.FromSeconds(0); _clockTimer = new Timer(new TimerCallback((o) => { this.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () => { sessionduration = sessionduration.Add(TimeSpan.FromMilliseconds(500)); tbClock.Text = sessionduration.ToString(@"hh\:mm\:ss\:fff"); }); }), null, 0, 500); } catch (Exception Ex) { } }
private async void ButtonBase_OnClick(object sender, RoutedEventArgs e) { mediaCapture = new MediaCapture(); await mediaCapture.InitializeAsync(); storageFolder = ApplicationData.Current.LocalFolder; storageFile = await storageFolder.CreateFileAsync("test.mp3", CreationCollisionOption.GenerateUniqueName); lowLagMedia = await mediaCapture.PrepareLowLagRecordToStorageFileAsync( MediaEncodingProfile.CreateMp3(AudioEncodingQuality.High), storageFile); await lowLagMedia.StartAsync(); }
async Task Start() { md = new MediaCapture(); await md.InitializeAsync(); var video = await Windows.Storage.StorageLibrary.GetLibraryAsync(Windows.Storage.KnownLibraryId.Videos); StorageFile file = await video.SaveFolder.CreateFileAsync("video.mp4", CreationCollisionOption.GenerateUniqueName); recorder = await md.PrepareLowLagRecordToStorageFileAsync( MediaEncodingProfile.CreateMp4(VideoEncodingQuality.Auto), file); await recorder.StartAsync(); }
private async void Initialize() { this.Loaded += InstantReplayPage_Loaded; viewModel = new InstantReplayPageViewModel(); viewModel.Initialize(inkCanvas); viewModel.TogglePlayPauseEvent += TogglePlayPause; Scrubber.ValueChanged += Scrubber_ValueChanged; var file = await viewModel.StartCapture(null); //var profiles = MediaCapture.FindAllVideoProfiles(cameraId); MediaCapture capture = new MediaCapture(); var devices = await Windows.Devices.Enumeration.DeviceInformation.FindAllAsync(Windows.Devices.Enumeration.DeviceClass.VideoCapture); var captureInitSettings = new MediaCaptureInitializationSettings(); var profile = MediaEncodingProfile.CreateWmv(VideoEncodingQuality.Auto); captureInitSettings.StreamingCaptureMode = StreamingCaptureMode.Video; captureInitSettings.VideoDeviceId = devices[0].Id; mediaCapture = new MediaCapture(); await mediaCapture.InitializeAsync(captureInitSettings); storageFile = await KnownFolders.VideosLibrary.CreateFileAsync("InstantReplayCapture.wmv", CreationCollisionOption.GenerateUniqueName); StorageApplicationPermissions.FutureAccessList.Add(storageFile); storageFileStream = await storageFile.OpenStreamForWriteAsync(); fileStream = new DVRRandomAccessStream(storageFileStream); lowLagRecord = await mediaCapture.PrepareLowLagRecordToStreamAsync(profile, fileStream); await lowLagRecord.StartAsync(); VideoPlayer.SetSource(fileStream.PlaybackStream, storageFile.ContentType); VideoPlayer.PartialMediaFailureDetected += VideoPlayer_PartialMediaFailureDetected; VideoPlayer.MediaFailed += VideoPlayer_MediaFailed; VideoPlayer.CurrentStateChanged += (s, e) => { Debug.WriteLine("State: " + VideoPlayer.CurrentState); }; VideoPlayer.MediaEnded += VideoPlayer_MediaEnded; this.DataContext = viewModel; }
private async void CaptureStartButton_Click(object sender, RoutedEventArgs e) { if (!IsCaptureEnabled) { return; } IsCaptureEnabled = false; await _mediaCapture.StartPreviewAsync(); _video = await ApplicationData.Current.LocalFolder.CreateFileAsync($"{Guid.NewGuid()}.mp4"); _mediaRecording = await _mediaCapture.PrepareLowLagRecordToStorageFileAsync( MediaEncodingProfile.CreateMp4(VideoEncodingQuality.Auto), _video); await _mediaRecording.StartAsync(); }
private async void MediaRecordbt_Click(object sender, RoutedEventArgs e) { if (cameraDevice == null) { return; } var myVideos = await Windows.Storage.StorageLibrary.GetLibraryAsync(Windows.Storage.KnownLibraryId.Videos); StorageFile file = await myVideos.SaveFolder.CreateFileAsync("video.mp4", CreationCollisionOption.GenerateUniqueName); _mediaRecording = await _mediaCapture.PrepareLowLagRecordToStorageFileAsync(MediaEncodingProfile.CreateMp4(VideoEncodingQuality.Auto), file); await _mediaRecording.StartAsync(); StopBt.IsEnabled = true; MediaRecordbt.IsEnabled = false; }
public async Task StartAudioCapture() { mediaCapture = new MediaCapture(); await mediaCapture.InitializeAsync(); //<SnippetStartAudioCapture> mediaCapture.RecordLimitationExceeded += MediaCapture_RecordLimitationExceeded; var localFolder = Windows.Storage.ApplicationData.Current.LocalFolder; StorageFile file = await localFolder.CreateFileAsync("audio.mp3", CreationCollisionOption.GenerateUniqueName); _mediaRecording = await mediaCapture.PrepareLowLagRecordToStorageFileAsync( MediaEncodingProfile.CreateMp3(AudioEncodingQuality.High), file); await _mediaRecording.StartAsync(); //</SnippetStartAudioCapture> }
//</SnippetLowLagMediaRecording> public async Task StartVideoCapture() { //<SnippetRecordLimitationExceeded> mediaCapture.RecordLimitationExceeded += MediaCapture_RecordLimitationExceeded; //</SnippetRecordLimitationExceeded> //<SnippetStartVideoCapture> var myVideos = await Windows.Storage.StorageLibrary.GetLibraryAsync(Windows.Storage.KnownLibraryId.Videos); StorageFile file = await myVideos.SaveFolder.CreateFileAsync("video.mp4", CreationCollisionOption.GenerateUniqueName); _mediaRecording = await mediaCapture.PrepareLowLagRecordToStorageFileAsync( MediaEncodingProfile.CreateMp4(VideoEncodingQuality.Auto), file); await _mediaRecording.StartAsync(); //</SnippetStartVideoCapture> }
private async Task Start() { try { if (_state == STATE_PARTY) { return; } _mediaCapture = new MediaCapture(); await _mediaCapture.InitializeAsync(); _mediaCapture.Failed += MediaCapture_Failed; _mediaCapture.RecordLimitationExceeded += MediaCapture_RecordLimitationExceeded; _stream = new InMemoryRandomAccessStream(); _position = 0; _mediaRecording = await _mediaCapture.PrepareLowLagRecordToStreamAsync(MediaEncodingProfile.CreateWav(AudioEncodingQuality.High), _stream); await _mediaRecording.StartAsync(); _timer = new DispatcherTimer(); _timer.Tick += timer_Tick; _timer.Interval = new TimeSpan(0, 0, (int)((double)BUFFER_SAMPLES / (double)RATE)); _timer.Start(); MQTT_BROKER_ADDRESS = txtMQTTServer.Text; // create client instance _client = new MqttClient(MQTT_BROKER_ADDRESS); string clientId = "publisher";//Guid.NewGuid().ToString(); _client.Connect(clientId); _state = STATE_PARTY; } catch (Exception ex) { UpdateStatus(ex.Message); } }
protected async override void OnNavigatedTo(NavigationEventArgs e) { base.OnNavigatedTo(e); if (e.Parameter.ToString() == "rec") { _mediaCapture = new MediaCapture(); await _mediaCapture.InitializeAsync(); _mediaCapture.Failed += _mediaCapture_Failed; var myVideo = await Windows.Storage.StorageLibrary.GetLibraryAsync(Windows.Storage.KnownLibraryId.Videos); StorageFile file = await myVideo.SaveFolder.CreateFileAsync("video.mp4", CreationCollisionOption.GenerateUniqueName); _mediaRecording = await _mediaCapture.PrepareLowLagRecordToStorageFileAsync( MediaEncodingProfile.CreateMp4(VideoEncodingQuality.Auto), file); await _mediaRecording.StartAsync(); } }
internal async Task StartRecordingAsync(string projectName, int sequenceNumber) { bool hasCameraName = _CameraNameText != null && _CameraNameText.Length > 0; string baseName = hasCameraName ? _CameraNameText : this.Name; bool hasProjectName = projectName != null && projectName.Length > 0; string project = hasProjectName ? projectName : "RecordCamsProject"; string name = project + "\\" + sequenceNumber.ToString("000") + "_" + baseName + ".mp4"; var myVideos = await StorageLibrary.GetLibraryAsync(KnownLibraryId.Videos); savedVideoFile = await myVideos.SaveFolder.CreateFileAsync(name, CreationCollisionOption.GenerateUniqueName); _mediaRecording = await mediaCapture.PrepareLowLagRecordToStorageFileAsync( MediaEncodingProfile.CreateMp4(VideoEncodingQuality.HD1080p), savedVideoFile); mediaCapture.RecordLimitationExceeded += MediaCapture_RecordLimitationExceeded; await _mediaRecording.StartAsync(); }
private async void startVideoStreamBtn_Click(object sender, RoutedEventArgs e) { if (mediaCapture == null) { MessageDialog messageDialog = new MessageDialog("Please start camera"); await messageDialog.ShowAsync(); return; } var myVideos = await Windows.Storage.StorageLibrary.GetLibraryAsync(Windows.Storage.KnownLibraryId.Videos); StorageFile file = await myVideos.SaveFolder.CreateFileAsync("video.mp4", CreationCollisionOption.GenerateUniqueName); await mediaCapture.InitializeAsync(); mediaRecording = await mediaCapture.PrepareLowLagRecordToStorageFileAsync( MediaEncodingProfile.CreateMp4(VideoEncodingQuality.Auto), file); await mediaRecording.StartAsync(); }
private async Task StartRecording() { int index = 0; lock (this) { if (uploadingSoundFileIndexes.Count() > 0) { int max = uploadingSoundFileIndexes.Max(); while (index <= max) { if (!uploadingSoundFileIndexes.Contains(index)) { break; } index++; } } uploadingSoundFileIndexes.Add(index); } currentFileName = soundFileNamePrefix + index + soudFileNameExt; try { StorageFile file = await Windows.Storage.ApplicationData.Current.LocalFolder.CreateFileAsync(currentFileName, Windows.Storage.CreationCollisionOption.ReplaceExisting); mediaRecording = await audioCapture.PrepareLowLagRecordToStorageFileAsync( MediaEncodingProfile.CreateMp3(AudioEncodingQuality.High), file); await mediaRecording.StartAsync(); Debug.WriteLine("StartR - " + currentFileName); } catch (Exception ex) { AppendPlayLog("Start Recording Exception:", ex.Message); } }
public async Task StartAsync() { m_isRecording = true; if (m_isVideo) { var profile = MediaEncodingProfile.CreateMp4(VideoEncodingQuality.Vga); m_lowLag = await m_mediaCapture.PrepareLowLagRecordToStorageFileAsync(profile, m_file); await m_lowLag.StartAsync(); } else { var wavEncodingProfile = MediaEncodingProfile.CreateWav(AudioEncodingQuality.High); wavEncodingProfile.Audio.BitsPerSample = 16; wavEncodingProfile.Audio.SampleRate = 48000; wavEncodingProfile.Audio.ChannelCount = 1; m_opusSink = await OpusCodec.CreateMediaSinkAsync(m_file); await m_mediaCapture.StartRecordToCustomSinkAsync(wavEncodingProfile, m_opusSink); } }
private async void ToggleButton_Checked(object sender, RoutedEventArgs e) { var button = (ToggleButton)sender; // get storage folder if (storageFolder == null) { var msg = new MessageDialog("Please choose a folder first..."); await msg.ShowAsync(); button.IsChecked = false; return; } // check storage folder permissions try { var files = await storageFolder.GetFilesAsync(); } catch { var dialog = new MessageDialog( "The selected storage directory does not exist anymore or is not accessable. Please select a new directory.", "Directory not found or not enough permissions"); await dialog.ShowAsync(); button.IsChecked = false; return; } var requestSuspensionExtension = new ExtendedExecutionForegroundSession(); requestSuspensionExtension.Reason = ExtendedExecutionForegroundReason.Unspecified; var requestExtensionResult = await requestSuspensionExtension.RequestExtensionAsync(); // get storage files var time = DateTime.Now.ToString("yyyy-MM-dd-HH-mm-ss_"); var screenFile = await storageFolder.CreateFileAsync(time + "slides.mp4"); var webcamFile = await storageFolder.CreateFileAsync(time + "talkinghead.mp4"); var jsonFile = await storageFolder.CreateFileAsync(time + "meta.json"); // get encoder properties var frameRate = uint.Parse(((string)FrameRateComboBox.SelectedItem).Replace("fps", "")); var quality = (VideoEncodingQuality)Enum.Parse(typeof(VideoEncodingQuality), (string)QualityComboBox.SelectedItem, false); var useSourceSize = UseCaptureItemSizeCheckBox.IsChecked.Value; var temp = MediaEncodingProfile.CreateMp4(quality); uint bitrate = 2500000; var width = temp.Video.Width; var height = temp.Video.Height; // get capture item var picker = new GraphicsCapturePicker(); captureItem = await picker.PickSingleItemAsync(); if (captureItem == null) { button.IsChecked = false; return; } // use the capture item's size for the encoding if desired if (useSourceSize) { width = (uint)captureItem.Size.Width; height = (uint)captureItem.Size.Height; } // we have a screen resolution of more than 4K? if (width > 1920) { var v = width / 1920; width = 1920; height /= v; } // even if we're using the capture item's real size, // we still want to make sure the numbers are even. width = EnsureEven(width); height = EnsureEven(height); // tell the user we've started recording var originalBrush = MainTextBlock.Foreground; MainTextBlock.Foreground = new SolidColorBrush(Colors.Red); MainProgressBar.IsIndeterminate = true; button.IsEnabled = false; MainTextBlock.Text = "3"; await Task.Delay(1000); MainTextBlock.Text = "2"; await Task.Delay(1000); MainTextBlock.Text = "1"; await Task.Delay(1000); button.IsEnabled = true; MainTextBlock.Text = "● rec"; _timerCount = 0; _timer.Start(); try { // start webcam recording MediaEncodingProfile webcamEncodingProfile = null; if (AdaptBitrateCheckBox.IsChecked.Value) { var selectedItem = WebcamComboBox.SelectedItem as ComboBoxItem; var encodingProperties = (selectedItem.Tag as StreamPropertiesHelper); if (encodingProperties.Height > 720) { webcamEncodingProfile = MediaEncodingProfile.CreateMp4(VideoEncodingQuality.HD1080p); webcamEncodingProfile.Video.Bitrate = 8000000; } else if (encodingProperties.Height > 480) { webcamEncodingProfile = MediaEncodingProfile.CreateMp4(VideoEncodingQuality.HD720p); webcamEncodingProfile.Video.Bitrate = 5000000; } else { webcamEncodingProfile = MediaEncodingProfile.CreateMp4(VideoEncodingQuality.Auto); } } else { webcamEncodingProfile = MediaEncodingProfile.CreateMp4(VideoEncodingQuality.Auto); } mediaRecording = await mediaCapture.PrepareLowLagRecordToStorageFileAsync(webcamEncodingProfile, webcamFile); // kick off the screen encoding parallel using (var stream = await screenFile.OpenAsync(FileAccessMode.ReadWrite)) using (screenCapture = new Encoder(screenDevice, captureItem)) { // webcam recording if (mediaCapture != null) { await mediaRecording.StartAsync(); } // screen recording await screenCapture.EncodeAsync( stream, width, height, bitrate, frameRate); } MainTextBlock.Foreground = originalBrush; // user has finished recording, so stop webcam recording await mediaRecording.StopAsync(); await mediaRecording.FinishAsync(); _timer.Stop(); } catch (Exception ex) { _timer.Stop(); var dialog = new MessageDialog( $"Uh-oh! Something went wrong!\n0x{ex.HResult:X8} - {ex.Message}", "Recording failed"); await dialog.ShowAsync(); button.IsChecked = false; MainTextBlock.Text = "failure"; MainTextBlock.Foreground = originalBrush; MainProgressBar.IsIndeterminate = false; captureItem = null; if (mediaRecording != null) { await mediaRecording.StopAsync(); await mediaRecording.FinishAsync(); } return; } // at this point the encoding has finished MainTextBlock.Text = "saving..."; // save slide markers var recording = new Recording() { Slides = screenCapture.GetTimestamps() }; var settings = new JsonSerializerSettings { ContractResolver = new CamelCasePropertyNamesContractResolver() }; var json = JsonConvert.SerializeObject(recording, Formatting.Indented, settings); await FileIO.WriteTextAsync(jsonFile, json); // add metadata var recordingMetadataDialog = new RecordingMetadataDialog(); var recordingMetadataDialogResult = await recordingMetadataDialog.ShowAsync(); if (recordingMetadataDialogResult == ContentDialogResult.Primary) { recording.Description = recordingMetadataDialog.LectureTitle; if (recordingMetadataDialog.LectureDate.HasValue) { recording.LectureDate = recordingMetadataDialog.LectureDate.Value.DateTime; } } else { recording.Description = null; recording.LectureDate = DateTime.Now; } json = JsonConvert.SerializeObject(recording, Formatting.Indented, settings); await FileIO.WriteTextAsync(jsonFile, json); // tell the user we're done button.IsChecked = false; MainTextBlock.Text = "done"; MainProgressBar.IsIndeterminate = false; requestSuspensionExtension.Dispose(); }