ScreenRecorderLib
ScreenRecorderLib copied to clipboard
No Sound recorded
Awesome but I tried everything to try to record sound video works great no sound? running TestAppWinforms directly from source. Here is the code I'm using
private void RecordButton_Click(object sender, EventArgs e)
{
List<AudioDevice> inputDevices = Recorder.GetSystemAudioDevices(AudioDeviceSource.InputDevices);
List<AudioDevice> outputDevices = Recorder.GetSystemAudioDevices(AudioDeviceSource.OutputDevices);
AudioDevice selectedOutputDevice = outputDevices.FirstOrDefault();//select one of the devices.. Passing empty string or null uses system default playback device.
AudioDevice selectedInputDevice = inputDevices.FirstOrDefault();//select one of the devices.. Passing empty string or null uses system default recording device.
//var AudioOptions = new AudioOptions
//{
// IsAudioEnabled = true,
// IsOutputDeviceEnabled = true,
// IsInputDeviceEnabled = true,
// AudioOutputDevice = selectedOutputDevice.DeviceName,
// AudioInputDevice = selectedInputDevice.DeviceName
//};
//These options must be set before starting the recording, and cannot be modified while recording.
RecorderOptions options = new RecorderOptions
{
SourceOptions = new SourceOptions
{
//Populate and pass a list of recordingsources.
RecordingSources = new List<RecordingSourceBase>()
},
OutputOptions = new OutputOptions
{
RecorderMode = RecorderMode.Video,
//This sets a custom size of the video output, in pixels.
OutputFrameSize = new ScreenSize(1920, 1080),
//Stretch controls how the resizing is done, if the new aspect ratio differs.
Stretch = StretchMode.Uniform,
//SourceRect allows you to crop the output.
SourceRect = new ScreenRect(100, 100, 500, 500)
},
AudioOptions = new AudioOptions
{
Bitrate = AudioBitrate.bitrate_128kbps,
Channels = AudioChannels.Stereo,
IsAudioEnabled = true,
IsOutputDeviceEnabled = true,
IsInputDeviceEnabled = true,
AudioOutputDevice = selectedOutputDevice.DeviceName,
AudioInputDevice = selectedInputDevice.DeviceName,
InputVolume = 1,
OutputVolume = 1,
},
VideoEncoderOptions = new VideoEncoderOptions
{
Bitrate = 8000 * 1000,
Framerate = 60,
IsFixedFramerate = true,
//Currently supported are H264VideoEncoder and H265VideoEncoder
Encoder = new H264VideoEncoder
{
BitrateMode = H264BitrateControlMode.CBR,
EncoderProfile = H264Profile.Main,
},
//Fragmented Mp4 allows playback to start at arbitrary positions inside a video stream,
//instead of requiring to read the headers at the start of the stream.
IsFragmentedMp4Enabled = true,
//If throttling is disabled, out of memory exceptions may eventually crash the program,
//depending on encoder settings and system specifications.
IsThrottlingDisabled = false,
//Hardware encoding is enabled by default.
IsHardwareEncodingEnabled = true,
//Low latency mode provides faster encoding, but can reduce quality.
IsLowLatencyEnabled = false,
//Fast start writes the mp4 header at the beginning of the file, to facilitate streaming.
IsMp4FastStartEnabled = false
},
MouseOptions = new MouseOptions
{
//Displays a colored dot under the mouse cursor when the left mouse button is pressed.
IsMouseClicksDetected = true,
MouseLeftClickDetectionColor = "#FFFF00",
MouseRightClickDetectionColor = "#FFFF00",
MouseClickDetectionRadius = 30,
MouseClickDetectionDuration = 100,
IsMousePointerEnabled = true,
/* Polling checks every millisecond if a mouse button is pressed.
Hook is more accurate, but may affect mouse performance as every mouse update must be processed.*/
MouseClickDetectionMode = MouseDetectionMode.Hook
},
OverlayOptions = new OverLayOptions
{
//Populate and pass a list of recording overlays.
Overlays = new List<RecordingOverlayBase>()
},
SnapshotOptions = new SnapshotOptions
{
//Take a snapshot of the video output at the given interval
SnapshotsWithVideo = false,
SnapshotsIntervalMillis = 1000,
SnapshotFormat = ImageFormat.PNG,
//Optional path to the directory to store snapshots in
//If not configured, snapshots are stored in the same folder as video output.
SnapshotsDirectory = ""
},
LogOptions = new LogOptions
{
//This enabled logging in release builds.
IsLogEnabled = true,
//If this path is configured, logs are redirected to this file.
LogFilePath = "recorder.log",
LogSeverityLevel = ScreenRecorderLib.LogLevel.Debug
}
};
Recorder rec = Recorder.CreateRecorder(options);
if (_isRecording)
{
_rec.Stop();
_progressTimer?.Stop();
_progressTimer = null;
_secondsElapsed = 0;
RecordButton.Enabled = false;
return;
}
textBoxResult.Text = "";
UpdateProgress();
string timestamp = DateTime.Now.ToString("yyyy-MM-dd HH-mm-ss");
string videoPath = Path.Combine(Path.GetTempPath(), "ScreenRecorder", timestamp, timestamp + ".mp4");
_progressTimer = new Timer();
_progressTimer.Tick += _progressTimer_Tick;
_progressTimer.Interval = 1000;
_progressTimer.Start();
if (_rec == null)
{
_rec = Recorder.CreateRecorder();
_rec.OnRecordingComplete += Rec_OnRecordingComplete;
_rec.OnRecordingFailed += Rec_OnRecordingFailed;
_rec.OnStatusChanged += _rec_OnStatusChanged;
_rec.OnSnapshotSaved += _rec_OnSnapshotSaved;
}
_rec.Record(videoPath);
_secondsElapsed = 0;
_isRecording = true;
}
Just tried the TestConsoleAppDotNetCore it works as expected. Still no sound in Windows form app?
List<AudioDevice> inputDevices = Recorder.GetSystemAudioDevices(AudioDeviceSource.InputDevices);
List<AudioDevice> outputDevices = Recorder.GetSystemAudioDevices(AudioDeviceSource.OutputDevices);
AudioDevice selectedOutputDevice = outputDevices.FirstOrDefault();//select one of the devices.. Passing empty string or null uses system default playback device.
AudioDevice selectedInputDevice = inputDevices.FirstOrDefault();//select one of the devices.. Passing empty string or null uses system default recording device.
This part just takes the first audio device in the list of audio devices on your system. It's not necessarily a device that has any ouput. PCs can have several audio devices for both output and input, e.g hdmi output, analog output, etc.
Passing Null will use the system default device. Else you probably want to get the device list and let the user select the correct one from a menu.
Well i figured it out going to put the code her but took all the code out not related to audio still no sound commented out bitrate and Channel and it now works so I assume its one of those 2 things. Here is my simplified final code using only what I needed. I left the 2 lines commented out for you to see. Thanks for your help if you need me o uncomment one line at a time to troubleshoot I can just let me know.
` private void RecordButton_Click(object sender, EventArgs e) { if (_isRecording) { _rec.Stop(); _progressTimer?.Stop(); _progressTimer = null; _secondsElapsed = 0; RecordButton.Enabled = false; return; } textBoxResult.Text = ""; UpdateProgress();
string timestamp = DateTime.Now.ToString("yyyy-MM-dd HH-mm-ss");
string videoPath = Path.Combine(Path.GetTempPath(), "ScreenRecorder", timestamp, timestamp + ".mp4");
_progressTimer = new Timer();
_progressTimer.Tick += _progressTimer_Tick;
_progressTimer.Interval = 1000;
_progressTimer.Start();
if (_rec == null)
{
List<AudioDevice> inputDevices = Recorder.GetSystemAudioDevices(AudioDeviceSource.InputDevices);
List<AudioDevice> outputDevices = Recorder.GetSystemAudioDevices(AudioDeviceSource.OutputDevices);
AudioDevice selectedOutputDevice = outputDevices.FirstOrDefault();//select one of the devices.. Passing empty string or null uses system default playback device.
AudioDevice selectedInputDevice = inputDevices.FirstOrDefault();//select one of the devices.. Passing empty string or null uses system default recording device.
Debug.Write(selectedOutputDevice);
Debug.Write(selectedInputDevice);
RecorderOptions options = new RecorderOptions
{
AudioOptions = new AudioOptions
{
//Bitrate = AudioBitrate.bitrate_128kbps,
//Channels = AudioChannels.Stereo,
IsAudioEnabled = true,
IsOutputDeviceEnabled = true,
IsInputDeviceEnabled = true,
AudioOutputDevice = selectedOutputDevice.DeviceName,
AudioInputDevice = selectedInputDevice.DeviceName,
InputVolume = 1,
OutputVolume = 1,
}
};
_rec = Recorder.CreateRecorder(options);
_rec.OnRecordingComplete += Rec_OnRecordingComplete;
_rec.OnRecordingFailed += Rec_OnRecordingFailed;
_rec.OnStatusChanged += _rec_OnStatusChanged;
_rec.OnSnapshotSaved += _rec_OnSnapshotSaved;
}
_rec.Record(videoPath);
_secondsElapsed = 0;
_isRecording = true;
}`