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

[Bug] Video recording fails on Android after repeated recordings #425

Closed orbitalnine closed 1 month ago

orbitalnine commented 2 months ago

Unity Version

2021.3.39

AVPro Movie Capture Version

5.3.0f1-trial (scripts v5.3.1)

Which platform(s) are you using?

Windows, Android

Which OS version(s) are you using?

Windows 11, Android 14

Which rendering API(s) are you using?

OpenGLES

Hardware

No response

Which capture component are you using?

Capture From Screen

Capture mode

Realtime

Which output mode are you using?

Video file

Video codecs

H264

Audio source

None

Audio codecs

AAC

Any other component configuration

Output Folder: Relative To Persistent Data

The issue

I can record video on Android about 10-20 times (short clips under 10s), eventually though recording fails with the error in the Log output below.

My game is a difficult physics drawing game and requires many retries to solve a level. I want to record all of the attempts, and throw them away, and just save the final good solution video.

Log output

2024-09-06 20:33:25.840 10187 10221 Error Unity [AVProMovieCapture] Failed to create recorder
2024-09-06 20:33:25.840 10187 10221 Error Unity RenderHeads.Media.AVProMovieCapture.CaptureBase:PrepareCapture()
2024-09-06 20:33:25.840 10187 10221 Error Unity RenderHeads.Media.AVProMovieCapture.CaptureBase:StartCapture()
Chris-RH commented 1 month ago

Its probably a memory thing.

Can you provide a full, unfiltered logcat in txt format please What android device are you using for testing? Is this occurring in Windows editor too or just your Android device? Is this reproducible in a new project, running only AVPro Movie Capture?

orbitalnine commented 1 month ago

Do you have an email I can send the log to? The full log contains too much information about my public product in it.

On Windows/Mac the recording seems to work ok. Just Android and iOS have problems.

orbitalnine commented 1 month ago

I think your email address was censored by your email server/client. Can you post on github directly?

orbitalnine commented 1 month ago

I'll just add my logcat file here logcat.txt

Chris-RH commented 1 month ago

ahh, ok, that's good to know. I knew that email replies didn't include any attachments, but I wasn't aware that it would censor email addresses. For future reference, our support email is unitysupport@renderheads.com

MorrisRH commented 1 month ago

I'm not seeing any log output for the captures being stopped in the logical provided, there should be something like the following:

[AVProMovieCapture] Stopping capture 53472
orbitalnine commented 1 month ago

I'm calling

if (Recorder.IsCapturing()) { Recorder.StopCapture(false, false, true); } CaptureBase.DeleteCapture(Recorder.OutputTarget, Recorder.LastFilePath);

when retrying a level

The only output line with "[AVProMovieCapture]" is "[AVProMovieCapture] Failed to create recorder" when the recording fails. There are lines like 2024-09-12 11:54:17.625 14572 15316 Debug MPEG4Writer Video track source stopping after each retry though

orbitalnine commented 1 month ago

Also, if I call

if (Recorder.IsCapturing())
{
    Recorder.StopCapture(true, true, true);
}

it immediately crashes the game logcat_crash.txt

MorrisRH commented 1 month ago

File writing is asynchronous on Android and iOS so when you call StopCapture it might not complete the file writing process immediately. Calling StopCapture(false, false, true) will delete the file when the recorder has finished so you should not need to call DeleteCapture directly and doing so might be harmful.

I can't reproduce a crash when calling StopCapture(true, true, true).

orbitalnine commented 1 month ago

The crash on StopCapture(true, true, true) happens everytime for me. This is on a Pixel 6, Android 14.

When I profile the demo project on my Android device I see memory is freed up when pressing the stop recording button. When I profile my project most of the memory is not freed up when stopping recording. A little bit is but most is not, so if i start/stop many times eventually I run out of memory. Is there something I should be doing to trigger the memory to be cleaned up when stopping a recording? Any settings for the video recorder that I should look at? I'm just calling StartCapture() at the start of a game level, and StopCapture() at the end. Is there something I'm missing?

orbitalnine commented 1 month ago

Here's what the memory looks like when start/stop recording 3 times:

VideoRecording
MorrisRH commented 1 month ago

Are you unloading the scene before the capture has completed?

orbitalnine commented 1 month ago

No. It looks like I missed the code in the demo for the cleanup. It seems a bit weird to manage the cleanup myself in an update loop, but it's working now. I'll close both of the issues i opened.

public void Update() { if (FileWritingHandler.Cleanup(m_fileWritingHandlers)) { if (m_fileWritingHandlers.Count == 0) { Debug.Log("All pending file writes completed"); } } }