public MainPage() { InitializeComponent(); if (!GraphicsCaptureSession.IsSupported()) { IsEnabled = false; var dialog = new MessageDialog( "Screen capture is not supported on this device for this release of Windows!", "Screen capture unsupported"); var ignored = dialog.ShowAsync(); return; } // initialize screen recording screenDevice = Direct3D11Helpers.CreateDevice(); // connect to the powerpoint app service App.AppServiceConnected += MainPage_AppServiceConnected; _timer.Interval = new TimeSpan(0, 0, 1); _timer.Tick += _timer_Tick; }
public MainPage() { this.InitializeComponent(); _device = Direct3D11Helpers.CreateDevice(); _semaphore = new SemaphoreSlim(0, 1); var appView = ApplicationView.GetForCurrentView(); if (!appView.IsViewModeSupported(ApplicationViewMode.CompactOverlay)) { OverlayButton.IsEnabled = false; } }
public MainPage() { InitializeComponent(); VM = new VideoManager(); if (!GraphicsCaptureSession.IsSupported()) { IsEnabled = false; var dialog = new MessageDialog( "Sorry! Screen capture is not supported on your device.", "Screen capture unsupported"); var ignored = dialog.ShowAsync(); return; } _device = Direct3D11Helpers.CreateDevice(); var settings = GetCachedSettings(); var names = new List <string>(); names.Add(nameof(VideoEncodingQuality.HD1080p)); names.Add(nameof(VideoEncodingQuality.HD720p)); names.Add(nameof(VideoEncodingQuality.Uhd2160p)); names.Add(nameof(VideoEncodingQuality.Uhd4320p)); QualityComboBox.ItemsSource = names; QualityComboBox.SelectedIndex = names.IndexOf(settings.Quality.ToString()); var frameRates = new List <string> { "30fps", "60fps" }; FrameRateComboBox.ItemsSource = frameRates; FrameRateComboBox.SelectedIndex = frameRates.IndexOf($"{settings.FrameRate}fps"); UseSourceSizeCheckBox.IsChecked = settings.UseSourceSize; ExampleNotif.Show("Some trext", 5); }
public MainPage() { InitializeComponent(); ApplicationView.GetForCurrentView().SetPreferredMinSize( new Size(350, 200)); if (!GraphicsCaptureSession.IsSupported()) { IsEnabled = false; var dialog = new MessageDialog( "Screen capture is not supported on this device for this release of Windows!", "Screen capture unsupported"); var ignored = dialog.ShowAsync(); return; } _device = Direct3D11Helpers.CreateDevice(); var settings = GetCachedSettings(); var names = new List <string>(); names.Add(nameof(VideoEncodingQuality.HD1080p)); names.Add(nameof(VideoEncodingQuality.HD720p)); names.Add(nameof(VideoEncodingQuality.Uhd2160p)); names.Add(nameof(VideoEncodingQuality.Uhd4320p)); QualityComboBox.ItemsSource = names; QualityComboBox.SelectedIndex = names.IndexOf(settings.Quality.ToString()); var frameRates = new List <string> { "30fps", "60fps" }; FrameRateComboBox.ItemsSource = frameRates; FrameRateComboBox.SelectedIndex = frameRates.IndexOf($"{settings.FrameRate}fps"); UseCaptureItemSizeCheckBox.IsChecked = settings.UseSourceSize; }
public MainPage() { InitializeComponent(); //Adjust minimum and default window size ApplicationView.GetForCurrentView().SetPreferredMinSize(new Size(400, 250)); ApplicationView.PreferredLaunchViewSize = new Size(400, 250); ApplicationView.PreferredLaunchWindowingMode = ApplicationViewWindowingMode.PreferredLaunchViewSize; //hide titlebar ApplicationViewTitleBar formattableTitleBar = ApplicationView.GetForCurrentView().TitleBar; formattableTitleBar.ButtonBackgroundColor = Colors.Transparent; CoreApplicationViewTitleBar coreTitleBar = CoreApplication.GetCurrentView().TitleBar; coreTitleBar.ExtendViewIntoTitleBar = true; //Record icon RecordIcon.Visibility = Visibility.Visible; StopIcon.Visibility = Visibility.Collapsed; Ellipse.Visibility = Visibility.Collapsed; ToolTip toolTip = new ToolTip(); toolTip.Content = "Start recording"; ToolTipService.SetToolTip(MainButton, toolTip); AutomationProperties.SetName(MainButton, "Start recording"); _device = Direct3D11Helpers.CreateDevice(); var settings = GetCachedSettings(); _resolutions = new List <ResolutionItem>(); foreach (var resolution in EncoderPresets.Resolutions) { _resolutions.Add(new ResolutionItem() { DisplayName = $"{resolution.Width} x {resolution.Height}", Resolution = resolution, }); } ResolutionComboBox.ItemsSource = _resolutions; ResolutionComboBox.SelectedIndex = GetResolutionIndex(settings.Width, settings.Height); _bitrates = new List <BitrateItem>(); foreach (var bitrate in EncoderPresets.Bitrates) { var mbps = (float)bitrate / 1000000; _bitrates.Add(new BitrateItem() { DisplayName = $"{mbps:0.##} Mbps", Bitrate = bitrate, }); } BitrateComboBox.ItemsSource = _bitrates; BitrateComboBox.SelectedIndex = GetBitrateIndex(settings.Bitrate); _frameRates = new List <FrameRateItem>(); foreach (var frameRate in EncoderPresets.FrameRates) { _frameRates.Add(new FrameRateItem() { DisplayName = $"{frameRate}fps", FrameRate = frameRate, }); } FrameRateComboBox.ItemsSource = _frameRates; FrameRateComboBox.SelectedIndex = GetFrameRateIndex(settings.FrameRate); UseCaptureItemToggleSwitch.IsOn = settings.UseSourceSize; PreviewToggleSwitch.IsOn = settings.Preview; }
private async void MainToggleButton_Checked(object sender, RoutedEventArgs e) { // Select what we want to capture var picker = new GraphicsCapturePicker(); var item = await picker.PickSingleItemAsync(); if (item != null) { // Get a temporary file to save our gif to var file = await GetTempFileAsync(); using (var stream = await file.OpenAsync(FileAccessMode.ReadWrite)) { // Get the various d3d objects we'll need var d3dDevice = Direct3D11Helpers.CreateSharpDXDevice(_device); // Create our encoder var encoder = await BitmapEncoder.CreateAsync(BitmapEncoder.GifEncoderId, stream); // Write the application block // http://www.vurdalakov.net/misc/gif/netscape-looping-application-extension var containerProperties = encoder.BitmapContainerProperties; await containerProperties.SetPropertiesAsync(new[] { new KeyValuePair <string, BitmapTypedValue>("/appext/application", new BitmapTypedValue(PropertyValue.CreateUInt8Array(Encoding.ASCII.GetBytes("NETSCAPE2.0")), PropertyType.UInt8Array)), // The first value is the size of the block, which is the fixed value 3. // The second value is the looping extension, which is the fixed value 1. // The third and fourth values comprise an unsigned 2-byte integer (little endian). // The value of 0 means to loop infinitely. // The final value is the block terminator, which is the fixed value 0. new KeyValuePair <string, BitmapTypedValue>("/appext/data", new BitmapTypedValue(PropertyValue.CreateUInt8Array(new byte[] { 3, 1, 0, 0, 0 }), PropertyType.UInt8Array)), }); // Setup Windows.Graphics.Capture var itemSize = item.Size; var framePool = Direct3D11CaptureFramePool.CreateFreeThreaded( _device, DirectXPixelFormat.B8G8R8A8UIntNormalized, 1, itemSize); var session = framePool.CreateCaptureSession(item); // We need a blank texture (background) and a texture that will hold the frame we'll be encoding var description = new SharpDX.Direct3D11.Texture2DDescription { Width = itemSize.Width, Height = itemSize.Height, MipLevels = 1, ArraySize = 1, Format = SharpDX.DXGI.Format.B8G8R8A8_UNorm, SampleDescription = new SharpDX.DXGI.SampleDescription() { Count = 1, Quality = 0 }, Usage = SharpDX.Direct3D11.ResourceUsage.Default, BindFlags = SharpDX.Direct3D11.BindFlags.ShaderResource | SharpDX.Direct3D11.BindFlags.RenderTarget, CpuAccessFlags = SharpDX.Direct3D11.CpuAccessFlags.None, OptionFlags = SharpDX.Direct3D11.ResourceOptionFlags.None }; var gifTexture = new SharpDX.Direct3D11.Texture2D(d3dDevice, description); var renderTargetView = new SharpDX.Direct3D11.RenderTargetView(d3dDevice, gifTexture); // Encode frames as they arrive. Because we created our frame pool using // Direct3D11CaptureFramePool::CreateFreeThreaded, this lambda will fire on a different thread // than our current one. If you'd like the callback to fire on your thread, create the frame pool // using Direct3D11CaptureFramePool::Create and make sure your thread has a DispatcherQueue and you // are pumping messages. TimeSpan lastTimeStamp = TimeSpan.MinValue; var frameCount = 0; framePool.FrameArrived += async(s, a) => { using (var frame = s.TryGetNextFrame()) { var contentSize = frame.ContentSize; var timeStamp = frame.SystemRelativeTime; using (var sourceTexture = Direct3D11Helpers.CreateSharpDXTexture2D(frame.Surface)) { var width = Math.Clamp(contentSize.Width, 0, itemSize.Width); var height = Math.Clamp(contentSize.Height, 0, itemSize.Height); var region = new SharpDX.Direct3D11.ResourceRegion(0, 0, 0, width, height, 1); d3dDevice.ImmediateContext.ClearRenderTargetView(renderTargetView, new SharpDX.Mathematics.Interop.RawColor4(0, 0, 0, 1)); d3dDevice.ImmediateContext.CopySubresourceRegion(sourceTexture, 0, region, gifTexture, 0); } if (lastTimeStamp == TimeSpan.MinValue) { lastTimeStamp = timeStamp; } var timeStampDelta = timeStamp - lastTimeStamp; lastTimeStamp = timeStamp; var milliseconds = timeStampDelta.TotalMilliseconds; // Use 10ms units var frameDelay = milliseconds / 10; if (frameCount > 0) { await encoder.GoToNextFrameAsync(); } // Write our frame delay await encoder.BitmapProperties.SetPropertiesAsync(new[] { new KeyValuePair <string, BitmapTypedValue>("/grctlext/Delay", new BitmapTypedValue(PropertyValue.CreateUInt16((ushort)frameDelay), PropertyType.UInt16)), }); // Write the frame to our image var gifSurface = Direct3D11Helpers.CreateDirect3DSurfaceFromSharpDXTexture(gifTexture); var copy = await SoftwareBitmap.CreateCopyFromSurfaceAsync(gifSurface); encoder.SetSoftwareBitmap(copy); frameCount++; } }; session.StartCapture(); await _semaphore.WaitAsync(); session.Dispose(); framePool.Dispose(); await Task.Delay(1000); await encoder.FlushAsync(); var newFile = await PickGifAsync(); if (newFile == null) { await file.DeleteAsync(); return; } await file.MoveAndReplaceAsync(newFile); await Launcher.LaunchFileAsync(newFile); } } }
public MainPage() { InitializeComponent(); this.Loaded += LoadedHandler; MergingProgressRing.Visibility = Visibility.Collapsed; SilentPlayer = new MediaPlayer() { IsLoopingEnabled = true }; SilentPlayer.Source = MediaSource.CreateFromUri(new Uri("ms-appx:///Assets/Silence.ogg")); SilentPlayer.Play(); ApplicationView.GetForCurrentView().SetPreferredMinSize(new Size(400, 260)); //hide titlebar SetupTitleBar(); ApplicationViewTitleBar formattableTitleBar = ApplicationView.GetForCurrentView().TitleBar; formattableTitleBar.ButtonBackgroundColor = Colors.Transparent; //Record icon RecordIcon.Visibility = Visibility.Visible; StopIcon.Visibility = Visibility.Collapsed; Ellipse.Visibility = Visibility.Collapsed; ToolTip toolTip = new ToolTip(); toolTip.Content = Strings.Resources.RecordingStart; ToolTipService.SetToolTip(MainButton, toolTip); AutomationProperties.SetName(MainButton, Strings.Resources.RecordingStart); _device = Direct3D11Helpers.CreateDevice(); var settings = GetCachedSettings(); _resolutions = new List <ResolutionItem>(); foreach (var resolution in EncoderPresets.Resolutions) { _resolutions.Add(new ResolutionItem() { DisplayName = $"{resolution.Width} x {resolution.Height}", Resolution = resolution, }); } _resolutions.Add(new ResolutionItem() { DisplayName = Strings.Resources.SourceSizeToggle, Resolution = new SizeUInt32() { Width = 0, Height = 0 }, }); ResolutionComboBox.ItemsSource = _resolutions; ResolutionComboBox.SelectedIndex = GetResolutionIndex(settings.Width, settings.Height); _bitrates = new List <BitrateItem>(); foreach (var bitrate in EncoderPresets.Bitrates) { var mbps = (float)bitrate / 1000000; _bitrates.Add(new BitrateItem() { DisplayName = $"{mbps:0.##} Mbps", Bitrate = bitrate, }); } BitrateComboBox.ItemsSource = _bitrates; BitrateComboBox.SelectedIndex = GetBitrateIndex(settings.Bitrate); _frameRates = new List <FrameRateItem>(); foreach (var frameRate in EncoderPresets.FrameRates) { _frameRates.Add(new FrameRateItem() { DisplayName = $"{frameRate}fps", FrameRate = frameRate, }); } FrameRateComboBox.ItemsSource = _frameRates; FrameRateComboBox.SelectedIndex = GetFrameRateIndex(settings.FrameRate); AudioToggleSwitch.IsOn = settings.IntAudio; ExtAudioToggleSwitch.IsOn = settings.ExtAudio; GalleryToggleSwitch.IsOn = settings.Gallery; SystemPlayerToggleSwitch.IsOn = settings.SystemPlayer; OverlayToggleSwitch.IsOn = settings.ShowOnTop; if (AudioToggleSwitch.IsOn) { InternalAudioCheck(); } }