Search Unity

NatCorder - Video Recording API

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

  1. Lanre

    Lanre

    Joined:
    Dec 26, 2013
    Posts:
    3,973
    If it's crashing as soon as you open the app, then it likely has nothing to do with NatCorder. NatCorder doesn't silently initialize itself, so NatCorder code would not have run by the time this crash happens.
     
  2. vn_man

    vn_man

    Joined:
    Jun 7, 2017
    Posts:
    24
    Hi Lanre,
    I record video by use 2 camera, code below:

    Camera[] camRecords;
    cameraInput = new CameraInput(videoRecorder, recordingClock, camRecords);

    I want to on/off one camera in recording, I have try enable camera component but not solve
    so How to do it or It can't do
    thanks!
     
  3. Lanre

    Lanre

    Joined:
    Dec 26, 2013
    Posts:
    3,973
    It isn't possible to 'turn off' a camera that you pass to CameraInput; it will render even if the camera is disabled. I think a better approach would be to determine which cameras should be recorded beforehand.
     
  4. vn_man

    vn_man

    Joined:
    Jun 7, 2017
    Posts:
    24
    I have test turn on/off camera by setting culling mask of camera to Nothing, and It's working :D
    thank!
     
    Lanre likes this.
  5. frikic

    frikic

    Joined:
    Dec 22, 2011
    Posts:
    44
    Hi Lanre,

    I'm currently using NatCorder to record video from MainCamera and audio from AudioListener, and this works fine.
    I tried adding microphone as AudioSource AudioInput and playing it after in order to record it, but i dont get any sound

    Code (CSharp):
    1. deviceMicrophone.clip = Microphone.Start(Microphone.devices[0], false, (int)maxRecordingTime, 44100);
    2. deviceMicrophone.Play();
    3. microphoneInput = new AudioInput(videoRecorder, recordingClock, deviceMicrophone, false);
    Please let me know if I'm doing something wrong, also is this issue that can be solved using NatMic?
     
  6. bhtruong93

    bhtruong93

    Joined:
    Jul 12, 2017
    Posts:
    8
    I'm noticing in the unity profiler that the memory usage slowly creeps up every time I'm starting/stopping, starting/stopping, etc. Tried it on iOS and the memory leak seems to be more serious. Can you confirm or deny what I'm seeing?
     
  7. kgbv

    kgbv

    Joined:
    Jun 5, 2013
    Posts:
    13
    Hello, Lanre,

    I was build IOS for Natcorder example [ReplayCam] in Ipad. "When I press the record button screen is freeze, but thus time recording is worked. And the video is fine.Please help...

    Video File is Below
    https://drive.google.com/file/d/1E9uyW4zKaKqjtj7oDq4QLuuzZMEy69-5/view

    Software:-
    Natcorder Version:1.6.4
    unity:2018.4.9f1
    IPad:iPad Air 2
    iPad version:12.3.1
     
  8. radraghag

    radraghag

    Joined:
    Jul 15, 2015
    Posts:
    5
    Hi!
    I encountered a bug on Android.
    If you use "Linear" color space in your player settings all videos will be too dark.
    So can you please add Linear color space support on android? On other platforms, it works well.

    Right now I worked around it by doing additional color space transformation blit, but it is bad for my application performance.

    Thank.
     
  9. Lanre

    Lanre

    Joined:
    Dec 26, 2013
    Posts:
    3,973
    I've just found the fix for this: you have to wait until Microphone.GetPosition is greater than zero before calling AudioSource.Play. NatMic isn't affected by weird issues like this.
     
  10. Lanre

    Lanre

    Joined:
    Dec 26, 2013
    Posts:
    3,973
    Are you observing this in the ReplayCam example? I am unable to reproduce this.
     
  11. Lanre

    Lanre

    Joined:
    Dec 26, 2013
    Posts:
    3,973
    This is a bug in Unity 2018. It has been fixed in Unity 2019.2.
     
  12. Lanre

    Lanre

    Joined:
    Dec 26, 2013
    Posts:
    3,973
    NatCorder does not support linear rendering on mobile platforms, and is not advertised to support it (though it will work on iOS). We can't avoid the blit, so it won't make a difference whether it's in our code or yours. We've tried before but we faced issues across several devices.
     
  13. Lanre

    Lanre

    Joined:
    Dec 26, 2013
    Posts:
    3,973
    What features would you like to see?

    I've been trying to collect all the Nat* API's into a full AV suite of plugins for Unity (see NatSuite on GitHub). In doing this, I'm looking to build a potentially cross-API feature wishlist to build out. I expect to add some of these features to the current API's and would be pretty excited to make others into standalone, open-source projects (like NatReader, which is a cross-platform video decoder). Please comment your wishes, and I'll add them to this list:
    • NatCorder: Linear rendering support on mobile (Android specifically, as it is unofficially supported on iOS).
    • NatCorder: Linux support?
     
  14. igor691

    igor691

    Joined:
    Apr 23, 2018
    Posts:
    11
    Good day. You have good sample, demo scene? How to use NatShare with NatCoder.
     
  15. Lanre

    Lanre

    Joined:
    Dec 26, 2013
    Posts:
    3,973
    See NatMicCorder-Demo.
     
  16. igor691

    igor691

    Joined:
    Apr 23, 2018
    Posts:
    11
    But I dont understand why when I stop record screen and then watch preview videos I not hear sound. Microphone not record? Test your sample in Natcorder
     
  17. igor691

    igor691

    Joined:
    Apr 23, 2018
    Posts:
    11
    when I go into the application access to the sound recording requests. but there is no sound in video
    I'm use Natcorder and Android 9

    Or need use only Natcorder + Natmic?
     
    Last edited: Dec 8, 2019
  18. Lanre

    Lanre

    Joined:
    Dec 26, 2013
    Posts:
    3,973
    Unity's Microphone API has a weird bug that causes the audio to be silent depending on how the microphone clip is played. I have a workaround and will publish it in the next update.
     
  19. igor691

    igor691

    Joined:
    Apr 23, 2018
    Posts:
    11
    when will the update be?
     
  20. Lanre

    Lanre

    Joined:
    Dec 26, 2013
    Posts:
    3,973
    Aiming for it to be live by the end of this coming week.
     
  21. igor691

    igor691

    Joined:
    Apr 23, 2018
    Posts:
    11
    Cool, I hope you finish)
     
  22. jimmying

    jimmying

    Joined:
    Sep 20, 2017
    Posts:
    107
    Can confirm this works! Thank you

    Although, probably not a NatCorder thing, but I had to change my audio settings DSP Buffer Size to Best latency. It was very choppy using Best Performance.
     
    Lanre likes this.
  23. bhtruong93

    bhtruong93

    Joined:
    Jul 12, 2017
    Posts:
    8
    Hey thanks for the response. For my test case, I modified the ReplayCam so that it doesn't record the microphone and only the audio listener. I can see the memory leak with this code.
    Code (CSharp):
    1. /*
    2. *   NatCorder
    3. *   Copyright (c) 2019 Yusuf Olokoba
    4. */
    5.  
    6. namespace NatCorder.Examples {
    7.  
    8.     #if UNITY_EDITOR
    9.     using UnityEditor;
    10.     #endif
    11.     using UnityEngine;
    12.     using Clocks;
    13.     using Inputs;
    14.  
    15.  
    16.     public class ReplayCam : MonoBehaviour {
    17.  
    18.         /**
    19.         * ReplayCam Example
    20.         * -----------------
    21.         * This example records the screen using a `CameraRecorder`.
    22.         * When we want mic audio, we play the mic to an AudioSource and record the audio source using an `AudioRecorder`
    23.         * -----------------
    24.         * Note that UI canvases in Overlay mode cannot be recorded, so we use a different mode (this is a Unity issue)
    25.         */
    26.  
    27.         [Header("Recording")]
    28.         public int videoWidth = 1280;
    29.         public int videoHeight = 720;
    30.  
    31.         [Header("Microphone")]
    32.         public AudioSource microphoneSource;
    33.  
    34.         private IMediaRecorder videoRecorder;
    35.         private IClock recordingClock;
    36.         private CameraInput cameraInput;
    37.         private AudioInput audioInput;
    38.  
    39.         public void StartRecording () {
    40.             // Start recording
    41.             recordingClock = new RealtimeClock();
    42.             videoRecorder = new MP4Recorder(
    43.                 videoWidth,
    44.                 videoHeight,
    45.                 30,
    46.                 AudioSettings.outputSampleRate,
    47.                 (int)AudioSettings.speakerMode,
    48.                 OnReplay
    49.             );
    50.             // Create recording inputs
    51.             cameraInput = new CameraInput(videoRecorder, recordingClock, Camera.main);
    52.             audioInput = new AudioInput(videoRecorder, recordingClock, Camera.main.GetComponent<AudioListener>());
    53.         }
    54.  
    55.         public void StopRecording () {
    56.             audioInput.Dispose();
    57.             cameraInput.Dispose();
    58.             videoRecorder.Dispose();
    59.         }
    60.  
    61.         private void OnReplay (string path) {
    62.             Debug.Log("Saved recording to: " +path);
    63.    //         // Playback the video
    64.    //         #if UNITY_EDITOR
    65.             //EditorUtility.OpenWithDefaultApp(path);
    66.             //#elif UNITY_IOS
    67.             //Handheld.PlayFullScreenMovie("file://" + path);
    68.             //#elif UNITY_ANDROID
    69.             //Handheld.PlayFullScreenMovie(path);
    70.             //#endif
    71.         }
    72.     }
    73. }
    I've also attached a screenshot from my xcode's memory profiler. The high peaks are when I start recording and I stop recording after a couple of seconds before trying it again. These are the results after a couple of tries, you can see that the plateaus are slowly rising. In my app I'm starting/stopping pretty frequently and can get it to crash after maybe 50 times
     

    Attached Files:

  24. Lanre

    Lanre

    Joined:
    Dec 26, 2013
    Posts:
    3,973
    I was able to reproduce this. I'll check it out. Thanks for bringing it to my attention.
     
    raphaelnew and bhtruong93 like this.
  25. monikpatel757

    monikpatel757

    Joined:
    Sep 20, 2019
    Posts:
    2
    I am trying to use unity plugin in my native android app.
    Its Screen recording works fine if i directly use "Build and Run" option in unity.
    But when i use it as a plugin in my native android project it gives error.

    E/Unity(13608): AndroidJavaException: java.lang.ClassNotFoundException: Didn't find class "com/olokobayusuf/natcorder/MP4Recorder" on path: DexPathList[[zip file "/data/app/com.unity.unitylib-1/base.apk", zip file "/data/app/com.unity.unitylib-1/split_lib_dependencies_apk.apk", zip file "/data/app/com.unity.unitylib-1/split_lib_slice_0_apk.apk", zip file "/data/app/com.unity.unitylib-1/split_lib_slice_1_apk.apk", zip file "/data/app/com.unity.unitylib-1/split_lib_slice_2_apk.apk", zip file "/data/app/com.unity.unitylib-1/split_lib_slice_3_apk.apk", zip file "/data/app/com.unity.unitylib-1/split_lib_slice_4_apk.apk", zip file "/data/app/com.unity.unitylib-1/split_lib_slice_5_apk.apk", zip file "/data/app/com.unity.unitylib-1/split_lib_slice_6_apk.apk", zip file "/data/app/com.unity.unitylib-1/split_lib_slice_7_apk.apk", zip file "/data/app/com.unity.unitylib-1/split_lib_slice_8_apk.apk", zip file "/data/app/com.unity.unitylib-1/split_lib_slice_9_apk.apk"],nativeLibraryDirectories=[/data/app/com.unity.unitylib-1/lib/arm, /dat

    Thanks
     
  26. WattyDev

    WattyDev

    Joined:
    Nov 28, 2018
    Posts:
    4
    Hi Lanre,
    I wonder how I can add a watermark to video from Ar Camera (Ar Foundation)?
     
  27. Lanre

    Lanre

    Joined:
    Dec 26, 2013
    Posts:
    3,973
    I don't think Unity's AndroidJavaObject class (what we use to communicate to Java) supports being encapsulated as a module in a native app. NatCorder isn't built for this purpose; you are better off writing your own Android code to record since you're already working in a native Java environment.
     
  28. Lanre

    Lanre

    Joined:
    Dec 26, 2013
    Posts:
    3,973
    You can use multiple cameras to do this. Setup a second camera to only see the watermark and keep it disabled in the scene, then record your normal camera and this camera with CameraInput.
     
    bhtruong93 likes this.
  29. reysantana

    reysantana

    Joined:
    Dec 13, 2019
    Posts:
    8
    Hello
    I have this error.
    Architecture: arm64
    iOS Target: 11.3
    Please help me to fix this error
    Thanks
     

    Attached Files:

    • 1.png
      1.png
      File size:
      24 KB
      Views:
      455
  30. reysantana

    reysantana

    Joined:
    Dec 13, 2019
    Posts:
    8
    upload_2019-12-13_18-25-11.png here is additional screenshot
     
  31. reysantana

    reysantana

    Joined:
    Dec 13, 2019
    Posts:
    8
    Hi @Lanre, please help me to resolve this issue...
     
  32. Lanre

    Lanre

    Joined:
    Dec 26, 2013
    Posts:
    3,973
    Delete and reimport NatCorder into your project.
     
  33. mtalbott

    mtalbott

    Joined:
    Dec 21, 2011
    Posts:
    125
    Hi @Lanre,

    I've asked this before but never got a clear answer. How do I record both scene audio AND microphone using NatMic in a single video. I could really use a clear code snippet on how to set this up. I'm using NatCorder 1.6.5 and NatMic 1.3.3

    Thanks,
    Mike
     
  34. WattyDev

    WattyDev

    Joined:
    Nov 28, 2018
    Posts:
    4
    Lanre, Could you tell me how I can improve recorded video quality. I ask it, because I have different what I see on screen and what I see on video. On video I see some pixels and squares, but in code I use smartphone screen resolution and 60 fps.
     
  35. Lanre

    Lanre

    Joined:
    Dec 26, 2013
    Posts:
    3,973
    NatMic doesn't have a way to mix microphone and game audio (we've tried in the past but could not get past synchronization issues). What you can do instead is record only the microphone as it should pick up audio coming out of the speakers (game audio).
     
  36. Lanre

    Lanre

    Joined:
    Dec 26, 2013
    Posts:
    3,973
    You can increase the recording bitrate in the recorder's constructor.
     
  37. igor691

    igor691

    Joined:
    Apr 23, 2018
    Posts:
    11
  38. Lanre

    Lanre

    Joined:
    Dec 26, 2013
    Posts:
    3,973
  39. igor691

    igor691

    Joined:
    Apr 23, 2018
    Posts:
    11
    Sorry, but I dont understand what information from this link i need take.
     
  40. Lanre

    Lanre

    Joined:
    Dec 26, 2013
    Posts:
    3,973
    You can wait for the NatShare update or pull the NatShare code from this pull request into your project.
     
  41. igor691

    igor691

    Joined:
    Apr 23, 2018
    Posts:
    11
    ok, I understood. But I dont see how use new NatShare with old NatCorder. Previous code We have

    if (shareRecordings)
    NatShare.Share(path);

    but this moment I not see same code.
    maybe you can say me what need write, or need add to my code.
    Thank you.
     
  42. Lanre

    Lanre

    Joined:
    Dec 26, 2013
    Posts:
    3,973
    Check out the README.
     
  43. mtalbott

    mtalbott

    Joined:
    Dec 21, 2011
    Posts:
    125
    I know this is out-of-scope for NatCorder but I'm having an issue with playing back NatCorder Videos through the Unity VideoPlayer on Android 10. My project is on Unity 2019.2.16f1. Has anyone here figured out a workaround? Seems to do with file permission changes in Android 10.
     
  44. Bongo_Studios

    Bongo_Studios

    Joined:
    Jan 26, 2019
    Posts:
    33
    We've already found the reason why it was crashing and has already been solved. The new version has been reimported and it is working well.
    However the performance is very bad, in Android the AndroidJNIHelper.InvokeJavaProxyMethod() method is using more than 50% of the CPU, thus making that whenever something is being recorded, the game is at 30 FPS only when nothing else is being executed.
    As soon as anything related with gameplay is used the FPS drops drastically. The game in execution without recording works at a stable 60 FPS, when recording at 30 FPS and interacting with the game the frames drop around to 15-20 FPS.
    We've been doing all the fixes and updates as you request all the time, and still recording and playing is impossible given the exessive amount of CPU used, which makes using the plugin useless since a user can't have a good experience if recording gameplay.
    Therefore, the plugin doesn't work for what it was purchased, its impossible to play when recording and all the effort to implement it has yielded more pains in the head than possitive impact for our game.

    Working on Unity 2019.2.16.
     
  45. monda

    monda

    Joined:
    May 14, 2015
    Posts:
    35
    Hi, I'm about to publish an AR App (ARCore), but I got a major issue with the Video Recording on Android.
    Like many apps I'm using Native calls (Prime31 Etcetera but tried others with same result), basically it records the video with a huge lag (5/6 fps) and also, slow the whole game while recording, if I remove all the Native plug ins or even a simple one I've wrote, Natcorder works fine but once added it goes very laggy.. Any idea how to solve this?
    I'm using Natcorder latest version on Unity 2019.2.6

    PS: ARkit version on iOS works fine
     
    WattyDev and raphaelnew like this.
  46. monikpatel757

    monikpatel757

    Joined:
    Sep 20, 2019
    Posts:
    2
    How can i change my path of video recording in android device and video size(in MB)?
    Thanks
     
  47. Arjun-Gupte

    Arjun-Gupte

    Joined:
    May 31, 2013
    Posts:
    54
    Hello

    I am trying to build a MacOS version of our app and I'm using a few plugins to help with the app(Natcorder, UTMail and Unibill).

    I kept getting an error in the application loader when I was trying to validate the app
    This didn't go through the application loader.

    I also got a warning for Natcorder saying the certificate is expired.

    So, I tried to change the bundle identfiers of these to what we used for our app, and that made it go through the application loader, but it didn't get approved by apple with this mail sent as the issue report
    Can anyone help with these issue?
     
  48. WattyDev

    WattyDev

    Joined:
    Nov 28, 2018
    Posts:
    4
    I have the same issue !
     
    monda likes this.
  49. musicdeveloper

    musicdeveloper

    Joined:
    Oct 16, 2019
    Posts:
    68
    Hello,
    I've been successfully using NatCorder in my project to record the Main Camera...

    I now also need to use NatCorder to be able to record the device camera using a WebCam Texture, as in this example:
    https://medium.com/@olokobayusuf/natcorder-unity-recording-made-easy-f0fdee0b5055

    However, when I try to run that code in a simple example, in an empty project, the Unity editor crashes

    Crash report attached - I'm using Unity 2019.3.0f3.


    And here is the example code I'm running:

    Code (CSharp):
    1. /*
    2. *   NatCorder
    3. *   Copyright (c) 2019 Yusuf Olokoba
    4. */
    5.  
    6. namespace NatCorder.Examples {
    7.  
    8.     using UnityEngine;
    9.     using System.Collections;
    10.     using Clocks;
    11.     using Inputs;
    12.    
    13.  
    14.     public class ReplayCam : MonoBehaviour {
    15.  
    16.         [Header("Recording")]
    17.         public int videoWidth = 1280;
    18.         public int videoHeight = 720;
    19.  
    20.         private IEnumerator Start () {
    21.  
    22.  
    23.             var cameraTexture = new WebCamTexture();
    24.             cameraTexture.Play();
    25.  
    26.             // Create a clock for generating recording timestamps
    27.             var clock = new RealtimeClock();
    28.  
    29.             // Create a recorder
    30.             var mediaRecorder = new MP4Recorder(videoWidth, videoHeight, 30, 0, 0, OnReplay);
    31.  
    32.             // Record 150 frames
    33.             for (int i = 0; i < 150; i++)
    34.             {
    35.                 // Commit the frame to NatCorder for encoding
    36.                 mediaRecorder.CommitFrame(cameraTexture.GetPixels32(), clock.Timestamp);
    37.                 // Wait for the end of the application frame
    38.                 yield return new WaitForEndOfFrame();
    39.             }
    40.             // Stop recording
    41.             mediaRecorder.Dispose();
    42.  
    43.  
    44.         }
    45.  
    46.         private void OnReplay (string path) {
    47.             Debug.Log("Saved recording to: "+path);
    48.             // Playback the video
    49.             #if UNITY_EDITOR
    50.             UnityEditor.EditorUtility.OpenWithDefaultApp(path);
    51.             #elif UNITY_IOS
    52.             Handheld.PlayFullScreenMovie("file://" + path);
    53.             #elif UNITY_ANDROID
    54.             Handheld.PlayFullScreenMovie(path);
    55.             #endif
    56.         }
    57.     }
    58. }

    [COLOR=rgba(0, 0, 0, 0.87)]
    [/COLOR]
     

    Attached Files:

  50. phoenixrising

    phoenixrising

    Joined:
    Aug 9, 2013
    Posts:
    57
    I would like to have a render to video function that plays a video
    and adds UI animations over top
    and then saves the resulting video.
    I have this working at normal time.timescale
    but when I adjust the time.timescale with NatCorder
    then 1) depending on the timescale sometimes it never triggers the save video/onrecording done callback
    2) I cannot adjust the variables properly to have the movie saved in such a way as it plays at normal speed with full frame rate when the time scale is increased

    If the renderSpeed = 10 then the file is not saved
    at renderSpeed = 5 the movie saved but it contains the movie at 5x speed not normal speed as desired

    Can you please help me understand how to set the FixedIntervalClock and framerate and be able to speed up timeScale and still save the frames so they are a normal playback speed video?

    I dug a little deeper and it seems that the frames get rendered with a WaitForEndOfFrame call in CameraInput.
    Does Time.captureFramerate effect this?

    Code (CSharp):
    1.  
    2. Time.timeScale = renderSpeed;
    3. videoPlayer.playbackSpeed = renderSpeed;
    4. var sampleRate = 0;
    5. var channelCount = 0;
    6. fixedIntervalClock = new FixedIntervalClock((int)(renderSpeed));
    7. videoRecorder = new MP4Recorder(videoWidth, videoHeight, frameRate, sampleRate, channelCount, OnReplay);
    8. cameraInput = new CameraInput(videoRecorder, fixedIntervalClock, Camera.main);
    9. videoPlayer.Play();
    10.  
     
    Last edited: Dec 25, 2019