Chocolade19721309

Untitled

May 4th, 2024
30
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.58 KB | None | 0 0
  1. using System.Diagnostics;
  2.  
  3. public class ScreenRecorder
  4. {
  5. private Process ffmpegProcess;
  6.  
  7. public void StartRecording(string outputPath)
  8. {
  9. // Replace the path with your actual path to ffmpeg.exe and your audio device name
  10. string ffmpegPath = @"D:\Captured Videos\ffmpeg.exe";
  11. string audioDeviceName = "Stereo Mix (Realtek(R) Audio)"; // Replace with actual device name
  12. string videoArguments = "-f gdigrab -framerate 30 -i desktop";
  13. string audioArguments = $"-f dshow -i audio=\"{audioDeviceName}\"";
  14. string fileArguments = $"-preset ultrafast -pix_fmt yuv420p \"{outputPath}\"";
  15.  
  16. ProcessStartInfo startInfo = new ProcessStartInfo
  17. {
  18. FileName = ffmpegPath,
  19. Arguments = $"{videoArguments} {audioArguments} {fileArguments}",
  20. UseShellExecute = false,
  21. CreateNoWindow = true,
  22. RedirectStandardInput = true,
  23. RedirectStandardOutput = true,
  24. RedirectStandardError = true
  25. };
  26.  
  27. ffmpegProcess = new Process { StartInfo = startInfo };
  28. ffmpegProcess.EnableRaisingEvents = true;
  29. ffmpegProcess.Start();
  30. ffmpegProcess.BeginErrorReadLine();
  31. ffmpegProcess.BeginOutputReadLine();
  32. }
  33.  
  34. public void StopRecording()
  35. {
  36. if (ffmpegProcess != null && !ffmpegProcess.HasExited)
  37. {
  38. ffmpegProcess.StandardInput.WriteLine("q"); // Sending 'q' to FFmpeg to stop recording
  39. ffmpegProcess.Kill();
  40. ffmpegProcess.WaitForExit();
  41. }
  42. }
  43. }
Advertisement
Add Comment
Please, Sign In to add comment