Closed artoonie closed 1 year ago
Hi @artoonie Thanks for letting us know. If you can provide any further details, we'd be most grateful, such as:
Awesome, thanks for the extra info. Hopefully we'll be able to narrow down what is causing the problem.
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.
Hey @artoonie, has this been occurring at all in the newer versions?
Hi Chris, I have still been seeing it, <1% of the time. It only occurs on iOS, and spans all OSs and devices. Here are the stats I have on it:
As hinted at above, I now have a workaround that's not great but is workable: if NumEncodedFrames
doesn't increase for 1 second, I stop the recording, log a bug, and restart. I can add whatever logs you need when I log the bug, so if there's something that would help debug, I'm happy to Debug.Log
it and send it to you.
My hunch is that it's related to one recording finishing writing while another one starts. My use case is the following:
Hi @artoonie, Thank you for the extra information, that's very helpful. Logs would be great if you've got a chance, thank you :)
Sounds good - currently I'm just printing out CaptureStats
, which doesn't seem to contain anything useful for debugging this. Is there anything else I should log? (See initial post for the contents of CaptureStats
)
Our iOS dev is on holiday at the moment, so I'll see if he wants anything specific when he gets back, thanks 😊
On Wed, 17 Aug 2022, 18:34 Armin Samii, @.***> wrote:
Sounds good - currently I'm just printing out CaptureStats, which doesn't seem to contain anything useful for debugging this. Is there anything else I should log? (See initial post for the contents of CaptureStats)
— Reply to this email directly, view it on GitHub https://github.com/RenderHeads/UnityPlugin-AVProMovieCapture/issues/180#issuecomment-1218308994, or unsubscribe https://github.com/notifications/unsubscribe-auth/AYRROUPKIZX6CWG622FNJSLVZUPC3ANCNFSM54H5T5LA . You are receiving this because you commented.Message ID: @.*** com>
Well this is quite weird.
As you're getting a valid movie file output something is definitely calling stop on the recorder. This could be being triggered by the app being sent to the background, for example if the device received a call this would happen.
I'll need to rig a test scene for this so if I could just check a few things:
RenderTexture
, so the WebCamTexture
is probably irrelevantSome additional information: I would expect to see this same behavior if the RenderTexture
is reinitialized without calling SetSourceTexture
again:
RenderTexture tex = new RenderTexture(w, h, 0, RenderTextureFormat.ARGB32);
captureFromTexture.SetSourceTexture(tex);
/* Write ten frames */
tex = new RenderTexture(w, h, 0, RenderTextureFormat.ARGB32);
However, I have several checks in the code to ensure this isn't happening. I don't know if this is the actual cause, but it seems like CaptureFromTexture
is "losing" the RenderTexture
- as if Unity changed RenderTexture
under the hood. This hunch could be a red herring.
It does feel like the RenderTexture's underlying native texture has been lost. I take it this is a real time capture then and you're not using the manual frame update mode?
Correct, this is real time capture.
I'll add some debug logs to print out sourceTexture.GetNativeTexturePtr()
every so often. When I detect this bug is encountered, I should be able to see if that value has unexpectedly changed - that may help pin this down. LMK if there's other info I should be periodically logging.
So I rigged a test scene matching your description: webcam texture -> blit with custom shader to render texture -> capture from texture component. Unfortunately it worked perfectly and I now have approx. 9 hours of 10 minute clips. This was using and iPad Pro (10.5") with iOS 15.6.1. I'll switch to another device to see if that has any influence (it will be an iPhone X running iOS 14.8.1).
The capture size was 1024x1024, outputting to h264 with audio coming from the microphone.
If you could share one of the full 10 minute broken videos that might yield some clues.
This is the test script I'm using. The capture component is using the default settings.
Thank you for doing that test - the code is indeed similar to what I'm doing on my end.
The bug was last reproduced with 5.0.1
- it's unlikely, but possible that it was resolved in 5.0.2
- more likely, it just hasn't been reproduced yet. (5.0.2
has not been rolled out to most of my users yet.)
Note, the 10 second attached video above is an example of a 10-minute recording; just, it stopped after 10 seconds and remained that way until I called StopCapture 590 seconds later.
For now, it seems I can't rule out that the bug is on my end, so I'm happy to leave this as CNR
and the burden will be on me to show whether the bug is really in AVProMovieCapture
, or if it's on my end. I'll continue adding information to this thread, but I'm okay if you don't spend any additional resources on this until I have more actionable information. Thanks for what you've done thus far!
I may have reproduced this. It took about 4 hours to show up on the iPhone X and I've only managed to get it to happen once. It was caused by a race condition in the microphone audio capture when finishing a recording.
I've put in a fix which will make it into the next release. I've had the iPhone X running for ~18 hours (and it's still going) now with this in so I'm hopeful that I've caught it.
Wow! Thank you @MorrisRH for dozens of hours of testing here. Looking forward to the next release. 🎉
The latest version has been released, please let us know if this issue has not been fixed.
Closing this issue for now, if it still happens please let us know and we'll reopen it.
Hi, I've just gotten my first report of this issue still happening with 5.0.3
- any ideas / what debug info can I provide? As before, I'm limited to Debug.Log data, since it's very hard to reproduce, and that shows nothing strange.
Hi @artoonie,
Thanks for letting us know. There isn't that much that can be done until its reproducible. If you could let us know which model of device and iOS version this is occurring on please, it would help. Also, any logs that you can get may point us in the right direction.
Thank you, I will!
This has occurred on iPhone11,8 (iPhone XR) and iPhone13,2 (iPhone 12), on iOS 15 and 16.
It is also possible that my detection of the bug just needs a stricter threshold: right now, I check if m_Capture.CaptureStats.FramesTotal
doesn't change for 60 frames in a row. Is it possible that there's a reason, other than this bug, that FramesTotal
wouldn't change for 60 frames in a row?
I'll also note that this isn't urgent for me because it's easily detectable on my end, and I only lose two seconds of footage before I recover. I'm okay with this being marked low-priority.
I'm trying a different approach to resolving this. I've got the same test as before running and it's been going for over a day now. I am wondering if some external event is acting as the trigger though, a call or notification that maybe interrupting things?
An unintentional 2FA request did cause a capture to stop, however call and text notification had no effect so we can discount those. The app didn't crash though so the test picked up again.
Not sure if the -> applicationWillResignActive()
log gets output in release builds but that would be indicative of an event happening that would stop a capture.
I manually pause capture and log output OnApplicationPause
, so that would get outputted and I don't think could be the cause
We stop capturing on iOS in response to OnApplicationPause, this is in CaptureBase.cs line 1420. Wondering if there is a conflict there...
It's possible, but I would guess not: I still Debug.Log
OnApplicationPause
, and those logs aren't appearing.
I'm going to add this new approach to the next release (5.0.5). I had my test scene running for over 48 hours without a hitch so hoping this has got it.
The next version has been released, please let us know if this has not fixed the issue.
This bug isn't totally fixed, but I recognize y'all have put a lot of work into investigating already and I'm doing my best to find a workaround on my end. Still, I wanted to provide some information in case it proves useful to you or others.
m_Capture.CaptureStats.FramesTotal
doesn't change for 4 seconds, I restart the video. About 95% of the time, the restarted video works. However, about 5% of the time, the restarted video is a static video that is just getting the same frame over and over. m_Capture.CaptureStats.FramesTotal
increments as expected, but the video file is just one static frame (with correct audio).Here are some stats on which users encounter the broken video. You can see that it trends towards lower-end phones.
I believe, but am not 100% confident, that the secondary bug (the frozen video with incrementing m_Capture.CaptureStats.FramesTotal
) only occurs when the previous broken video returns handler.IsFileReady()==false
forever.
To summarize each video in this scenario:
StartCapture
calledStopCapture
then immediately StartCapture
StopCapture
then immediately StartCapture
Video 1 is ten minutes long and correct. Video 2 is always between 8 and 12 seconds long, with no new frames for the last 4 seconds of the video
~95% of the time, Video 3 is fine.
~5% of the time:
Video 2's handler.IsFileReady()
always returns false
Video 3 is ten minutes long, but repeats Frame 1 for every frame throughout the video. handler.IsFileReady()
eventually returns true as expected. The audio works fine. The file size is about 25% smaller than Video 1.
Thanks for the very detailed report :)
Seeing as its generally older/lower end devices, its most likely a hardware/OS level issue. It is probably the system running out of encoder resources and being unable to encode any more frames. This might be improved if you wait until the previous capture has finished completely (thus releasing encoder resources) before starting the next one.
That's a great idea. I'll put in a pause between Video 2 and Video 3 above.
I'll get back to you in about a month after our next deployment to see if this helped.
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.
Describe the bug Occasionally (about 1 in 100 videos), the capture stops after 5-10 seconds. There are no error messages. The video just stops encoding.
Your Setup (please complete the following information):
To Reproduce Unfortunately, I don't have reliably reproducible steps, so I can't give too much useful information here. I still wanted to flag, in case others can find a way to reproduce, or in the hopes that you may somehow know what's going on.
Here's what happens:
StopCapture
later, everything seems to work as I expect.Logs Once it hits the bug, CaptureStats looks like this:
And it prints out the same thing every frame. That's also my workaround: if NumEncodedFrames isn't increasing after some time, I'm going to manually stop and start capture.
Videos Attached is one video where this has happened. Let me know if you would like additional videos.
https://user-images.githubusercontent.com/537316/180242743-ad987fbb-b2a8-496c-ae95-fe5180683b9e.MP4