Search Unity

NatCorder - Video Recording API

Discussion in 'Assets and Asset Store' started by Lanre, Nov 18, 2017.

  1. Viniterra

    Viniterra

    Joined:
    Dec 4, 2014
    Posts:
    151
    All UI elements are drawed normally, but the region where you click/touch is messed up, does not match the visual representation. This is just while recording, when stoped, all seems to work properly.
     
    Last edited: May 23, 2021
  2. Lanre

    Lanre

    Joined:
    Dec 26, 2013
    Posts:
    3,773
    Do you have an illustration of what's going on, just so I understand fully? Is your project using any AR framework, or something else that controls rendering?
     
  3. Viniterra

    Viniterra

    Joined:
    Dec 4, 2014
    Posts:
    151

    I am attaching a basic example to reproduce the issue.

    Import the NatShare by using git, then import the NatCorder package, after that import the example package.

    I have used Android as target platform to select the existing 18:9 landscape aspect. But it occurs in other non 16:9 aspects also.

    Navigate trought the UI and you'll see all working properly (The RGB buttons, the OK button, and the close button).

    Start recording and try to navigate again, and some of them are unresponsive. You will notice that the "cast area" of the buttons are displaced from the component visual representation.

    EDIT: I've just tested on latest LTS (2020.3.9f1) and the problem still occurs.
     

    Attached Files:

    Last edited: May 22, 2021
  4. Ikaro88

    Ikaro88

    Joined:
    Jun 6, 2016
    Posts:
    199
    I am not familiar with xcode, i tried to select the breakpoint tags and try to added the excepion point but I am not sure I done it correctly...

    This is a brakpoint that gone correctly


    And this is one that generate an error:





    also seems that i can not set the IL2CPP to debug because is not selectable




    After a few tries seems that the problem occurs when the number after recorder0 does not change...

    what I have to do?
    I am stuck with this :(
     
    Last edited: May 23, 2021
  5. Lanre

    Lanre

    Joined:
    Dec 26, 2013
    Posts:
    3,773
    I'll try to repro this and get back to you.
     
  6. Lanre

    Lanre

    Joined:
    Dec 26, 2013
    Posts:
    3,773
    Delete NatCorder in your project and import NatCorder 1.8 from the Asset Store. Then try again and let me know if the crash still happens.
     
  7. Ikaro88

    Ikaro88

    Joined:
    Jun 6, 2016
    Posts:
    199
    After doone that the error changed into a nullreferenceexception:

    From unity:
    Code (CSharp):
    1. Autoconnected Player NullReferenceException: Object reference not set to an instance of an object.
    2.   at NatSuite.Recorders.Inputs.CameraInput.Dispose () [0x00000] in <00000000000000000000000000000000>:0
    3.   at NatSuite.Examples.CameraRecorderReplay+<StopRecording>d__20.MoveNext () [0x00000] in <00000000000000000000000000000000>:0
    4.   at System.Threading.ContextCallback.Invoke (System.Object state) [0x00000] in <00000000000000000000000000000000>:0
    5.   at System.Threading.ExecutionContext.RunInternal (System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, System.Object state, System.Boolean preserveSyncCtx) [0x00000] in <00000000000000000000000000000000>:0
    6.   at System.Runtime.CompilerServices.AsyncMethodBuilderCore+MoveNextRunner.Run () [0x00000] in <00000000000000000000000000000000>:0
    7.   at System.Action.Invoke () [0x00000] in <00000000000000000000000000000000>:0
    8.   at System.Threading.SendOrPostCallback.Invoke (System.Object state) [0x00000] in <00000000000000000000000000000000>:0
    9.   at UnityEngine.UnitySynchronizationContext.Exec () [0x00000] in <00000000000000000000000000000000>:0
    10.   at UnityEngine.UnitySynchronizationContext.Exec () [0x00000] in <00000000000000000000000000000000>:0
    11. --- End of stack trace from previous location where exception was thrown ---
    12.   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x00000] in <00000000000000000000000000000000>:0
    13.   at System.Threading.SendOrPostCallback.Invoke (System.Object state) [0x00000] in <00000000000000000000000000000000>:0
    14.   at UnityEngine.UnitySynchronizationContext.Exec () [0x00000] in <00000000000000000000000000000000>:0
    15.   at UnityEngine.UnitySynchronizationContext.Exec () [0x00000] in <00000000000000000000000000000000>:0
    16. UnityEngine.UnitySynchronizationContext:Exec()
    17. UnityEngine.UnitySynchronizationContext:Exec()
    18. (Filename: currently not available on il2cpp Line: -1)
    From Xcode:

    Code (CSharp):
    1.  
    2.  
    3. NullReferenceException: Object reference not set to an instance of an object.
    4.   at NatSuite.Recorders.Inputs.CameraInput.Dispose () [0x00000] in <00000000000000000000000000000000>:0
    5.   at NatSuite.Examples.CameraRecorderReplay+<StopRecording>d__20.MoveNext () [0x00000] in <00000000000000000000000000000000>:0
    6.   at System.Threading.ContextCallback.Invoke (System.Object state) [0x00000] in <00000000000000000000000000000000>:0
    7.   at System.Threading.ExecutionContext.RunInternal (System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, System.Object state, System.Boolean preserveSyncCtx) [0x00000] in <00000000000000000000000000000000>:0
    8.   at System.Runtime.CompilerServices.AsyncMethodBuilderCore+MoveNextRunner.Run () [0x00000] in <00000000000000000000000000000000>:0
    9.   at System.Action.Invoke () [0x00000] in <00000000000000000000000000000000>:0
    10.   at System.Threading.SendOrPostCallback.Invoke (System.Object state) [0x00000] in <00000000000000000000000000000000>:0
    11.   at UnityEngine.UnitySynchronizationContext.Exec () [0x00000] in <00000000000000000000000000000000>:0
    12.   at UnityEngine.UnitySynchronizationContext.Exec () [0x00000] in <00000000000000000000000000000000>:0
    13. --- End of stack trace from previous location where exception was thrown ---
    14.   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x00000] in <00000000000000000000000000000000>:0
    15.   at System.Threading.SendOrPostCallback.Invoke (System.Object state) [0x00000] in <00000000000000000000000000000000>:0
    16.   at UnityEngine.UnitySynchronizationContext.Exec () [0x00000] in <00000000000000000000000000000000>:0
    17.   at UnityEngine.UnitySynchronizationContext.Exec () [0x00000] in <00000000000000000000000000000000>:0
    18. UnityEngine.UnitySynchronizationContext:Exec()
    19. UnityEngine.UnitySynchronizationContext:Exec()
    20. (Filename: currently not available on il2cpp Line: -1)
    21.  
    22. NullReferenceException: Object reference not set to an instance of an object.
    23.   at NatSuite.Recorders.Inputs.CameraInput.Dispose () [0x00000] in <00000000000000000000000000000000>:0
    24.   at NatSuite.Examples.CameraRecorderReplay+<StopRecording>d__20.MoveNext () [0x00000] in <00000000000000000000000000000000>:0
    25.   at System.Threading.ContextCallback.Invoke (System.Object state) [0x00000] in <00000000000000000000000000000000>:0
    26.   at System.Threading.ExecutionContext.RunInternal (System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, System.Object state, System.Boolean preserveSyncCtx) [0x00000] in <00000000000000000000000000000000>:0
    27.   at System.Runtime.CompilerServices.AsyncMethodBuilderCore+MoveNextRunner.Run () [0x00000] in <00000000000000000000000000000000>:0
    28.   at System.Action.Invoke () [0x00000] in <00000000000000000000000000000000>:0
    29.   at System.Threading.SendOrPostCallback.Invoke (System.Object state) [0x00000] in <00000000000000000000000000000000>:0
    30.   at UnityEngine.UnitySynchronizationContext.Exec () [0x00000] in <00000000000000000000000000000000>:0
    31.   at UnityEngine.UnitySynchronizationContext.Exec () [0x00000] in <00000000000000000000000000000000>:0
    32. --- End of stack trace from previous location where exception was thrown ---
    33.   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x00000] in <00000000000000000000000000000000>:0
    34.   at System.Threading.SendOrPostCallback.Invoke (System.Object state) [0x00000] in <00000000000000000000000000000000>:0
    35.   at UnityEngine.UnitySynchronizationContext.Exec () [0x00000] in <00000000000000000000000000000000>:0
    36.   at UnityEngine.UnitySynchronizationContext.Exec () [0x00000] in <00000000000000000000000000000000>:0
    37. UnityEngine.UnitySynchronizationContext:Exec()
    38. UnityEngine.UnitySynchronizationContext:Exec()
    39. (Filename: currently not available on il2cpp Line: -1)
    40.  

    How can I solve?
     
  8. Lanre

    Lanre

    Joined:
    Dec 26, 2013
    Posts:
    3,773
    You have a null reference in your code, so check your code and resolve it. This error isn't coming from NatCorder.
     
  9. Ikaro88

    Ikaro88

    Joined:
    Jun 6, 2016
    Posts:
    199
    But seems that the error is from:

    at NatSuite.Recorders.Inputs.CameraInput.Dispose ()

    so this seems the line that generates the error:

    public void Dispose () {
    GameObject.Destroy(attachment.gameObject);
    textureInput = null; // Auto-dispose
    }
    to be exactly this is the line:

    GameObject.Destroy(attachment.gameObject);

    Already check if cameranput is null so, to stop the call i need to call the cameraInput.dispose, but when i do that the error occurs

    I already share with you the code and you told me that was ok...
    I am missing something?
     
  10. Lanre

    Lanre

    Joined:
    Dec 26, 2013
    Posts:
    3,773
    The attachment can't be null unless you call Dispose more than once. Can you build the ReplayCam example and let me know if you see an error when you stop recording?
     
  11. Ikaro88

    Ikaro88

    Joined:
    Jun 6, 2016
    Posts:
    199
    To be sure of that i placed a debug before the command and it is not called more than 1 time... and the problem occurs only after a few recordings....

    But i tried anyway the example and the problem persist, at least the first one:



    I tried with a try catch to fix the error by myself but also if i do this:


    Code (CSharp):
    1.  try
    2.                 {
    3.                     cameraInput?.Dispose();
    4.                     Debug.Log("cameradisp");
    5.                     //  await Task.Delay(100);
    6.                     var path = await recorder.FinishWriting();
    7.                     // Playback recording
    8.                     Debug.Log($"Saved recording to: {path}");
    9.                     StartCoroutine(DeleteMic());
    10.                     callback(path);
    11.                 }
    12.                 catch (Exception e)
    13.                 {
    14.          
    15.                     CameraInputAttachment[] foundCanvasObjects = FindObjectsOfType<CameraInputAttachment>();
    16.                     for (int i = 0; i<foundCanvasObjects.Length; i++)
    17.                     {
    18.                         if(foundCanvasObjects[i].gameObject!=null)
    19.                         Destroy(foundCanvasObjects[i].gameObject);
    20.                     }
    21.  
    22.                     var path = await recorder.FinishWriting();
    23.                     Debug.LogError(e);
    24.                     StartCoroutine(DeleteMic());
    25.                     ToastMessage.Instance.SendSpecificMessage("error recording video");
    26.                     callback(path);
    27.                 }
    with a little modify in the cameraInput script but with this the error the foundCanvasObjects ALWAYS return 0
    And when it go on the catch part it give to me the error we discussed in the previus post...
    How to solve?

    After the update i get a little distortion in the audio when i use the AVPro videos...

    Please help me


    also
    in your demo, in the script:
    ReplayCam
    if i comment just this 2 lines:
    cameraInput = new CameraInput(recorder, clock, Camera.main);
    cameraInput.Dispose();

    When i stop recording the entire editor crash on windows, am I doing something wrong?

    Because i tried to follow your idea, i assumed that if cameraInput.attachment was null and there is no script in scene with CameraInputAttachment component i can finish the writing or at least create a new camera input....but it give me the previus error in both cases

    how to solve?
     
    Last edited: May 25, 2021
    ROBYER1 likes this.
  12. Viniterra

    Viniterra

    Joined:
    Dec 4, 2014
    Posts:
    151
    Unfortunately, it seems to be happening in 16:9 aspects also. On this demo scene, with the 1920x1080 screen aspect, which sets the recording resolution as 1280x720, the issue is still present.

    In my complete project, that has some more elaborated UI, even with the original 1280x720 screen aspect the issue occurs.

    It seems to be something related to adding the UI camera into the CameraInput Camera[] parameter.

    Alternatvely, are there any way to record the video by using the current frame, instead of passing specific game cameras? This is not the ideal soulution, since the record UI layer will be present, but due to my deadline, I need to address this problem someway.
     
  13. Ikaro88

    Ikaro88

    Joined:
    Jun 6, 2016
    Posts:
    199
    I notice that seems that after called:
    cameraInput = new CameraInput(recorder, clock, CameraRecorded);
    cameraInput.input" is null, so, i supposed that the problem is the Natcorder.
    If i try to create it again, the program crash

    It could be the unity version?
     
    Last edited: May 25, 2021
  14. bvisionary

    bvisionary

    Joined:
    Aug 4, 2019
    Posts:
    4
    Hi,
    We have the same problem, on IOS after few recordings from 3 to 12, the cameraInput.input result null after called new CameraInput, it is normal?

    how to solve?
     
  15. Viniterra

    Viniterra

    Joined:
    Dec 4, 2014
    Posts:
    151

    I have modified the example project, using only 1 orthographic camera, and added some colored line rendererers to identify the raycast areas of the UI elements.

    Here is an image of the results with the video recording turned off (left) and on (right), for different aspect ratios.

    raycast-areas.jpg

    Even the 16:9 layout seems to be messed up. I could not even find the cast area for the close button in some layouts.
     
  16. Lanre

    Lanre

    Joined:
    Dec 26, 2013
    Posts:
    3,773
    PM me your invoice # and email address; I'll send you a beta build of NatCorder 1.8.1 that we can use to investigate.
    You need to commit at least one frame. If not, recording will fail.
    Are you switching scenes by any chance? This is the only way that the attachment can be null without the CameraInput having been disposed yet.
     
  17. Lanre

    Lanre

    Joined:
    Dec 26, 2013
    Posts:
    3,773
    Can you PM me your invoice # and email? I fixed a minor bug in `CameraInput` that might resolve this. Also, what version of Unity are you using?
    Getting the current frame is the question. You'll need some way to render your scene into a RenderTexture, which is what the CameraInput script does for you.
     
  18. Lanre

    Lanre

    Joined:
    Dec 26, 2013
    Posts:
    3,773
    I've refactored this in NatCorder 1.8.1. PM me your invoice # and email and I'll send you the build.
     
  19. Lanre

    Lanre

    Joined:
    Dec 26, 2013
    Posts:
    3,773
    This is incredibly helpful, thanks.
     
  20. dora-lifeonmars

    dora-lifeonmars

    Joined:
    Jul 13, 2017
    Posts:
    1
    Hello
    I'm doing video recording on Android and getting sound from a microphone, but I'm having trouble with low volume.
    Is there any way to adjust the volume gain of the microphone?
     
  21. bvisionary

    bvisionary

    Joined:
    Aug 4, 2019
    Posts:
    4
    Thank you. I sent you a PM
     
    Lanre likes this.
  22. ROBYER1

    ROBYER1

    Joined:
    Oct 9, 2015
    Posts:
    1,213
    Why is this not fixed in Natcorder already, this one had me scratching my head for days in the editor!
     
  23. Lanre

    Lanre

    Joined:
    Dec 26, 2013
    Posts:
    3,773
    Hey there, I don't think you can change the volume of the microphone.
     
  24. Lanre

    Lanre

    Joined:
    Dec 26, 2013
    Posts:
    3,773
    This isn't something we can fix. The platform's native encoder will simply fail.
     
  25. ROBYER1

    ROBYER1

    Joined:
    Oct 9, 2015
    Posts:
    1,213
    Thanks for the clarification, I have amended the code in our app so it is fixed for us
     
  26. nobluff67

    nobluff67

    Joined:
    Nov 3, 2016
    Posts:
    259
    I am completely frustrated with your documentation and examples! Can you please just post a very simple script here to record 10 seconds of the game view (camera) when you press play, or do you maybe have a video tutorial?

    This should be so extremely easy todo with documentation that I can understand, however I don't see a workable example anywhere. I can not use any of your examples as they all require/ask for a cam. This is a game recording asset correct, or have I totally misunderstood the purpose of your asset?
     
  27. Lanre

    Lanre

    Joined:
    Dec 26, 2013
    Posts:
    3,773
    Have you seen this code snippet in the documentation? All you have to add in between the two code sections is a 10 second delay.
     
  28. nobluff67

    nobluff67

    Joined:
    Nov 3, 2016
    Posts:
    259
    Yes thanks found that useful. The result is horrible though (very jittery, finding this a common issue in this thread), but at least it creates a video. I'll post a couple of related questions (to my attempt) later, hopefully they can get answered.
     
    Lanre likes this.
  29. nobluff67

    nobluff67

    Joined:
    Nov 3, 2016
    Posts:
    259
    I have a jittering issue when I record. The issue only occurs on camera's with post processing TAA anti-aliasing mode, which I require. Do you have a solution for this?
     
  30. Lanre

    Lanre

    Joined:
    Dec 26, 2013
    Posts:
    3,773
    I'm afraid I can't assist you on this; I don't know enough of how TAA is implemented to advise on this. As far as NatCorder is concerned, the CameraInput script (which you are probably using) simply re-renders the game camera into a RenderTexture (you can check out the code for yourself). Perhaps TAA doesn't work when rendering off-screen.
     
    nobluff67 likes this.
  31. murakamik

    murakamik

    Joined:
    Mar 2, 2020
    Posts:
    1
    Hi Lanre.
    I'm using NatCorder1.8 with NCPX for recording RenderTexture.
    The performance is pretty good, but there is an issue.

    1) The first frame is black on both iOS and Android.
    2) This cause a black thumbnail when length of movie is short (shorter than about 1-2sec, depends on device, framerate, keyframeInterval.)

    My environment
    Unity2020.3.3
    NatCorder1.8
    NCPX latest

    Tested device.
    The first frame is black on every device.
    But rarely, a first frame become correct image.
    Huawei P30 lite Android10
    Asus ZenfoneAR Android7.0
    iPhone Xs iOS 14.4.2
    iPhone 12 pro max iOS14.4.2
    iPad air (4th) iOS14.4.4
     
  32. Ivegotalotofquestions

    Ivegotalotofquestions

    Joined:
    Feb 18, 2021
    Posts:
    5
    Hi,

    I tried NatCorder and everything works very well.

    Now I want to capture the player only “successful” gameplay into a single video. Let’s say there are three checkpoints and the player die once at stage 2. I want to dispose the first attempt at stage 2 so the final video is a complete successful attempt.

    Is there anyway to archive this? Is there any ways to stitch the clips? Or is it possible to dispose part of the video?

    Thank you for reading my question.
     
  33. Lanre

    Lanre

    Joined:
    Dec 26, 2013
    Posts:
    3,773
    I'll check this out. See the issue I've created here.
     
    muranken likes this.
  34. Lanre

    Lanre

    Joined:
    Dec 26, 2013
    Posts:
    3,773
    NatCorder doesn't support any video editing functionality; it only supports recording. There is an open-source video decoding library, NatReader, but it is a work in progress and only supports video. You can also try using Unity's VideoPlayer to playback the full video, but only record the parts you want using another recorder.
     
  35. Zenezim

    Zenezim

    Joined:
    Jun 5, 2021
    Posts:
    7
    Hi, are there any way to programatically avoid crashing when the device does not support a higher resolution than 1280x720?

    I have tried to use try/catch when creating the recorder, but the app still crashes.

    I want to automatically detect when the device does not support a higher resolution and disable the option for it.

    To manual profile each device it is pratically impossible...
     
  36. Lanre

    Lanre

    Joined:
    Dec 26, 2013
    Posts:
    3,773
    It's very rare to find a device that doesn't support a resolution greater than 1280x720 (see the XY problem). The crash you are experiencing is likely due to something else. Like on Android or Windows, if either your width or height is not divisible by two, the native encoder might cause a hard crash.

    Can you share more information about the crash? What device, OS version, and can you share the crash logs/report in a .txt attachment?
     
  37. Gango_98_

    Gango_98_

    Joined:
    Aug 10, 2020
    Posts:
    3
    Hi, I'm getting this error when I stop recording on my app on Android. In the editor it works.

    NatCorder Error: MediaWriter failed to finish writing media

    Here is my code:
    Code (CSharp):
    1.   private void StartRecording () {
    2.  
    3.         // Create a recorder
    4.         videoRecorder = new MP4Recorder(
    5.             videoWidth,
    6.             videoHeight,
    7.             30,
    8.             44100,
    9.             1
    10.         );
    11.  
    12.         recordingClock = new RealtimeClock();
    13.         cameraInput = new CameraInput(videoRecorder, recordingClock, camerasToRecord);      
    14.     }
    15.  
    16.     private async void StopRecording() {
    17.         // Stop sending frames to the recorder
    18.         cameraInput.Dispose();
    19.         // Finish writing
    20.         string path = await videoRecorder.FinishWriting();
    21.  
    22.         OnFinished(path);
    23.     }
    24.  
    25.     private void OnFinished(string path) {
    26.         videoPath = path;
    27.         StartCoroutine(playVideo(path));
    28.     }
    Here is the full logcat:

    Code (CSharp):
    1. 2021/06/10 15:52:43.854 4443 5472 Info MPEG4Writer Received total/0-length (0/0) buffers and encoded 0 frames. - Audio
    2. 2021/06/10 15:52:43.854 4443 5472 Info MPEG4Writer Audio track drift time: 0 us
    3. 2021/06/10 15:52:43.854 4443 5471 Info MPEG4Writer Received total/0-length (62/0) buffers and encoded 62 frames. - Video
    4. 2021/06/10 15:52:43.854 4443 5470 Info MPEG4Writer writeChunkToFile E: from Video track (2818085us)
    5. 2021/06/10 15:52:43.857 4443 5453 Debug MPEG4Writer Audio track stopped. Stop source
    6. 2021/06/10 15:52:43.857 4443 5470 Info MPEG4Writer writeChunkToFile X: from Video track, WriteSize(1071620 byte)
    7. 2021/06/10 15:52:43.857 4443 5453 Debug MPEG4Writer Video track stopping. Stop source
    8. 2021/06/10 15:52:43.857 4443 5453 Debug MPEG4Writer Video track source stopping
    9. 2021/06/10 15:52:43.857 4443 5453 Debug MPEG4Writer Video track source stopped
    10. 2021/06/10 15:52:43.857 4443 5453 Debug MPEG4Writer Video track stopped. Stop source
    11. 2021/06/10 15:52:43.857 4443 5453 Debug MPEG4Writer Duration from tracks range is [0, 2858842] us
    12. 2021/06/10 15:52:43.857 4443 5453 Debug MPEG4Writer Stopping writer thread
    13. 2021/06/10 15:52:43.857 4443 5470 Debug MPEG4Writer 0 chunks are written in the last batch
    14. 2021/06/10 15:52:43.858 4443 5453 Debug MPEG4Writer Writer thread stopped
    15.  
    16. 2021/06/10 15:52:43.860 4443 5453 Error NatSuite NatCorder Error: MediaWriter failed to finish writing media
    17. 2021/06/10 15:52:43.860 4443 5453 Error NatSuite java.lang.IllegalStateException: Failed to stop the muxer
    18. 2021/06/10 15:52:43.860 4443 5453 Error NatSuite     at android.media.MediaMuxer.nativeStop(Native Method)
    19. 2021/06/10 15:52:43.860 4443 5453 Error NatSuite     at android.media.MediaMuxer.stop(MediaMuxer.java:467)
    20. 2021/06/10 15:52:43.860 4443 5453 Error NatSuite     at api.natsuite.natcorder.internal.MediaWriter.finishWriting(MediaWriter.java:58)
    21. 2021/06/10 15:52:43.860 4443 5453 Error NatSuite     at api.natsuite.natcorder.internal.AVMediaWriter.finishWriting(AVMediaWriter.java:91)
    22. 2021/06/10 15:52:43.860 4443 5453 Error NatSuite     at api.natsuite.natcorder.internal.HardwareRecorder$1.run(HardwareRecorder.java:152)
    23. 2021/06/10 15:52:43.860 4443 5453 Error NatSuite     at java.lang.Thread.run(Thread.java:919)
    24. 2021/06/10 15:52:43.933 4443 4531 Error Unity Exception: Recorder failed to finish writing
    25. 2021/06/10 15:52:43.933 4443 4531 Error Unity   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x00000] in <00000000000000000000000000000000>:0
    26. 2021/06/10 15:52:43.933 4443 4531 Error Unity   at System.Runtime.CompilerServices.TaskAwaiter`1[TResult].GetResult () [0x00000] in <00000000000000000000000000000000>:0
    27. 2021/06/10 15:52:43.933 4443 4531 Error Unity   at CaptureManager+<StopRecording>d__42.MoveNext () [0x00000] in <00000000000000000000000000000000>:0
    28. 2021/06/10 15:52:43.933 4443 4531 Error Unity   at System.Threading.ContextCallback.Invoke (System.Object state) [0x00000] in <00000000000000000000000000000000>:0
    29. 2021/06/10 15:52:43.933 4443 4531 Error Unity   at System.Threading.ExecutionContext.RunInternal (System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, System.Object state, System.Boolean preserveSyncCtx) [0x00000] in <00000000000000000000000000000000>:0
    30. 2021/06/10 15:52:43.933 4443 4531 Error Unity   at System.Runtime.CompilerServices.AsyncMethodBuilderCore+MoveNextRunner.Run () [0x00000] in <00000000000000000000000000000000>:0
    31. 2021/06/10 15:52:43.933 4443 4531 Error Unity   at System.Action.Invoke () [0x00000] in <00000000000000000000000000000000>:0
    32. 2021/06/10 15:52:43.933 4443 4531 Error Unity   at System.Threading.SendOrPostCallback.Invoke
    33.  

    -----------------------------------------

    Here is my setup:
    - Unity 2020.3.7f1
    - Natcorder 1.8.0 (Edited: I wrongly wrote 1.6.2)

    Android build with
    - IL2CPP
    - Net Standard 2.0
    - ARMv7, ARM64
    - Minimum API Level: Android 7.0 (API level 24)

    I'm using an LG G7 ThinQ with Android 10
     
    Last edited: Jun 10, 2021
  38. Zenezim

    Zenezim

    Joined:
    Jun 5, 2021
    Posts:
    7

    The device is a Samsung Galaxy Tab A7, model SM-T500, Android 11. I am trying to pass its native screen resolution (2000 x 1200) to the recorder. As soon as I instantiate, it crashes. I've tried with 1920x1080 also, and it still crashes.

    I have to build the app on the device to run it, how can I generate the log on a android device for a Unity app to see the errors?

    EDIT: I have attached the Visual Studio Unity Debugger to the Android. WHen the crash happens, no error is displayed. It seems to be an internal error related to the native activity on android that instantiates the recorder. I believe there are no error treatments in the activity return, so I cannot see any log of it.
     
    Last edited: Jun 10, 2021
  39. Lanre

    Lanre

    Joined:
    Dec 26, 2013
    Posts:
    3,773
    You'll need to use the logcat tool that is provided with the Android SDK. It dumps logs from all processes on Android, and with that much information, you're typically able to find the exact cause of a crash without much room left for speculation.
     
  40. jiraphatK

    jiraphatK

    Joined:
    Sep 29, 2018
    Posts:
    116
    Meanwhile, I'm using this code to circumvent the first frame black.

    Code (CSharp):
    1.  
    2. var frameBuffer = RenderTexture.GetTemporary(frameDescriptor);
    3. for (var i = 0; i < cameras.Length; i++)
    4.     CommitFrame(cameras[i], frameBuffer);
    5. // Commit
    6. if (currentFrameIndex == 0)
    7. {
    8.     var prev = RenderTexture.active;
    9.     RenderTexture.active = frameBuffer;
    10.     Texture2D rt = new Texture2D(frameDescriptor.width, frameDescriptor.height, TextureFormat.RGBA32, false, false);
    11.     rt.ReadPixels(new Rect(0,0,frameDescriptor.width,frameDescriptor.height),0,0,false);
    12.     recorder?.CommitFrame(NativeArrayUnsafeUtility.GetUnsafeBufferPointerWithoutChecks(rt.GetRawTextureData<byte>()),clock?.timestamp ?? 0L);
    13.     RenderTexture.active = prev;
    14. }
    15. else
    16. {
    17.     input?.CommitFrame(frameBuffer, clock?.timestamp ?? 0L);
    18.     RenderTexture.ReleaseTemporary(frameBuffer);
    19. }
    20. currentFrameIndex++;
    21.  
     
  41. jiraphatK

    jiraphatK

    Joined:
    Sep 29, 2018
    Posts:
    116
    Apparently, the above code will make the 2nd frame black ugh..... :(
    Screenshot_20210611_151311_com.framebyframe.jpg
     
  42. Lanre

    Lanre

    Joined:
    Dec 26, 2013
    Posts:
    3,773
    I've started looking into this bug. I'll have updates late today or tomorrow.
     
  43. Zenezim

    Zenezim

    Joined:
    Jun 5, 2021
    Posts:
    7
    Thank you for the feedback, I'll try to configure the logcat to provide the response and post it here.
     
    Lanre likes this.
  44. Zenezim

    Zenezim

    Joined:
    Jun 5, 2021
    Posts:
    7
    I've extracted the logcat for the crash:

    On a quick search for this error 0xfffffc0e I've found some people talking about a video dimension related issue. In this case it is not the multiple of 2 case, since the tested resolutions are multiple of 2 (2000 x 1200 and 1920x1080 ). Any ideas?
     
  45. Lanre

    Lanre

    Joined:
    Dec 26, 2013
    Posts:
    3,773
    Try recapturing the logs, but capture everything from app start to crash. The codec typically logs the reason for the crash before the crash itself shows up.
     
  46. Zenezim

    Zenezim

    Joined:
    Jun 5, 2021
    Posts:
    7
    The full log is attached.
     

    Attached Files:

    • log.txt
      File size:
      1.1 MB
      Views:
      30
  47. Lanre

    Lanre

    Joined:
    Dec 26, 2013
    Posts:
    3,773
    Here's the relevant info from the logs:
    Code (CSharp):
    1. I OMX-VENC: Component_init : OMX.qcom.video.encoder.avc : return = 0x0
    2. I ACodec  : [OMX.qcom.video.encoder.avc] Now Loaded
    3. W OMXNodeInstance: setParameter(0xf6b952c4:qcom.encoder.avc, OMX.google.android.index.allocateNativeHandle(0x7f00005d): Input:0 en=0) (0x80001019)
    4. W OMXNodeInstance: setParameter(0xf6b952c4:qcom.encoder.avc, OMX.google.android.index.allocateNativeHandle(0x7f00005d): Output:1 en=0) (0x80001019)
    5. E OMX-VENC: venc_dev: set format failed, type 10, wxh 1200x2000, pixelformat 0x3231564e, colorspace 0x6
    6. E OMX-VENC: ERROR: venc_set_param input failed
    7. W OMXNodeInstance: setParameter(0xf6b952c4:qcom.encoder.avc, ParamPortDefinition(0x2000001)) (0x80001019)
    8. E ACodec  : [OMX.qcom.video.encoder.avc] failed to set input port definition parameters.
    9. E ACodec  : [OMX.qcom.video.encoder.avc] configureCodec returning error -1010
    10. E ACodec  : signalError(omxError 0x80001001, internalError -1010)
    11. E MediaCodec: Codec reported err 0xfffffc0e, actionCode 0, while in state 3
    12. E MediaCodec: configure failed with err 0xfffffc0e, resetting...
    What device and Android version are you testing on? It seems to not support 1200x2000 specifically. Can you try recording at 1280x720? If the same crash occurs, then your device likely doesn't fully support the Android encoding requirements.
     
  48. Zenezim

    Zenezim

    Joined:
    Jun 5, 2021
    Posts:
    7
    I already mentioned the device specs here (Samsung galaxy tab a7, Android 11): #3787

    The 1200x2000 is the native screen resolution for this device. By using 1280x720 it works normally.

    The native part of your package does not seem deal with that exception, so the app crashes. I need a way to avoid this crash. Many other Android devices supports its native resolution, being it larger than 1200x2000. Basically I want to record at native screen resoluton every time it is possible.

    Again, on my first post (#3785), I asked for a way to detect that a device does not support a resolution (in this case, the device native screen resolution). By detecting this, I can lower the resolution and also prevent the app from crashing.

    I believe this is a better way than making a manual profile for each device that exists.
     
  49. Lanre

    Lanre

    Joined:
    Dec 26, 2013
    Posts:
    3,773
    I'll add a check for this and make the `MP4Recorder` constructor throw a managed exception. This way, you can then create a recorder with a smaller resolution. I won't be adding a way to check if a resolution is supported, because this isn't exposed across different platforms. This fix will be in NatCorder 1.8.1.
     
  50. Zenezim

    Zenezim

    Joined:
    Jun 5, 2021
    Posts:
    7
    This fix will work for me, thanks.
     
    Lanre likes this.
unityunity