videokit
videokit copied to clipboard
Standalone app crashes when creating a MP4 MediaRecorder
Description:
Standalone app crashes in the MediaRecorder creation.
How to Reproduce
I'm using the following code for my tests. Create a scene with a couple of buttons to call StartRecording()
and StopRecording()
and build it to standalone. It works in the editor. But when I generate the build, the app crashes as soon as I call StartRecording
. I've tested on 3 different PCs, and got the same crash stack in all of them:
using UnityEngine;
using VideoKit;
using VideoKit.Sources;
using VideoKit.Clocks;
public class ScreenRecorder : MonoBehaviour
{
public TMPro.TextMeshProUGUI PathText;
private MediaRecorder videoRecorder;
private ScreenSource screenSource;
private IClock recordingClock;
public async void StartRecording()
{
recordingClock = new RealtimeClock();
var videoWidth = Screen.width;
var videoHeight = Screen.height;
videoRecorder = await MediaRecorder.Create(MediaRecorder.Format.MP4, videoWidth, videoHeight, 30);
screenSource = new ScreenSource(videoRecorder, recordingClock);
PathText.text = "Recording...";
}
public async void StopRecording()
{
screenSource?.Dispose();
screenSource = null;
var asset = await videoRecorder.FinishWriting();
Debug.Log("VIDEO PATH: " + asset.path);
PathText.text = "Saved at " + asset.path;
}
}
Crash Stack
========== OUTPUTTING STACK TRACE ==================
0x00007FFA30A60E86 (VideoKit) VKTPixelBufferCreatePlanar
0x00007FFA30A6555B (VideoKit) VKTMediaRecorderCreateMP4
0x00000187AEA96D20 (Mono JIT Code) (wrapper managed-to-native) VideoKit.Internal.VideoKit:CreateMP4Recorder (string,int,int,single,int,int,int,int,int,intptr&)
0x00000187AE305D83 (Mono JIT Code) VideoKit.MediaRecorder/<Create>d__15:MoveNext ()
0x00000187AEA4F772 (Mono JIT Code) System.Runtime.CompilerServices.AsyncMethodBuilderCore/MoveNextRunner:InvokeMoveNext (object)
0x00000187AEA4F3FE (Mono JIT Code) System.Threading.ExecutionContext:RunInternal (System.Threading.ExecutionContext,System.Threading.ContextCallback,object,bool)
0x00000187AEA4F1DB (Mono JIT Code) System.Threading.ExecutionContext:Run (System.Threading.ExecutionContext,System.Threading.ContextCallback,object,bool)
0x00000187AEA4F0CB (Mono JIT Code) System.Runtime.CompilerServices.AsyncMethodBuilderCore/MoveNextRunner:Run ()
0x00000187AEA81B4A (Mono JIT Code) System.Threading.Tasks.AwaitTaskContinuation:InvokeAction (object)
0x00000187AEA81955 (Mono JIT Code) System.Threading.Tasks.AwaitTaskContinuation:RunCallback (System.Threading.ContextCallback,object,System.Threading.Tasks.Task&)
0x00000187AEA817B3 (Mono JIT Code) System.Threading.Tasks.SynchronizationContextAwaitTaskContinuation:Run (System.Threading.Tasks.Task,bool)
0x00000187AEA80C07 (Mono JIT Code) System.Threading.Tasks.Task:FinishContinuations ()
0x00000187AEA807A3 (Mono JIT Code) System.Threading.Tasks.Task:FinishStageThree ()
0x00000187AEA82423 (Mono JIT Code) System.Threading.Tasks.Task`1<VideoKit.Internal.VideoKit/Status>:TrySetResult (VideoKit.Internal.VideoKit/Status)
0x00000187AEA822B3 (Mono JIT Code) System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1<VideoKit.Internal.VideoKit/Status>:SetResult (VideoKit.Internal.VideoKit/Status)
0x00000187AE307333 (Mono JIT Code) VideoKit.Internal.VideoKitClient/<CheckSession>d__8:MoveNext ()
0x00000187AEA4F772 (Mono JIT Code) System.Runtime.CompilerServices.AsyncMethodBuilderCore/MoveNextRunner:InvokeMoveNext (object)
0x00000187AEA4F3FE (Mono JIT Code) System.Threading.ExecutionContext:RunInternal (System.Threading.ExecutionContext,System.Threading.ContextCallback,object,bool)
0x00000187AEA4F1DB (Mono JIT Code) System.Threading.ExecutionContext:Run (System.Threading.ExecutionContext,System.Threading.ContextCallback,object,bool)
0x00000187AEA4F0CB (Mono JIT Code) System.Runtime.CompilerServices.AsyncMethodBuilderCore/MoveNextRunner:Run ()
0x00000187AEA81B4A (Mono JIT Code) System.Threading.Tasks.AwaitTaskContinuation:InvokeAction (object)
0x00000187AEA81955 (Mono JIT Code) System.Threading.Tasks.AwaitTaskContinuation:RunCallback (System.Threading.ContextCallback,object,System.Threading.Tasks.Task&)
0x00000187AEA817B3 (Mono JIT Code) System.Threading.Tasks.SynchronizationContextAwaitTaskContinuation:Run (System.Threading.Tasks.Task,bool)
0x00000187AEA80C07 (Mono JIT Code) System.Threading.Tasks.Task:FinishContinuations ()
0x00000187AEA807A3 (Mono JIT Code) System.Threading.Tasks.Task:FinishStageThree ()
0x00000187AEA80583 (Mono JIT Code) System.Threading.Tasks.Task`1<TResult_REF>:TrySetResult (TResult_REF)
0x00000187AEA803B3 (Mono JIT Code) System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1<TResult_REF>:SetResult (TResult_REF)
0x00000187AE308943 (Mono JIT Code) VideoKit.Internal.VideoKitClient/<CreateSessionToken>d__20:MoveNext ()
0x00000187AEA4F772 (Mono JIT Code) System.Runtime.CompilerServices.AsyncMethodBuilderCore/MoveNextRunner:InvokeMoveNext (object)
0x00000187AEA4F3FE (Mono JIT Code) System.Threading.ExecutionContext:RunInternal (System.Threading.ExecutionContext,System.Threading.ContextCallback,object,bool)
0x00000187AEA4F1DB (Mono JIT Code) System.Threading.ExecutionContext:Run (System.Threading.ExecutionContext,System.Threading.ContextCallback,object,bool)
0x00000187AEA4F0CB (Mono JIT Code) System.Runtime.CompilerServices.AsyncMethodBuilderCore/MoveNextRunner:Run ()
0x00000187AEA4EF7A (Mono JIT Code) System.Runtime.CompilerServices.YieldAwaitable/YieldAwaiter:RunAction (object)
0x00000187AEA4EE84 (Mono JIT Code) UnityEngine.UnitySynchronizationContext/WorkRequest:Invoke ()
0x00000187AE2A0EE3 (Mono JIT Code) UnityEngine.UnitySynchronizationContext:Exec ()
0x00000187AE2A0B7B (Mono JIT Code) UnityEngine.UnitySynchronizationContext:ExecuteTasks ()
0x0000018713C11575 (Mono JIT Code) (wrapper runtime-invoke) object:runtime_invoke_void (object,intptr,intptr,intptr)
0x00007FF92E374BFE (mono-2.0-bdwgc) mono_jit_set_domain
0x00007FF92E2AD254 (mono-2.0-bdwgc) mono_object_get_virtual_method
0x00007FF92E2AD3CC (mono-2.0-bdwgc) mono_runtime_invoke
0x00007FF92F361229 (UnityPlayer) ScriptingInvocation::Invoke<void>
0x00007FF92F10E3B7 (UnityPlayer) `InitPlayerLoopCallbacks'::`2'::UpdateScriptRunDelayedTasksRegistrator::Forward
0x00007FF92F0FD797 (UnityPlayer) ExecutePlayerLoop
0x00007FF92F0FD96F (UnityPlayer) ExecutePlayerLoop
0x00007FF92F0FDDB2 (UnityPlayer) PlayerLoop
0x00007FF92F3544AB (UnityPlayer) PerformMainLoop
0x00007FF92F356F0B (UnityPlayer) MainMessageLoop
0x00007FF92F35A2BB (UnityPlayer) UnityMainImpl
0x00007FF92F35A55B (UnityPlayer) UnityMain
0x00007FF7433211F2 (holo one) __scrt_common_main_seh
0x00007FFA4085257D (KERNEL32) BaseThreadInitThunk
0x00007FFA425CAF28 (ntdll) RtlUserThreadStart
========== END OF STACKTRACE ===========
Environment:
Unity Version: 2022.3.20f1 Editor Platform: Windows 11 Target Platform: Standalone VideoKit Library Version: 0.0.21