Madwin74

Temp

Mar 21st, 2024
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.09 KB | None | 0 0
  1. using System;
  2. using System.Runtime.InteropServices;
  3. using System.Windows.Forms;
  4. using CefSharp;
  5. using CefSharp.WinForms;
  6. using Vlc.DotNet.Forms;
  7. using System.IO;
  8.  
  9. namespace ScreenRecorder
  10. {
  11. public partial class MainForm : Form
  12. {
  13. private ChromiumWebBrowser browser;
  14. private VlcControl vlcControl;
  15. private bool isRecording = false;
  16.  
  17. public MainForm()
  18. {
  19. InitializeComponent();
  20. InitializeCefSharp();
  21. InitializeVlcControl();
  22. }
  23.  
  24. private void InitializeCefSharp()
  25. {
  26. CefSettings settings = new CefSettings();
  27. Cef.Initialize(settings);
  28. browser = new ChromiumWebBrowser("http://www.example.com"); // Set your URL here
  29. browser.Dock = DockStyle.Fill;
  30. Controls.Add(browser);
  31. }
  32.  
  33. private void InitializeVlcControl()
  34. {
  35. vlcControl = new VlcControl();
  36. vlcControl.Dock = DockStyle.Fill;
  37. Controls.Add(vlcControl);
  38. }
  39.  
  40. private void RecordButton_Click(object sender, EventArgs e)
  41. {
  42. if (!isRecording)
  43. {
  44. StartRecording();
  45. }
  46. else
  47. {
  48. StopRecording();
  49. }
  50. }
  51.  
  52. private void StartRecording()
  53. {
  54. string outputPath = "output.mp4"; // Set your desired output path
  55.  
  56. IntPtr windowHandle = IntPtr.Zero;
  57. if (browser.IsBrowserInitialized && !browser.IsBrowserFullScreen)
  58. {
  59. windowHandle = browser.GetBrowser().Host.WindowHandle;
  60. }
  61.  
  62. string vlcArgs;
  63. if (windowHandle != IntPtr.Zero)
  64. {
  65. vlcArgs = $"screen:// :screen-fps=30 :screen-caching=100 :screen-top={browser.Top} :screen-left={browser.Left} :screen-width={browser.Width} :screen-height={browser.Height} :screen-geometry={browser.Width}x{browser.Height}+{browser.Left}+{browser.Top} :screen-screennum=0 :screen-redirect-gdi :screen-redirect-fps=30 :input-repeat=inf :sout=file/ts:{outputPath}";
  66. }
  67. else
  68. {
  69. vlcArgs = $"screen:// :screen-fps=30 :screen-caching=100 --sout=file/ts:{outputPath}";
  70. }
  71.  
  72. vlcControl.SetMedia(new FileInfo(vlcArgs));
  73. vlcControl.Play();
  74. isRecording = true;
  75. RecordButton.Text = "Stop Recording";
  76. }
  77.  
  78. private void StopRecording()
  79. {
  80. vlcControl.Stop();
  81. isRecording = false;
  82. RecordButton.Text = "Start Recording";
  83. }
  84. }
  85. }
  86. In this modified code, when starting the recording, it checks if the CefSharp browser is initialized and not in fullscreen mode. If so, it retrieves the handle of the browser window and uses its dimensions and position to specify the region to capture using VLC DotNet. If the browser is fullscreen or not initialized, it captures the entire screen as before.
  87.  
  88.  
  89.  
  90.  
  91.  
  92.  
  93. Message ChatGPT…
  94.  
  95. ChatGPT can make mistakes. Consider checking important
Advertisement
Add Comment
Please, Sign In to add comment