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/
45 stars 8 forks source link

Using Microphone as Audio Source makes second+ captures file corrupt / audio not sync in Android Build #334

Closed RErwandi closed 4 months ago

RErwandi commented 8 months ago

Describe the bug When I run StartCapture and then StopCapture the first time, the resulted video is fine. But if I run another StartCapture and StopCapture, the resulting video got corrupted. I'm using Capture from Camera to capture my full-screen raw image with WebCamTexture as its source. So I can make it support switching camera and rotate it accordingly. When I ran switch camera to the webcamtexture, somehow the resulted video is not corrupted but the audio is not sync. If I record using my front camera for 5 secs, and then switch to back camera and start talking "Hello". The resulted video is not corrupted but my voice "Hello" start as the video start, not after 5 secs.

THIS ONLY HAPPEND IF AUDIO SOURCE IS MICROPHONE, SETTING IT TO NONE RESOLVE THIS ISSUE

Your Setup (please complete the following information):

To Reproduce Steps to reproduce the behavior:

  1. I start capture using Capture from Camera
  2. I stop capture and see the resulted video. Everything is good
  3. I decide to make another capture and ran start capture then stop capture again
  4. This time, the resulted video is corrupted.

Video This is the video. https://youtube.com/shorts/nFc1e3p7qZk

First take is working as intended. Second take is black (file corrupted) Third take is working if i switch camera in the middle of recording but audio is not sync

I use screen capture so you wont hear me talking during recording, only in playback

MorrisRH commented 8 months ago

I've not been able to reproduce this with the Screen Capture Demo scene using Unity 2022.3.11f1, AVPro Movie Capture 5.1.8-trial on a Pixel 4 running Android 13.

Are you waiting for file writing to complete before starting the next capture?

RErwandi commented 8 months ago

Yes, I have tried both using BeginFinalFileWritingAction and CompletedFileWritingAction to make sure file writing is completed before proceed to next page which I play the media.

here is my recording script.

public class RecordingManager : MonoSingleton<RecordingManager>
{
    [SerializeField] private CaptureBase recorder;
    [SerializeField] private GameObject canvas;
    [SerializeField] private GameObject recordingCamera;
    [SerializeField] private RawImage rawImage;

    public UnityEvent<string> OnFinishRecording;

    public float Progress { get; set; }
    public bool IsRecording => recorder.IsCapturing();
    public int RecordingDuration => (int)recorder.CaptureStats.TotalEncodedSeconds;
    public Texture2D Thumbnail { get; set; }

    private void OnEnable()
    {
        recorder.CompletedFileWritingAction += FinishRecording;
    }

    private void OnDisable()
    {
        recorder.CompletedFileWritingAction -= FinishRecording;
    }

    public void SetTexture(Texture texture)
    {
        rawImage.texture = texture;
    }

    private void Update()
    {
        if (recorder.IsCapturing())
        {
            Progress = recorder.CaptureStats.NumEncodedFrames / (recorder.StopAfterSecondsElapsed * recorder.FrameRate);
        }
    }

    public void StartResumeRecording()
    {
        if (recorder.IsCapturing())
        {
            recorder.ResumeCapture();
        }
        else
        {
            recorder.StartCapture();
            CaptureThumbnail();
        }
    }

    private void CaptureThumbnail()
    {
        var webcamTexture = rawImage.texture as WebCamTexture;
        Thumbnail = new Texture2D(rawImage.texture.width, rawImage.texture.height);
        Thumbnail.SetPixels(webcamTexture.GetPixels());
        Thumbnail.Apply();
    }

    public void PauseRecording()
    {
        if (!recorder.IsCapturing()) return;

        recorder.PauseCapture();
    }

    public void StopAndFinishRecording()
    {
        recorder.StopCapture();
    }

    public void AbortRecording()
    {
        if (recorder.IsCapturing())
        {
            recorder.CancelCapture();
        }
    }

    public void ShowRecording(bool value)
    {
        if (value)
        {
            canvas.SetActive(true);
            recordingCamera.SetActive(true);
        }
        else
        {
            canvas.SetActive(false);
            recordingCamera.SetActive(false);
        }
    }

    private void FinishRecording(FileWritingHandler fileWritingHandler)
    {
        OnFinishRecording?.Invoke(fileWritingHandler.Path);
    }
}

script that subscribe to OnFinishRecording is just enable other pages that has AVPro Media Player and run player.OpenMedia(new MediaPath(filePath, MediaPathType.AbsolutePathOrURL));

IsMeKena commented 8 months ago

@MorrisRH any update on this please?

stale[bot] commented 7 months ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

Chris-RH commented 6 months ago

Are you able to send us a simple project that reproduces the issue, please? unitysupport@renderheads.com

Chris-RH commented 5 months ago

Are you able to send us a simple project that reproduces the issue, please? unitysupport@renderheads.com

IsMeKena commented 5 months ago

@Chris-RH okay we will do that in the coming days

MorrisRH commented 5 months ago

We've changed the microphone capture implementation to use Oboe. Hoping this will resolve your issue or at least give us something more to work with. This will be in the next release.

IsMeKena commented 5 months ago

We went around the implementation to solve the issue. Currently testing to see if it is completely okay. If anything shows up we will let you know. thanks

Chris-RH commented 4 months ago

AVPro Movie Capture 5.2.1 has been released. Please let us know if it has not fixed your issue.