Search Unity

NatCorder - Video Recording API

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

  1. pjaimin

    pjaimin

    Joined:
    Nov 3, 2018
    Posts:
    13
    I checked for audio settings but everything seems normal to me. While playing ion unity is working fine but recorded video has noise itself.
     
  2. nsmith1024

    nsmith1024

    Joined:
    Mar 18, 2014
    Posts:
    870
    Does you video/audio recorder work on MAC desktop?
     
  3. Lanre

    Lanre

    Joined:
    Dec 26, 2013
    Posts:
    3,973
    A good way to test audio recording by itself is to use the WAVRecorder. Try swapping out your MP4Recorder for a WAVRecorder and let me know if the generated .wav file also has noise.
     
  4. Lanre

    Lanre

    Joined:
    Dec 26, 2013
    Posts:
    3,973
  5. Masoverflow

    Masoverflow

    Joined:
    Jan 20, 2013
    Posts:
    5
    Hi,
    In our HEVC camera input recordings on IOS we're seeing multiple black frames at the very start and very end of the video.

    The app is running at 60 fps with the skip frame boolean enabled so the video is recorded at 30 fps.

    Is there a simple way to trim the start and end, just the first and last 6 frames before the video is created.
    Or maybe you're aware of this issue and there is another solution the resolves it.

    Thanks.
     
  6. Lanre

    Lanre

    Joined:
    Dec 26, 2013
    Posts:
    3,973
    I'm not aware of this issue. Does this happen if you disable frame skipping?
     
  7. Masoverflow

    Masoverflow

    Joined:
    Jan 20, 2013
    Posts:
    5
    Hi,
    So I've done a bunch of recording both with and without frame skipping and the only once was it multiple black frames, start and end, a few times the first frame was black but most of the time it works perfect.

    The real issue I've noticed is the video appears to be being squished, we're recording on a IOS phone with 2778x1284 resolution and setting the HEVC recorder to 1920x1080. I've seen earlier in this thread that it is supposed to work like a render texture so it shouldn't be squished.
    Some videos here that show the squish, second one has a square behind that appears as a rectangle (video1) (video2)

    I use this to begin the recording:
    Code (CSharp):
    1. if (Screen.height > Screen.width)
    2. {
    3.     width = 1080;
    4.     height = 1920;
    5. }
    6. else
    7. {
    8.     width = 1920;
    9.     height = 1080;
    10. }
    11. recordingClock = new RealtimeClock();
    12. videoRecorder = new HEVCRecorder(width, height, 30, AudioSettings.outputSampleRate, (int)AudioSettings.speakerMode);
    13. cameraInput = new CameraInput(videoRecorder, recordingClock, Camera.main);
    14. cameraInput.frameSkip = 1;
    15. if (audioListener == null) audioListener = FindObjectOfType<AudioListener>();
    16. audioInput = new AudioInput(videoRecorder, recordingClock, audioListener);
    This to end (the delete/move is to rename the file since sharing show's the end user the filename):
    Code (CSharp):
    1. audioInput?.Dispose();
    2. cameraInput.Dispose();
    3. string oldPath = await videoRecorder.FinishWriting();
    4.  
    5. await Task.Delay(100);
    6.  
    7. _path = Path.Combine(oldPath.Replace(Path.GetFileName(oldPath), ""), "Recorded_Clip.mp4");
    8. File.Delete(_path);
    9. File.Move(oldPath, _path);
    And this to save (_path is a member variable of the class with these methods):
    Code (CSharp):
    1. var payload = new SharePayload();
    2. payload.AddMedia(_path);
    3. var success = await payload.Commit();
     
  8. Lanre

    Lanre

    Joined:
    Dec 26, 2013
    Posts:
    3,973
    When recording in augmented reality, the aspect ratio of the recording has to exactly match that of the screen. This is a quirk because AR game cameras don't render the same way that normal cameras do.
     
  9. SergeyRomanko

    SergeyRomanko

    Joined:
    Oct 18, 2014
    Posts:
    47
    @Lanre
    Hi, I need some help with NatCorder. I'm using unity editor installed on macOs ver. 11.6 (20G165) machine. iOs platform is selected inside unity editor. I get errors occasionally, several times a day. It is hard to relate this errors to anything inside the game, they seem random. This is error message from log file

    Code (CSharp):
    1. 2022-02-02 10:26:52.511 Unity[71413:3909682] NatCorder Error: MP4Recorder failed to record video frame for time 651913400 with error: Error Domain=AVFoundationErrorDomain Code=-11861 "Cannot Encode Media" UserInfo={NSLocalizedFailureReason=The encoding parameters are not supported., NSLocalizedDescription=Cannot Encode Media, NSUnderlyingError=0x7fbf875a7480 {Error Domain=NSOSStatusErrorDomain Code=-12651 "(null)"}}
    2. 2022-02-02 10:26:52.522 Unity[71413:3909682] NatCorder Error: MP4Recorder failed to commit video frame for time 671322100 due to invalid recorder state: 3
    3. 2022-02-02 10:26:52.540 Unity[71413:3909682] NatCorder Error: MP4Recorder failed to commit video frame for time 706413300 due to invalid recorder state: 3
    4. 2022-02-02 10:26:52.540 Unity[71413:3909682] NatCorder Error: MP4Recorder failed to commit video frame for time 725223000 due to invalid recorder state: 3
    5. 2022-02-02 10:26:52.574 Unity[71413:3909682] NatCorder Error: MP4Recorder failed to commit video frame for time 804701100 due to invalid recorder state: 3
    Or another very similar message

    Code (CSharp):
    1. 2022-02-04 09:56:46.836 Unity[71413:6044944] NatCorder Error: MP4Recorder failed to commit audio frame for time 817331200 with error: Error Domain=AVFoundationErrorDomain Code=-11861 "Cannot Encode Media" UserInfo={NSLocalizedFailureReason=The encoding parameters are not supported., NSLocalizedDescription=Cannot Encode Media, NSUnderlyingError=0x7fbeb5c1be70 {Error Domain=NSOSStatusErrorDomain Code=-12651 "(null)"}}
    2. 2022-02-04 09:56:46.851 Unity[71413:3909682] NatCorder Error: MP4Recorder failed to commit video frame for time 767655800 due to invalid recorder state: 3
    3. 2022-02-04 09:56:46.868 Unity[71413:3909682] NatCorder Error: MP4Recorder failed to commit video frame for time 800676100 due to invalid recorder state: 3
    4. 2022-02-04 09:56:46.907 Unity[71413:3909682] NatCorder Error: MP4Recorder failed to commit video frame for time 817971600 due to invalid recorder state: 3
    After getting such error I get the exception inside unity after calling FinishWriting()

    Code (CSharp):
    1. Exception: Recorder failed to finish writing
    2. System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () (at <eae584ce26bc40229c1b1aa476bfa589>:0)
    3. System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Threading.Tasks.Task task) (at <eae584ce26bc40229c1b1aa476bfa589>:0)
    4. System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Threading.Tasks.Task task) (at <eae584ce26bc40229c1b1aa476bfa589>:0)
    5. System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd (System.Threading.Tasks.Task task) (at <eae584ce26bc40229c1b1aa476bfa589>:0)
    6. System.Runtime.CompilerServices.TaskAwaiter`1[TResult].GetResult () (at <eae584ce26bc40229c1b1aa476bfa589>:0)
    7. Engine.VideoRecording.PoolVideoRecorder+<Stop>d__17.MoveNext () (at Assets/Scripts/Engine/VideoRecording/PoolVideoRecorder.cs:70)
    Do you have any suggestions? Is there a way to gather more information about the error?
     
    Last edited: Feb 8, 2022
  10. Lanre

    Lanre

    Joined:
    Dec 26, 2013
    Posts:
    3,973
    Can you share your recording code?
     
  11. Masoverflow

    Masoverflow

    Joined:
    Jan 20, 2013
    Posts:
    5
    Hi,
    For recording in AR on IOS where the outputed video must be 16 by 9 but the screen is a different aspect ratio, what would be the best way to get a non squished video?
    So far I have tried calling SetResolution to the 16 by 9 resolution which seems to effect the UI but not the 3D content in the scene and still results in a squished video.
    A solution that involves cropping or letterboxing would be better than the squish, is that possible?
     
  12. Lanre

    Lanre

    Joined:
    Dec 26, 2013
    Posts:
    3,973
    There isn't a way to do this out of the box, but you can build it manually: implement letterboxing in a shader by creating a custom ITextureInput implementation.
     
  13. SergeyRomanko

    SergeyRomanko

    Joined:
    Oct 18, 2014
    Posts:
    47
    I've replied to you in the private conversation
     
    Lanre likes this.
  14. pjaimin

    pjaimin

    Joined:
    Nov 3, 2018
    Posts:
    13
    Okk, so I tried wavrecorder but it gives same result as a mp4recorder. Here I attach my original video, recorded video and recorded wav file. Check it out https://drive.google.com/drive/folders/1aoJDBKhmKCY3pMCeJfitl0kai79HG5UI?usp=sharing
     
  15. Lanre

    Lanre

    Joined:
    Dec 26, 2013
    Posts:
    3,973
    In that case the noise is coming from Unity. The fact that it also happens with the WAVRecorder indicates that the noise is present in the audio samples being sent to the recorders. Maybe there's something in your project that is causing this?
     
  16. verystep

    verystep

    Joined:
    Nov 1, 2020
    Posts:
    2
    Hi.

    When recording a Game Scene with NatCorder's MP4Recorder on Android, the color is recorded differently than what is displayed on the screen.

    For example, a yellow colored area is recorded in orange.

    JPGRecorder records without problems.

    Is there any way to solve it?

    It only happens on Android devices.

    thank you.
     

    Attached Files:

  17. Lanre

    Lanre

    Joined:
    Dec 26, 2013
    Posts:
    3,973
    Hey there, this might be related to the color transfer matrix used to convert from RGBA8888 to YUV420 for the encoder. Can you PM me with a link to a repro?
     
  18. SergeyRomanko

    SergeyRomanko

    Joined:
    Oct 18, 2014
    Posts:
    47
    Hey, I have trouble with creation of MP4Recorder on Xiaomi Redmi 8A, other devices work well

    The parameters are
    Code (CSharp):
    1. >>> MP4Recorder create with parameters width:1920 height:1080 frameRate:30 sampleRate:48000 channelCount:2 videoBitRate:10000000 keyframeInterval:2 audioBitRate:64000
    I see following exception in unity
    Code (CSharp):
    1.  
    2. 2022-02-14 15:26:10.773 3939-4133/starkgames.billiards.pool.clash E/Unity: InvalidOperationException: Failed to create MP4Recorder
    3.       at NatSuite.Recorders.MP4Recorder.Create (System.Int32 width, System.Int32 height, System.Single frameRate, System.Int32 sampleRate, System.Int32 channelCount, System.Int32 videoBitRate, System.Int32 keyframeInterval, System.Int32 audioBitRate) [0x00000] in <00000000000000000000000000000000>:0
    4.       at NatSuite.Recorders.MP4Recorder..ctor (System.Int32 width, System.Int32 height, System.Single frameRate, System.Int32 sampleRate, System.Int32 channelCount, System.Int32 videoBitRate, System.Int32 keyframeInterval, System.Int32 audioBitRate) [0x00000] in <00000000000000000000000000000000>:0
    5.       at Engine.VideoRecording.PoolVideoRecorder.Start (System.Int32 videoWidth, System.Int32 videoHeight, System.Boolean noFrame) [0x00000] in <00000000000000000000000000000000>:0
    6.  
    here is android log. my app is starkgames.billiards.pool.clash
    Code (CSharp):
    1. 2022-02-14 15:26:08.568 3939-4133/starkgames.billiards.pool.clash I/Unity: EVENT: open_window PARAMS: {"window_id":"GameWindow","parent_window_id":"GameHUD","session_id":"7c0d3c79-775d-4b3b-ad4f-f848d093ba02","client_version":"11101","client_platform":1,"client_time":1644841571,"user_id":63167,"user_level":2,"user_groups":["micring:test|A","new_ftue:tutorial|B","premiumprice_1:test|B","pvpwithbet_ab_1:rpgpool|B","seasonpass_1:test|B"],"event_sequence_number":54}
    2.     UnityEngine.DebugLogHandler:LogFormat(LogType, Object, String, Object[])
    3.     UnityEngine.Logger:Log(LogType, Object)
    4.     UnityEngine.Debug:Log(Object)
    5.     StarkAnalyticsSDK.StarkAnalytics:PushEvent(String, Dictionary`2)
    6.     Integrations.Analytics.StarkAnalyticsAdapter:PushEvent(String, Dictionary`2)
    7.     Integrations.Analytics.StarkAnalyticsAdapter:SendEvent(String, Dictionary`2)
    8.     Integrations.Analytics.AnalyticsController:SendEventToNetworkList(String, Dictionary`2, List`1)
    9.     Integrations.Analytics.AnalyticsController:SendEvent(String, Dictionary`2)
    10.     Assets.Scripts.UI.WindowManager.WindowManager:OnCompleteOpenWindow(WindowId)
    11.     Assets.Scripts.UI.Win
    12. 2022-02-14 15:26:08.578 3610-3610/? I/AssistHolderContentView: forceFitSystemWindows pb = 96
    13. 2022-02-14 15:26:08.645 3610-3610/? I/chatty: uid=1000(system) com.mi.android.globalminusscreen identical 4 lines
    14. 2022-02-14 15:26:08.661 3610-3610/? I/AssistHolderContentView: forceFitSystemWindows pb = 96
    15. 2022-02-14 15:26:08.666 3939-5413/starkgames.billiards.pool.clash I/OMXClient: IOmx service obtained
    16. 2022-02-14 15:26:08.672 831-27777/? I/OMXMaster: makeComponentInstance(OMX.qcom.video.encoder.avc) in android.hardwar process
    17. 2022-02-14 15:26:08.678 3610-3610/? I/AssistHolderContentView: forceFitSystemWindows pb = 96
    18. 2022-02-14 15:26:08.812 3610-3610/? I/chatty: uid=1000(system) com.mi.android.globalminusscreen identical 8 lines
    19. 2022-02-14 15:26:08.828 3610-3610/? I/AssistHolderContentView: forceFitSystemWindows pb = 96
    20. 2022-02-14 15:26:08.845 831-27777/? I/OMX-VENC: Video encode perflock acquired,handle=210
    21. 2022-02-14 15:26:08.845 3610-3610/? I/AssistHolderContentView: forceFitSystemWindows pb = 96
    22. 2022-02-14 15:26:08.856 831-27777/? I/OMX-VENC: Component_init : OMX.qcom.video.encoder.avc : return = 0x0
    23. 2022-02-14 15:26:08.862 3610-3610/? I/AssistHolderContentView: forceFitSystemWindows pb = 96
    24. 2022-02-14 15:26:08.871 831-2337/? E/OMXNodeInstance: setParameter(0xa7182404:qcom.encoder.avc, OMX.google.android.index.allocateNativeHandle(0x7f00005d): Input:0 en=0) ERROR: UnsupportedSetting(0x80001019)
    25. 2022-02-14 15:26:08.871 831-2337/? E/OMXNodeInstance: setParameter(0xa7182404:qcom.encoder.avc, OMX.google.android.index.allocateNativeHandle(0x7f00005d): Output:1 en=0) ERROR: UnsupportedSetting(0x80001019)
    26. 2022-02-14 15:26:08.871 831-2337/? W/OMXNodeInstance: [0xa7182404:qcom.encoder.avc] component does not support metadata mode; using fallback
    27. 2022-02-14 15:26:08.871 3939-5413/starkgames.billiards.pool.clash I/ExtendedACodec: setupVideoEncoder()
    28. 2022-02-14 15:26:08.871 3939-5413/starkgames.billiards.pool.clash W/OMXUtils: do not know color format 0x7fa30c04 = 2141391876
    29. 2022-02-14 15:26:08.872 3939-5413/starkgames.billiards.pool.clash W/OMXUtils: do not know color format 0x7f000789 = 2130708361
    30. 2022-02-14 15:26:08.872 3939-5413/starkgames.billiards.pool.clash I/ACodec: [OMX.qcom.video.encoder.avc] using color format 0x15 in place of 0x7f420888
    31. 2022-02-14 15:26:08.875 831-2337/? E/OMX-VENC: VIDIOC_S_FMT OUTPUT_MPLANE Failed
    32. 2022-02-14 15:26:08.875 831-2337/? E/OMX-VENC: ERROR: venc_set_param input failed
    33. 2022-02-14 15:26:08.875 831-2337/? E/OMXNodeInstance: setParameter(0xa7182404:qcom.encoder.avc, ParamPortDefinition(0x2000001)) ERROR: InsufficientResources(0x80001000)
    34. 2022-02-14 15:26:08.875 3939-5413/starkgames.billiards.pool.clash E/ACodec: [OMX.qcom.video.encoder.avc] failed to set input port definition parameters.
    35. 2022-02-14 15:26:08.875 3939-5413/starkgames.billiards.pool.clash E/ExtendedACodec: [OMX.qcom.video.encoder.avc] configureCodec returning error -12
    36. 2022-02-14 15:26:08.875 3939-5413/starkgames.billiards.pool.clash E/ACodec: signalError(omxError 0x80001001, internalError -12)
    37. 2022-02-14 15:26:08.875 3939-5413/starkgames.billiards.pool.clash E/ACodec: [OMX.qcom.video.encoder.avc] configureCodec returning error -12
    38. 2022-02-14 15:26:08.875 3939-5413/starkgames.billiards.pool.clash E/ACodec: signalError(omxError 0x80001001, internalError -12)
    39. 2022-02-14 15:26:08.875 3939-5412/starkgames.billiards.pool.clash E/MediaCodec: Codec reported err 0xfffffff4, actionCode 0, while in state 3
    40. 2022-02-14 15:26:08.878 3610-3610/? I/AssistHolderContentView: forceFitSystemWindows pb = 96
    41. 2022-02-14 15:26:08.880 3939-5412/starkgames.billiards.pool.clash E/MediaCodec: Codec reported err 0xfffffff4, actionCode 0, while in state 0
    42. 2022-02-14 15:26:08.880 3939-4133/starkgames.billiards.pool.clash E/MediaCodec: configure failed with err 0xfffffff4, resetting...
    43. 2022-02-14 15:26:08.882 831-2337/? I/OMX-VENC: Component Deinit
    44. 2022-02-14 15:26:08.882 831-2337/? I/OMX-VENC: Video encode perflock released
    45. 2022-02-14 15:26:08.887 3939-5413/starkgames.billiards.pool.clash I/OMXClient: IOmx service obtained
    46. 2022-02-14 15:26:08.887 831-2337/? I/OMXMaster: makeComponentInstance(OMX.qcom.video.encoder.avc) in android.hardwar process
    47. 2022-02-14 15:26:08.890 831-2337/? I/OMX-VENC: Video encode perflock acquired,handle=211
    48. 2022-02-14 15:26:08.895 3610-3610/? I/AssistHolderContentView: forceFitSystemWindows pb = 96
    49. 2022-02-14 15:26:08.898 831-2337/? I/OMX-VENC: Component_init : OMX.qcom.video.encoder.avc : return = 0x0
    50. 2022-02-14 15:26:08.900 820-21644/? E/ResourceManagerService: getLowestPriorityBiggestClient_l: lowest priority 0 vs caller priority 0
    51. 2022-02-14 15:26:08.901 820-21644/? E/ResourceManagerService: getLowestPriorityBiggestClient_l: lowest priority 0 vs caller priority 0
    52. 2022-02-14 15:26:08.912 3610-3610/? I/AssistHolderContentView: forceFitSystemWindows pb = 96
    53. 2022-02-14 15:26:08.928 3939-4133/starkgames.billiards.pool.clash W/System.err: android.media.MediaCodec$CodecException: Error 0xfffffff4
    54. 2022-02-14 15:26:08.928 3610-3610/? I/AssistHolderContentView: forceFitSystemWindows pb = 96
    55. 2022-02-14 15:26:08.929 3939-4133/starkgames.billiards.pool.clash W/System.err:     at android.media.MediaCodec.native_configure(Native Method)
    56. 2022-02-14 15:26:08.929 3939-4133/starkgames.billiards.pool.clash W/System.err:     at android.media.MediaCodec.configure(MediaCodec.java:2023)
    57. 2022-02-14 15:26:08.929 3939-4133/starkgames.billiards.pool.clash W/System.err:     at android.media.MediaCodec.configure(MediaCodec.java:1951)
    58. 2022-02-14 15:26:08.929 3939-4133/starkgames.billiards.pool.clash W/System.err:     at api.natsuite.natcorder.MP4Recorder.<init>(MP4Recorder.java:53)
    59. 2022-02-14 15:26:08.929 3939-4133/starkgames.billiards.pool.clash W/System.err:     at com.unity3d.player.UnityPlayer.nativeRender(Native Method)
    60. 2022-02-14 15:26:08.929 3939-4133/starkgames.billiards.pool.clash W/System.err:     at com.unity3d.player.UnityPlayer.access$300(Unknown Source:0)
    61. 2022-02-14 15:26:08.929 3939-4133/starkgames.billiards.pool.clash W/System.err:     at com.unity3d.player.UnityPlayer$e$1.handleMessage(Unknown Source:95)
    62. 2022-02-14 15:26:08.929 3939-4133/starkgames.billiards.pool.clash W/System.err:     at android.os.Handler.dispatchMessage(Handler.java:103)
    63. 2022-02-14 15:26:08.929 3939-4133/starkgames.billiards.pool.clash W/System.err:     at android.os.Looper.loop(Looper.java:223)
    64. 2022-02-14 15:26:08.929 3939-4133/starkgames.billiards.pool.clash W/System.err:     at com.unity3d.player.UnityPlayer$e.run(Unknown Source:20)
    65. 2022-02-14 15:26:08.931 429-429/? I/hwservicemanager: getTransport: Cannot find entry vendor.qti.hardware.servicetracker@1.0::IServicetracker/default in either framework or device manifest.
    66. 2022-02-14 15:26:08.933 429-429/? I/hwservicemanager: getTransport: Cannot find entry vendor.qti.hardware.servicetracker@1.0::IServicetracker/default in either framework or device manifest.
    67. 2022-02-14 15:26:08.933 3377-3377/? D/BoundBrokerSvc: onUnbind: Intent { act=com.google.android.gms.measurement.START pkg=com.google.android.gms }
    68. 2022-02-14 15:26:08.945 3610-3610/? I/AssistHolderContentView: forceFitSystemWindows pb = 96
    69. 2022-02-14 15:26:09.447 3610-3610/? I/chatty: uid=1000(system) com.mi.android.globalminusscreen identical 30 lines
    70. 2022-02-14 15:26:09.463 3610-3610/? I/AssistHolderContentView: forceFitSystemWindows pb = 96
    71. 2022-02-14 15:26:09.480 3610-3610/? I/AssistHolderContentView: forceFitSystemWindows pb = 96
    72. 2022-02-14 15:26:10.449 3610-3610/? I/chatty: uid=1000(system) com.mi.android.globalminusscreen identical 58 lines
    73. 2022-02-14 15:26:10.466 3610-3610/? I/AssistHolderContentView: forceFitSystemWindows pb = 96
    74. 2022-02-14 15:26:10.483 3610-3610/? I/AssistHolderContentView: forceFitSystemWindows pb = 96
    75. 2022-02-14 15:26:10.532 3610-3610/? I/chatty: uid=1000(system) com.mi.android.globalminusscreen identical 3 lines
    76. 2022-02-14 15:26:10.550 3610-3610/? I/AssistHolderContentView: forceFitSystemWindows pb = 96
    77. 2022-02-14 15:26:10.552 5270-5270/? W/Settings: Setting airplane_mode_on has moved from android.provider.Settings.System to android.provider.Settings.Global, returning read-only value.
    78. 2022-02-14 15:26:10.559 5270-5270/? D/SarControllerService: 10s after boot, isPhoneCallOn=false, isMobileNetOn=false, isAirmodeOn=false
    79. 2022-02-14 15:26:10.566 3610-3610/? I/AssistHolderContentView: forceFitSystemWindows pb = 96
    80. 2022-02-14 15:26:10.600 3610-3610/? I/chatty: uid=1000(system) com.mi.android.globalminusscreen identical 2 lines
    81. 2022-02-14 15:26:10.617 3610-3610/? I/AssistHolderContentView: forceFitSystemWindows pb = 96
    82. 2022-02-14 15:26:10.624 429-429/? I/hwservicemanager: getTransport: Cannot find entry vendor.qti.hardware.servicetracker@1.0::IServicetracker/default in either framework or device manifest.
    83. 2022-02-14 15:26:10.633 3610-3610/? I/AssistHolderContentView: forceFitSystemWindows pb = 96
    84. 2022-02-14 15:26:10.750 3610-3610/? I/chatty: uid=1000(system) com.mi.android.globalminusscreen identical 7 lines
    85. 2022-02-14 15:26:10.766 3610-3610/? I/AssistHolderContentView: forceFitSystemWindows pb = 96
    86. 2022-02-14 15:26:10.773 3939-4133/starkgames.billiards.pool.clash E/Unity: InvalidOperationException: Failed to create MP4Recorder
    87.       at NatSuite.Recorders.MP4Recorder.Create (System.Int32 width, System.Int32 height, System.Single frameRate, System.Int32 sampleRate, System.Int32 channelCount, System.Int32 videoBitRate, System.Int32 keyframeInterval, System.Int32 audioBitRate) [0x00000] in <00000000000000000000000000000000>:0
    Could you please give me any suggestions what could be wrong?
     
  19. Lanre

    Lanre

    Joined:
    Dec 26, 2013
    Posts:
    3,973
    It seems that the device does not have the necessary hardware resources to support recording:
    Code (CSharp):
    1. E/OMXNodeInstance: setParameter(0xa7182404:qcom.encoder.avc, ParamPortDefinition(0x2000001)) ERROR: InsufficientResources(0x80001000)
    This is very device-specific, so the best way to handle it is by displaying a UI panel to the user informing them that recording isn't available in the current session.
     
  20. SergeyRomanko

    SergeyRomanko

    Joined:
    Oct 18, 2014
    Posts:
    47
    Thank you for the reply. Are you sure that ERROR: InsufficientResources(0x80001000) is the main problem? Before this error I see other messages from encoder.avc . There are 2 UnsupportedSetting(0x80001019) errors. Can they cause the problem?

    Code (CSharp):
    1. 2022-02-16 17:05:09.123 18340-18905/starkgames.billiards.pool.clash I/OMXClient: IOmx service obtained
    2. 2022-02-16 17:05:09.124 803-14960/? I/OMXMaster: makeComponentInstance(OMX.qcom.video.encoder.avc) in android.hardwar process
    3. 2022-02-16 17:05:09.126 3432-3432/? I/AssistHolderContentView: forceFitSystemWindows pb = 96
    4. 2022-02-16 17:05:09.133 803-14960/? I/OMX-VENC: Video encode perflock acquired,handle=69
    5. 2022-02-16 17:05:09.143 3432-3432/? I/AssistHolderContentView: forceFitSystemWindows pb = 96
    6. 2022-02-16 17:05:09.146 803-14960/? I/OMX-VENC: Component_init : OMX.qcom.video.encoder.avc : return = 0x0
    7. 2022-02-16 17:05:09.154 803-14960/? E/OMXNodeInstance: setParameter(0xb0d62504:qcom.encoder.avc, OMX.google.android.index.allocateNativeHandle(0x7f00005d): Input:0 en=0) ERROR: UnsupportedSetting(0x80001019)
    8. 2022-02-16 17:05:09.154 803-14960/? E/OMXNodeInstance: setParameter(0xb0d62504:qcom.encoder.avc, OMX.google.android.index.allocateNativeHandle(0x7f00005d): Output:1 en=0) ERROR: UnsupportedSetting(0x80001019)
    9. 2022-02-16 17:05:09.154 803-14960/? W/OMXNodeInstance: [0xb0d62504:qcom.encoder.avc] component does not support metadata mode; using fallback
    10. 2022-02-16 17:05:09.154 18340-18905/starkgames.billiards.pool.clash I/ExtendedACodec: setupVideoEncoder()
    11. 2022-02-16 17:05:09.155 18340-18905/starkgames.billiards.pool.clash W/OMXUtils: do not know color format 0x7fa30c04 = 2141391876
    12. 2022-02-16 17:05:09.155 18340-18905/starkgames.billiards.pool.clash W/OMXUtils: do not know color format 0x7f000789 = 2130708361
    13. 2022-02-16 17:05:09.155 18340-18905/starkgames.billiards.pool.clash I/ACodec: [OMX.qcom.video.encoder.avc] using color format 0x15 in place of 0x7f420888
    14. 2022-02-16 17:05:09.159 803-14960/? E/OMX-VENC: VIDIOC_S_FMT OUTPUT_MPLANE Failed
    15. 2022-02-16 17:05:09.159 803-14960/? E/OMX-VENC: ERROR: venc_set_param input failed
    16. 2022-02-16 17:05:09.159 803-14960/? E/OMXNodeInstance: setParameter(0xb0d62504:qcom.encoder.avc, ParamPortDefinition(0x2000001)) ERROR: InsufficientResources(0x80001000)
    17. 2022-02-16 17:05:09.159 18340-18905/starkgames.billiards.pool.clash E/ACodec: [OMX.qcom.video.encoder.avc] failed to set input port definition parameters.
    18. 2022-02-16 17:05:09.159 18340-18905/starkgames.billiards.pool.clash E/ExtendedACodec: [OMX.qcom.video.encoder.avc] configureCodec returning error -12
    19. 2022-02-16 17:05:09.159 18340-18905/starkgames.billiards.pool.clash E/ACodec: signalError(omxError 0x80001001, internalError -12)
    20. 2022-02-16 17:05:09.160 18340-18905/starkgames.billiards.pool.clash E/ACodec: [OMX.qcom.video.encoder.avc] configureCodec returning error -12
    21. 2022-02-16 17:05:09.160 18340-18905/starkgames.billiards.pool.clash E/ACodec: signalError(omxError 0x80001001, internalError -12)
    22. 2022-02-16 17:05:09.160 3432-3432/? I/AssistHolderContentView: forceFitSystemWindows pb = 96
    23. 2022-02-16 17:05:09.160 18340-18904/starkgames.billiards.pool.clash E/MediaCodec: Codec reported err 0xfffffff4, actionCode 0, while in state 3
    24. 2022-02-16 17:05:09.161 18340-18904/starkgames.billiards.pool.clash E/MediaCodec: Codec reported err 0xfffffff4, actionCode 0, while in state 0
    25. 2022-02-16 17:05:09.161 18340-18449/starkgames.billiards.pool.clash E/MediaCodec: configure failed with err 0xfffffff4, resetting...
    26. 2022-02-16 17:05:09.164 803-14960/? I/OMX-VENC: Component Deinit
    27. 2022-02-16 17:05:09.164 803-14960/? I/OMX-VENC: Video encode perflock released
    28. 2022-02-16 17:05:09.169 18340-18905/starkgames.billiards.pool.clash I/OMXClient: IOmx service obtained
    29. 2022-02-16 17:05:09.169 803-14960/? I/OMXMaster: makeComponentInstance(OMX.qcom.video.encoder.avc) in android.hardwar process
    30. 2022-02-16 17:05:09.171 803-14960/? I/OMX-VENC: Video encode perflock acquired,handle=70
    31. 2022-02-16 17:05:09.176 3432-3432/? I/AssistHolderContentView: forceFitSystemWindows pb = 96
    32. 2022-02-16 17:05:09.177 803-14960/? I/OMX-VENC: Component_init : OMX.qcom.video.encoder.avc : return = 0x0
     
  21. Lanre

    Lanre

    Joined:
    Dec 26, 2013
    Posts:
    3,973
    They are likely related. Can you try recording at 640x480 to see if the error still occurs?
     
  22. SergeyRomanko

    SergeyRomanko

    Joined:
    Oct 18, 2014
    Posts:
    47
    On a small resolution there is no exception. But the picture on the screen becomes unstable, there are some sorts of visual glitches. Eventually the application just crashes. It looks like this is a low level issue on operation system level or hardware level
     
  23. SergeyRomanko

    SergeyRomanko

    Joined:
    Oct 18, 2014
    Posts:
    47
    I have another question. I noticed that I use textures with transparency to generate video. But I don't need transparency for my video. I am wondering if it is possible to speed up reading data from GPU by excluding alpha channel. Can I use RGB data for rendering video? Do you know how much excluding alpha channel could affect performance?
     
  24. Lanre

    Lanre

    Joined:
    Dec 26, 2013
    Posts:
    3,973
    Sounds like it.
    So all of our API's (NatML, NatCorder, NatDevice) run on RGBA8888. Taking a step back, you can actually have worse performance using RGB888 instead of RGBA8888. The reason for this is that a lot of hardware media processing benefits strongly from memory alignment guarantees, and a single pixel with RGBA8888 takes 32 bits (power of two) whereas RGB888 is 24 bits (not power of two). So you'll see either similar or slightly worse performance with RGB888.
     
  25. dragologic

    dragologic

    Joined:
    Oct 28, 2012
    Posts:
    16
    How to hide UI from being recorded?
     
  26. Lanre

    Lanre

    Joined:
    Dec 26, 2013
    Posts:
    3,973
    Set the render mode to Overlay - Canvas.
     
  27. dragologic

    dragologic

    Joined:
    Oct 28, 2012
    Posts:
    16
    Thanks
     
    Lanre likes this.
  28. dragologic

    dragologic

    Joined:
    Oct 28, 2012
    Posts:
    16
    For wikitude should use
    cameraInput = new CameraInput(recorder, clock, Camera.allCameras);
    ?
     
    Last edited: Feb 23, 2022
  29. Lanre

    Lanre

    Joined:
    Dec 26, 2013
    Posts:
    3,973
    It depends on what cameras you want to record. If you want to record all the cameras in the scene, then sure.
     
  30. Noisecrime

    Noisecrime

    Joined:
    Apr 7, 2010
    Posts:
    2,054
    Hi,

    I just updated to NatCorder 1.82 for a new project in Unity 2021.2.8f1 and came across the following script error

    Assets\NatML\NatCorder\Runtime\Inputs\AudioInput.cs(73,13): error CS0103: The name 'AndroidJNI' does not exist in the current context


    I believe its due to the line 'AndroidJNI.AttachCurrentThread();' not being wrapped in a define and the fact that I don't install any modules other than windows standalone in my Unity Editors unless I need them for a project.

    I've wrapped it in a UNITY_ANDROID define for now.
    I assume this will be fine and that AttachCurrentThread call is only relevant when running on Android?

    In order to get Natcorder to completely compile I also had to add a define check inside the runtime conditional checking for the android platform in CameraPreview.cs, where it looks at permission.

    If these don't adversely affect the plugin it would be nice to get them added in the next update.
     
  31. Lanre

    Lanre

    Joined:
    Dec 26, 2013
    Posts:
    3,973
    Hey there, this is a good catch. It looks like Unity has moved the `AndroidJNI` class into a different assembly, which is why it now errors. I'll go ahead and add an `#if UNITY_ANDROID` check.
    Correct! This only affects Android.
    Sounds good.
    Yup, added already.
     
    Noisecrime likes this.
  32. PrisedRabbit

    PrisedRabbit

    Joined:
    Aug 14, 2012
    Posts:
    63
    Is it possible to stream mobile camera feed along with sound to Azure Media Service?
     
  33. Lanre

    Lanre

    Joined:
    Dec 26, 2013
    Posts:
    3,973
    Hey there, NatCorder does not support streaming over a network. It always records videos to a file.
     
    PrisedRabbit likes this.
  34. tykeen

    tykeen

    Joined:
    Dec 8, 2021
    Posts:
    3
    Hi, my project needs to be started or stopped several times due to the demand, but every time it starts or stops, there will be a delay. Is there any solution? My device is ios
     
  35. Lanre

    Lanre

    Joined:
    Dec 26, 2013
    Posts:
    3,973
    I'm not entirely sure I follow. What do you mean by "but every time it starts or stops, there will be a delay"?
     
  36. tykeen

    tykeen

    Joined:
    Dec 8, 2021
    Posts:
    3
    Every time I start recording and stop recording, the project freezes for 1 to 2 seconds before running normally
     
  37. Lanre

    Lanre

    Joined:
    Dec 26, 2013
    Posts:
    3,973
    What are your system specs? And what version of NatCorder are you using?
     
  38. tykeen

    tykeen

    Joined:
    Dec 8, 2021
    Posts:
    3
    unity2019.4.27f1,NatCorder is some version of 2020,I may need to update the Natcorder version
     
  39. Lanre

    Lanre

    Joined:
    Dec 26, 2013
    Posts:
    3,973
    Try the latest version of NatCorder and let me know if the issue persists.
     
  40. NaijaNY82

    NaijaNY82

    Joined:
    Mar 7, 2017
    Posts:
    19
    Checked Record Microphone box but I get poor sound quality with Natcorder alone. I added Natdevice, when I try to update ReplayCam.cs with this code
    Code (CSharp):
    1.  
    2. audioDevice.StartRunning((sampleBuffer, timestamp) => {
    3.     // And pass sample buffers directly to the recorder
    4.     recorder.CommitSamples(sampleBuffer);
    5. });
    6.  
    I get the following error:

    Assets\NatML\Examples\ReplayCam\ReplayCam.cs(85,29): error CS1593: Delegate 'Action<AudioBuffer>' does not take 2 arguments

    I'm using Unity 2021.2.16 with URP
     
    Last edited: Mar 23, 2022
  41. Lanre

    Lanre

    Joined:
    Dec 26, 2013
    Posts:
    3,973
    Hey there, I presume you copied code from the docs? We're currently updating the docs, but your code should now look like this:
    Code (CSharp):
    1. audioDevice.StartRunning(audioBuffer => {
    2.     // And pass sample buffers directly to the recorder
    3.     recorder.CommitSamples(audioBuffer.sampleBuffer.ToArray());
    4. });
    Depending on which recorder you are using, you might also need to pass in a timestamp. Use your recording clock's timestamp for this.
     
  42. NaijaNY82

    NaijaNY82

    Joined:
    Mar 7, 2017
    Posts:
    19
    Thanks for the quick response. Yes I was following the docs and my past usage, I imagine there are several changes since I've last used it. I tried the code you suggested and I now get the following error:

    Assets\NatML\Examples\ReplayCam\PlayCam.cs(53,14): error CS1501: No overload for method 'CommitSamples' takes 1 arguments

    Below is my code thus far, am I missing something? Also you mentioned timestamp, is there an example?
    Code (CSharp):
    1. namespace NatSuite.Examples {
    2.  
    3.     using System.Collections;
    4.     using UnityEngine;
    5.     using Recorders;
    6.     using Recorders.Clocks;
    7.     using Recorders.Inputs;
    8.     using NatSuite.Devices;
    9.  
    10. public class PlayCam : MonoBehaviour
    11. {
    12.  
    13.     MP4Recorder recorder;
    14.     CameraInput cameraInput;    // Recorder input for recording video from a game camera
    15.     AudioDevice audioDevice;    // Microphone for recording user audio
    16.         public async void Start()
    17.         {
    18.  
    19.             if (await MediaDeviceQuery.RequestPermissions<AudioDevice>() != PermissionStatus.Authorized) {
    20.                 Debug.LogError("User did not grant microphone permissions");
    21.                 return;
    22.             }
    23.  
    24.             if (await MediaDeviceQuery.RequestPermissions<CameraDevice>() != PermissionStatus.Authorized) {
    25.                 Debug.LogError("User did not grant microphone permissions");
    26.                 return;
    27.             }
    28.  
    29.         }
    30.  
    31.     public void StartRecording () {
    32.         // Get a microphone
    33.         var query = new MediaDeviceQuery(MediaDeviceCriteria.AudioDevice);
    34.         audioDevice = query.current as AudioDevice;
    35.  
    36.         // Create recorder
    37.         var clock = new RealtimeClock();
    38.         recorder = new MP4Recorder(1280, 720, 30, audioDevice.sampleRate, audioDevice.channelCount);
    39.  
    40.         // Stream media samples
    41.         cameraInput = new CameraInput(recorder, clock, Camera.main);
    42.         //audioDevice.StartRunning((sampleBuffer, timestamp) => recorder.CommitSamples(sampleBuffer, clock.timestamp));
    43.         //audioDevice.StartRunning((sampleBuffer, timestamp) => {recorder.CommitSamples(sampleBuffer);});
    44.        
    45.         audioDevice.StartRunning(audioBuffer => {
    46.         // And pass sample buffers directly to the recorder
    47.         recorder.CommitSamples(audioBuffer.sampleBuffer.ToArray());
    48.         });
    49.        
    50.     }
    51.    
    52.     public async void StopRecording () {
    53.         // Stop streaming media to the recorder
    54.         cameraInput.Dispose();
    55.         audioDevice.StopRunning();
    56.  
    57.         // Finish writing video
    58.         var recordingPath = await recorder.FinishWriting();
    59.         Debug.Log($"Saved recording to: {recordingPath}");
    60.         #if !UNITY_STANDALONE
    61.         Handheld.PlayFullScreenMovie($"file://{recordingPath}");
    62.         #endif
    63.     }
    64. }
    65. }
     
  43. Lanre

    Lanre

    Joined:
    Dec 26, 2013
    Posts:
    3,973
    Yup this is what I mentioned earlier: some recorders require timestamps when committing audio frames. So do this:
    Code (CSharp):
    1. recorder.CommitSamples(audioBuffer.sampleBuffer.ToArray(), clock.timestamp);
     
    NaijaNY82 likes this.
  44. NaijaNY82

    NaijaNY82

    Joined:
    Mar 7, 2017
    Posts:
    19

    Thanks. That got it working. Sound quality is much better
     
  45. muranken

    muranken

    Joined:
    Jun 25, 2015
    Posts:
    1
    Hello.
    I had the same problem as pjaimin.
    I get noise in the recorded audio, but not in the sound coming out of the speakers in real time.

    Unity 2020.3.30f1
    NatCorder 1.8.1

    In my case, the problem was that the volume was too loud when playing multiple SEs.
    And I solved it by using Audio Normalize Effect.
     
    Lanre likes this.
  46. Lanre

    Lanre

    Joined:
    Dec 26, 2013
    Posts:
    3,973
    Glad to hear it!
     
  47. pjaimin

    pjaimin

    Joined:
    Nov 3, 2018
    Posts:
    13
    Could you please elaborate how exactly you solved this problem ??? @muranken
     
    Lanre likes this.
  48. vcasas

    vcasas

    Joined:
    Oct 6, 2017
    Posts:
    7
  49. Lanre

    Lanre

    Joined:
    Dec 26, 2013
    Posts:
    3,973
  50. dragologic

    dragologic

    Joined:
    Oct 28, 2012
    Posts:
    16
    Is there some specific setup for AR foundation and Natcorder?