Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Runtime.InteropServices;
- using System.Windows.Forms;
- using CefSharp;
- using CefSharp.WinForms;
- using Vlc.DotNet.Forms;
- using System.IO;
- namespace ScreenRecorder
- {
- public partial class MainForm : Form
- {
- private ChromiumWebBrowser browser;
- private VlcControl vlcControl;
- private bool isRecording = false;
- public MainForm()
- {
- InitializeComponent();
- InitializeCefSharp();
- InitializeVlcControl();
- }
- private void InitializeCefSharp()
- {
- CefSettings settings = new CefSettings();
- Cef.Initialize(settings);
- browser = new ChromiumWebBrowser("http://www.example.com"); // Set your URL here
- browser.Dock = DockStyle.Fill;
- Controls.Add(browser);
- }
- private void InitializeVlcControl()
- {
- vlcControl = new VlcControl();
- vlcControl.Dock = DockStyle.Fill;
- Controls.Add(vlcControl);
- }
- private void RecordButton_Click(object sender, EventArgs e)
- {
- if (!isRecording)
- {
- StartRecording();
- }
- else
- {
- StopRecording();
- }
- }
- private void StartRecording()
- {
- string outputPath = "output.mp4"; // Set your desired output path
- IntPtr windowHandle = IntPtr.Zero;
- if (browser.IsBrowserInitialized && !browser.IsBrowserFullScreen)
- {
- windowHandle = browser.GetBrowser().Host.WindowHandle;
- }
- string vlcArgs;
- if (windowHandle != IntPtr.Zero)
- {
- 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}";
- }
- else
- {
- vlcArgs = $"screen:// :screen-fps=30 :screen-caching=100 --sout=file/ts:{outputPath}";
- }
- vlcControl.SetMedia(new FileInfo(vlcArgs));
- vlcControl.Play();
- isRecording = true;
- RecordButton.Text = "Stop Recording";
- }
- private void StopRecording()
- {
- vlcControl.Stop();
- isRecording = false;
- RecordButton.Text = "Start Recording";
- }
- }
- }
- 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.
- Message ChatGPT…
- ChatGPT can make mistakes. Consider checking important
Advertisement
Add Comment
Please, Sign In to add comment