Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Screen recording as video, audio on SharpAvi - Audio not recording #33

Open
Gopichandar opened this issue Feb 25, 2020 · 4 comments
Open

Comments

@Gopichandar
Copy link

What has been achieved:
I have successfully integrated that with the sample provided and I'm trying to capture the audio through NAudio with SharpAPI video stream for the video to record along with audio implementation.

Issue:
Whatever I write the audio stream in SharpAvi video. On output, It was recorded only with video and audio is empty.

Checking audio alone to make sure:
But When I try capture the audio as separate file called "output.wav" and It was recorded with audio as expected and can able to hear the recorded audio. So, I'm concluding for now that the issue is only on integration with video via SharpApi

writterx = new WaveFileWriter("Out.wav", audioSource.WaveFormat);

Full code to reproduce the issue:
https://drive.google.com/open?id=1H7Ziy_yrs37hdpYriWRF-nuRmmFbsfe-

Code glimpse from Recorder.cs
NAudio Initialization:

audioSource = new WasapiLoopbackCapture();

audioStream = CreateAudioStream(audioSource.WaveFormat, encodeAudio, audioBitRate);

audioSource.DataAvailable += audioSource_DataAvailable;

Capturing audio bytes and write it on SharpAvi Audio Stream:

private void audioSource_DataAvailable(object sender, WaveInEventArgs e)
{
    var signalled = WaitHandle.WaitAny(new WaitHandle[] { videoFrameWritten, stopThread });
    if (signalled == 0)
    {
        audioStream.WriteBlock(e.Buffer, 0, e.BytesRecorded);               
        audioBlockWritten.Set();
        Debug.WriteLine("Bytes: " + e.BytesRecorded);
    }
}

Can you please suggest a Solution

Asked the same in SO
https://stackoverflow.com/questions/60238492/screen-recording-as-video-audio-on-sharpavi-audio-not-recording?noredirect=1

@BranigansLaw
Copy link

I know this is old, but I'm stuck at the same place with this.

@Gopichandar, did you even get your solution working?

@BranigansLaw
Copy link

Just to follow up on this, I believe the issue is using the JPEG Motion format which might not allow embedding of audio. I tried switching to DivX format but SharpAVI kept throwing an exception I didn't have that codec (even though DivX is installed on my system).

In the end, I decided to switch to recording the sections separately and then recombining with ffmpeg.

If anyone found a way around this, let me know! I'd much rather stream into on file then saving and using ffmpeg to recombine.

@cytivrat
Copy link

cytivrat commented Nov 6, 2021

I doing the same thing and I get part of the sound, but it is in extremely bad quality, too many silent pieces: like I'm saying 1-2-3-4-5-6, 1 can go properly, then start of the 2, then silence or some noise and then I get the end of three and no 4-5-6 at all.

@cytivrat
Copy link

cytivrat commented Nov 6, 2021

As I found out, in my case adding new frame took 0.2-0.3 seconds, when I set frame rate to 10. So I was getting a new frame data longer than I tried to write it. After I optimized my code that creates a new frame, I was able to get clear sound inside recorded avi file

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants