RenderHeads / UnityPlugin-AVProMovieCapture

AVPro Movie Capture is a Unity Plugin for advanced video capture to AVI/MP4/MOV files
https://renderheads.com/products/avpro-movie-capture/
48 stars 8 forks source link

Microphone not found even when microphone is present #319

Closed qasymcorp closed 10 months ago

qasymcorp commented 1 year ago

Description When I want to record, it works fine but it doesn't record sounds. I do receive a warning saying "No microphone found", though in the same build I do use microphone somewhere else before

Your Setup (please complete the following information):

To Reproduce Steps to reproduce the behavior:

Logs I added Debug.LogWarning($"Microphone.devices[0] = {Microphone.devices[0]}"); into one of my scripts just to show that Microphone actually exists and it works

Screenshots

image

Videos

Chris-RH commented 1 year ago
  1. "saying No microphone found, but with actual microphone working in a different place" - do you mean that something else is using it at the same time or slightly before?
  2. Can you reproduce this in a new project using just AVPro Movie Capture Webcam demoscene?
qasymcorp commented 1 year ago
  1. No, the microphone is stopped by Microphone.End(microphoneName) before proceeding to the part where I use the screen recording
  2. I will try to, where should I email the unitypackage file?
Chris-RH commented 1 year ago

I would like you to test it in a new project. Just the webcam demo scene with microphone selected. That should determine if the issue is either: a) It works - AVPro Movie Capture is not having issues finding your mic, so its probably something in your code preventing it b) It doesn't work - AVPro Movie Capture isn't finding your mic for some reason

qasymcorp commented 1 year ago

I found the issue here.

  1. I created a simple scene in which I use the microphone (two buttons to start microphone recording and stopping it)
  2. I also created a WebCamTexture to record the camera
  3. I connected CaptureFromWebCamTexture to the texture from step 2 (also added two buttons to start and stop capturing)
  4. The recorder works fine in both cases: (1) when microphone is used by a monobehavior (2) when microphone is not being used Meaning that the other monobehavior accessing the microphone does not block recorder from accessing it. So the problem is not in my code.

The problem is how PrepareCapture method is implemented Consider the following code:

using RenderHeads.Media.AVProMovieCapture;
using UnityEngine;

namespace UnitedAssociates.AVProMovieCapture
{
    public class RecordingManager : MonoBehaviour
    {
        private CaptureFromWebCamTexture recorder;
        [SerializeField] private DeviceCamera deviceCamera;

        private void Awake()
        {
            recorder = gameObject.AddComponent<CaptureFromWebCamTexture>();
            recorder.CompletedFileWritingAction += OnRecordingFinished;
        }

        private void Start()
        {
            recorder.AudioCaptureSource = AudioCaptureSource.Microphone;
            recorder.SetSourceTexture(deviceCamera.FrontCamera);
            recorder.PrepareCapture();
        }

        public void OnStartRecordingButtonClicked()
        {
            recorder.StartCapture();
        }

        public void OnStopRecordingButtonClicked()
        {
            if (recorder.IsCapturing())
                recorder.StopCapture();
        }

        private void OnRecordingFinished(FileWritingHandler obj)
        {
            Debug.Log($"Path: {obj.Path}");
        }
    }
}

Intuitively it seemed to me that I need to put PrepareCapture in the Start method so that it prepares all the necessary resources before actually starting the capture. If you run the code as it is in this case, it is going to say "No microphone was found" (even though I can clearly see how I am using it) If you run the code with the recorder.PrepareCapture(); line commented out (or removed), it is going to record everything quite well.

I attached the unitypackage file with the scene and scripts (I hope it works!) [redacted]

Let me know if you have any questions

qasymcorp commented 1 year ago

During my troubleshooting process, I found myself reflecting on the purpose of this particular method and its relevance to my implementation. In an effort to gain a deeper understanding, I attempted to access the documentation to review the method's description. Regrettably, my search for this information was unsuccessful.

The package's included documentation did not yield the method description I was seeking, and even when I tried to use Ctrl + F within the provided PDF, I couldn't locate any relevant details. The online documentation, although informative with method names and arguments, lacked the comprehensive descriptions I needed.

I am writing to inquire if there might be an alternate source of documentation or if I may be overlooking a specific resource. If there is indeed a more comprehensive guide or any supplementary information available, I would greatly appreciate your guidance on how to access it.

qasymcorp commented 1 year ago

Were you able to reproduce the error? Any updates?