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
    This sounds like a VideoPlayer issue then. Consider filing a bug report with Unity.
     
  2. Lanre

    Lanre

    Joined:
    Dec 26, 2013
    Posts:
    3,973
    This is not supported. Instead, you should record the scene's AudioListener which catches all audio in the scene.
     
  3. Privateer

    Privateer

    Joined:
    Jun 5, 2016
    Posts:
    23
    This helped. Why is the default bitrate so low, then?
     
  4. Lanre

    Lanre

    Joined:
    Dec 26, 2013
    Posts:
    3,973
    It depends on your recording resolution. For some resolutions, the default bitrate is sufficient.
     
  5. danielesuppo

    danielesuppo

    Joined:
    Oct 20, 2015
    Posts:
    331
    Hi Lanre,
    I think there's a BUG with NatCorder and ARCore: if I enable "Record Microphone" on ReplayCam script, with "HelloAR" sample ARCore scene, the app freeze.

    But it work fine with "Record Microphone" disabled.

    Tested with Unity 2018.1.6f1
    On Samsung Galaxy S8 - Android 8

    Can you help me?
    Thank-you!
     
  6. zlllwy520

    zlllwy520

    Joined:
    Feb 27, 2018
    Posts:
    4
    I would like to record the contents of two cameras, one is an AR camera, the other is with a gyroscope moving. Can you provide a way to record multiple cameras?
     
  7. Lanre

    Lanre

    Joined:
    Dec 26, 2013
    Posts:
    3,973
    Can you email me the full logs from logcat as a .txt file? It might be the case that ARCore doesn't work when the microphone is enabled.
     
  8. Lanre

    Lanre

    Joined:
    Dec 26, 2013
    Posts:
    3,973
    We didn't include a multiple-camera recorder in NatCorder because these configurations tend to be highly application-specific. You will have to manually implement a recorder that will record both cameras how you want it to. You can use this gist as a starting template.
     
  9. shin_unity197

    shin_unity197

    Joined:
    Oct 30, 2017
    Posts:
    18
    Hi,
    I'm integrating Natcorder with Android and it seems there is about a second delay from the microphone to the video. This problem doesn't seem to occur on the iOS device. Is this a Unity's microphone problem or potentially the plugin?
     
  10. jkampitakis

    jkampitakis

    Joined:
    Dec 27, 2015
    Posts:
    56
    Hello, I have purchased the plugin but then I noticed it doesn't support recording the overlay camera canvas so our UI isn't visible :(

    Is there any way to fix this?

    Kind regards,
    John.
     
  11. Lanre

    Lanre

    Joined:
    Dec 26, 2013
    Posts:
    3,973
    This is likely latency from Unity's microphone API. NatCorder itself can't add latency, it uses the timestamps that are provided when a video frame or audio buffer is committed.
     
  12. Lanre

    Lanre

    Joined:
    Dec 26, 2013
    Posts:
    3,973
    Check the README.md for more information on this. In short, you need to use a different canvas mode.
     
  13. dragologic

    dragologic

    Joined:
    Oct 28, 2012
    Posts:
    16
    How to record both audio and microphone at same time?
     
  14. buckUnity

    buckUnity

    Joined:
    Apr 23, 2018
    Posts:
    10
    I'm getting this error in my android logcat while I'm recording my screen. Doesn't seem to crash anything and the video records/replays properly, just thought that you should know about it.
    upload_2018-9-6_14-19-14.png
     
  15. williamchan1993

    williamchan1993

    Joined:
    Nov 20, 2017
    Posts:
    1
    I have been testing NatCorder and Vuforia together on iPhone6 and iPhone6S, however the app keeps crashing on both phones due to memory issues when I start recording videos (with or without AR objects being tracked). I have tried to lower the resolution for the recorded video, it works better for iPhone6S, but iPhone6 still got the memory issue and crashes.

    Is there any way I can improve this situation? Further reducing the resolution is not a good solution as the video recorded does not look too nice already.

    Screen Shot 2018-09-07 at 11.53.30.png
     
  16. unity_r4mSHKj0yZb-4g

    unity_r4mSHKj0yZb-4g

    Joined:
    Sep 11, 2017
    Posts:
    9
    Hi, I'm trying to use this plugin and I'm getting an error on iOS that the framePool in NatCorderiOS.cs already has that particular key.

    This is the code I'm using to feed it the frames:
    Code (CSharp):
    1.  
    2.     void OnRenderImage (RenderTexture source, RenderTexture destination) {
    3.  
    4.         if (isRecording && NatCorder.IsRecording) {
    5.             frame = NatCorder.AcquireFrame ();
    6.             Graphics.Blit (source, frame);
    7.             NatCorder.CommitFrame (frame);
    8.         }
    9.  
    10.         // Passthrough
    11.         UnityEngine.Graphics.Blit (source, destination);
    12.     }
    13.  
     

    Attached Files:

  17. free_ono

    free_ono

    Joined:
    Oct 6, 2016
    Posts:
    2
    Hello, I bought a plugin.
    I am sorry that English is wrong because it is Google translation.
    Is it possible to shoot in wide view when holding in a vertical position?
     
  18. Lanre

    Lanre

    Joined:
    Dec 26, 2013
    Posts:
    3,973
    You can use the AudioRecorder component for this (the AudioRecorder.Create function). Pass in AudioListener for game audio and an AudioSource that is playing the microphone clip. AudioRecorder will mix audio from both.
     
  19. Lanre

    Lanre

    Joined:
    Dec 26, 2013
    Posts:
    3,973
    I'm not sure what this is. The error is not descriptive at all.
     
  20. Lanre

    Lanre

    Joined:
    Dec 26, 2013
    Posts:
    3,973
    What is your application's framerate? If it is 60, make sure that you are sending frames to NatCorder at 30FPS by setting the `CameraRecorder.recordEveryNthFrame` to 2. This property causes NatCorder to record every other application frame, causing the effective framerate to be 30FPS. With this, there won't be a backlog of frames in memory waiting to be encoded.
     
  21. Lanre

    Lanre

    Joined:
    Dec 26, 2013
    Posts:
    3,973
    What testing device are you using? Does it use Metal or OpenGL ES? In your code, add this line before the call to `Blit` and let me know what is logged:
    Code (CSharp):
    1. Debug.Log((frame as RenderTexture).GetNativeTexturePtr());
     
  22. Lanre

    Lanre

    Joined:
    Dec 26, 2013
    Posts:
    3,973
    You can write a shader to do this. Your shader should add blank space on either side of the camera frame. You can then record with this shader using the `CameraRecorder.recordingMaterial` property.
     
  23. free_ono

    free_ono

    Joined:
    Oct 6, 2016
    Posts:
    2
    Thanks Lanre
     
    Lanre likes this.
  24. unity_r4mSHKj0yZb-4g

    unity_r4mSHKj0yZb-4g

    Joined:
    Sep 11, 2017
    Posts:
    9
    Hi, I've tried several devices (7+, SE, 8, X, iPad Pro 10.5 inch), and it only happens on the iPhone 7+ iOS version 11.3.1, using Metal, don't think it's the os cause it worked fine on the SE with the same os version.

    this time I got a different error (sometimes it doesn't even give an error):

    Code (CSharp):
    1. 2018-09-10 09:26:32.180205-0600 PROJECTNAME[481:121583] -[MTLRenderPipelineDescriptorInternal validateWithDevice:], line 2400: error 'No valid pixelFormats set.'
    2. -[MTLRenderPipelineDescriptorInternal validateWithDevice:]:2400: failed assertion `No valid pixelFormats set.

    The only difference I notice with the other phones is that this one has far more 0 pointers, the other ones do have here and there but not nearly as much.

    here's the log you asked for: https://pastebin.com/mL0ZVYzT (didn't let me upload the file nor copy it here cause it took it as spam :3)

    I'll add a screenshot of the stack JIC.

    EDIT: After some more testing I got both errors at the same time (unity sucks when printing out the errors >.<, feels so random when they print or not) and I got the duplicate key on dictionary error FIRST then it printed out the framePtr: 0 and finally the 'No valid pixelFormats set.'.
     

    Attached Files:

    Last edited: Sep 10, 2018
  25. someone-somewhere

    someone-somewhere

    Joined:
    Mar 5, 2018
    Posts:
    1
     
  26. infinity135

    infinity135

    Joined:
    Feb 5, 2018
    Posts:
    17
    Hey, I am getting the following error
    OPENGL NATIVE PLUG-IN ERROR: GL_INVALID_VALUE: Numeric argument out of range
    When Recording Completes
     
  27. Lanre

    Lanre

    Joined:
    Dec 26, 2013
    Posts:
    3,973
    The error you are getting about validation can be resolved by disabling Metal API Validation in the Scheme settings in Xcode (Project > Edit Scheme). Regarding the RenderTexture being zero, it looks related to this issue. Try adding this before the Debug.Log to see if it fixes the issue:
    Code (CSharp):
    1. var _= (frame as RenderTexture).colorBuffer;
     
  28. Lanre

    Lanre

    Joined:
    Dec 26, 2013
    Posts:
    3,973
    Errors like this are hard to investigate because Unity doesn't provide a source for the error. Except it creates an issue in your application, I would ignore it.
     
  29. BLOBENJEU

    BLOBENJEU

    Joined:
    Jan 11, 2018
    Posts:
    2
    Hello,
    We have this asset since very recently, and we don't quite understand, every videos we record with natcorder have a very crappy, hashed sound quality (image is ok), even in the test scene. ave you ever heard of that issue ?

    edit: same result in unity editor and built in an ipad
     
  30. tcmeric

    tcmeric

    Joined:
    Dec 21, 2016
    Posts:
    190
    Here is my simple example of using Natcorder for timelapse videos. I toggle it using uGUI buttons (therefore two public class. One to toggle gif and one to toggle mpeg). Var timeStampduration is how long each screen capture should play for in the final video (measure in nano seconds). So 62500000 is 1/6th of a second. Var screenShotDuration is how often to take a screenshot in seconds. So 0.5f is one screenshot every 1/2 second.


    Code (CSharp):
    1.  
    2. using UnityEngine;
    3. using System.Collections;
    4. using NatCorderU.Core;
    5.  
    6. namespace dumbGameDev
    7. {
    8.     public class ClampTimeLapse : MonoBehaviour
    9.     {
    10.         [SerializeField]
    11.         private Camera _camera;
    12.  
    13.         [SerializeField]
    14.         private long timeStampDuration = 62500000;
    15.  
    16.         [SerializeField]
    17.         private float screenShotDuration = 0.5f;
    18.  
    19. // debug
    20.  
    21.         [SerializeField]
    22.         private bool enableDebug;
    23.  
    24.         private long newTimeStamp;
    25.         private float timer = 0;
    26.         private bool recording = false;
    27.         private Frame frame;
    28.         private bool isFirstFrame = true;
    29.         private bool isGif;
    30.  
    31.  
    32.         private void Start()
    33.         {
    34.             if (NatCorder.IsRecording)
    35.             {
    36.                 NatCorder.StopRecording();
    37.             }
    38.  
    39.             recording = false;
    40.             timer = 0;
    41.             isFirstFrame = true;
    42.         }
    43.  
    44.         public void ToggleRecording()
    45.         {
    46.             isGif = false;
    47.  
    48.             if (!recording)
    49.             {
    50.                 StartRecording();
    51.             }
    52.             else
    53.             {
    54.                 StopRecording();
    55.             }
    56.         }
    57.  
    58.         public void ToggleGifRecording()
    59.         {
    60.             isGif = true;
    61.  
    62.             if (!recording)
    63.             {
    64.                 StartRecording();
    65.             }
    66.             else
    67.             {
    68.                 StopRecording();
    69.             }
    70.         }
    71.  
    72.         private void StartRecording()
    73.         {
    74.             if (enableDebug) Debug.Log("Video recording");
    75.  
    76.  
    77.             if (!isGif)
    78.             {
    79.                 // Start recording
    80.                 NatCorder.StartRecording(
    81.                     Container.MP4,
    82.                     new VideoFormat(640, 480),
    83.                     AudioFormat.None,
    84.                     OnVideo
    85.                 );
    86.             }
    87.  
    88.             else
    89.             {
    90.                 // Start recording
    91.                 NatCorder.StartRecording(
    92.                     Container.GIF,
    93.                     new VideoFormat(480, 320),
    94.                     AudioFormat.None,
    95.                     OnVideo
    96.                 );
    97.             }
    98.  
    99.             recording = true;
    100.         }
    101.  
    102.         private void StopRecording()
    103.         {
    104.             NatCorder.StopRecording();
    105.             if (enableDebug) Debug.Log("Video stopped");
    106.             recording = false;
    107.         }
    108.  
    109.         void Update()
    110.         {
    111.             if (recording)
    112.             {
    113.                 timer += Time.deltaTime;
    114.                 if (timer > screenShotDuration)
    115.                 {
    116.                     UpdateNat();
    117.                     timer = 0f;
    118.                 }
    119.             }
    120.         }
    121.  
    122.         private void UpdateNat()
    123.         {
    124.             if (NatCorder.IsRecording)
    125.             {
    126.                 _camera.enabled = true;
    127.                 frame = NatCorder.AcquireFrame();
    128.  
    129.                 if (isFirstFrame)
    130.                 {
    131.                     newTimeStamp = frame.timestamp;
    132.                     isFirstFrame = false;
    133.                     if (enableDebug) Debug.Log("First frame time " + frame.timestamp);
    134.                 }
    135.                 else
    136.                 {
    137.                     newTimeStamp += timeStampDuration;
    138.                     frame.timestamp = newTimeStamp;
    139.                 }
    140.  
    141.  
    142.                 _camera.targetTexture = frame;
    143.                 _camera.Render();
    144.                 NatCorder.CommitFrame(frame);
    145.                 if (enableDebug) Debug.Log("Frame Commited");
    146.                 _camera.enabled = false;
    147.             }
    148.         }
    149.  
    150.         void OnVideo(string path)
    151.         {
    152.             if (enableDebug) Debug.Log("Video Finished and saved at : " + path);
    153.         }
    154.     }
    155. }
     
    Lanre likes this.
  31. danielesuppo

    danielesuppo

    Joined:
    Oct 20, 2015
    Posts:
    331
    I'll do that in a couple of days!
     
    Lanre likes this.
  32. Lanre

    Lanre

    Joined:
    Dec 26, 2013
    Posts:
    3,973
    Are you recording game audio or microphone audio? Can you share some code?
     
  33. unity_r4mSHKj0yZb-4g

    unity_r4mSHKj0yZb-4g

    Joined:
    Sep 11, 2017
    Posts:
    9

    Hi, I just tried adding what you said and indeed most of the zeros are gone, however it does get 1 of them and it uses it with no issue but the next one it gets will still make it crash like you can see here: https://pastebin.com/HF4EjAVG

    Metal API Validation is already disabled btw.
     
  34. nikosurfing

    nikosurfing

    Joined:
    Mar 11, 2014
    Posts:
    45
    Hey, i interested to buy this asset, but i have some questions:
    1. Can it save to gallery android? I see on previous post that it not possible in the current version, so we need to move manually
    2. Is there a APK example file?
    3. Any plan for discount price?
     
  35. danielesuppo

    danielesuppo

    Joined:
    Oct 20, 2015
    Posts:
    331
    Hi Lanre, sorry for my late reply.
    When I enable the microphone (and I touch the record button) the app freeze and on Logcat there's any message anymore. No errors, nothing. It just freeze...
     
  36. Lanre

    Lanre

    Joined:
    Dec 26, 2013
    Posts:
    3,973
    I'll add a catch so that zeros are discarded. In the mean time, you should set Script Call Execution to "Slow and Safe" in Player Settings.
     
  37. Lanre

    Lanre

    Joined:
    Dec 26, 2013
    Posts:
    3,973
    No, it doesn't provide this functionality. But you can use our free NatShare API to do this.
    Currently there is but it's pretty outdated. I'll update it and share the link with you.
    I believe Unity has a sale planned within the next few months.
     
  38. Lanre

    Lanre

    Joined:
    Dec 26, 2013
    Posts:
    3,973
    That's fine. Send me the full logs from logcat (no filtering). The logs could have a clue.
     
  39. strongbox3d

    strongbox3d

    Joined:
    May 8, 2012
    Posts:
    860
    Hello Lanre,

    If I buy NatCorder, and download your other asset NatShare... Can I share gameplay videos recorded with NatCorder to Facebook, Twitter, etc from Android/iOS? Is that part of the functionality of these two assets?

    Of course I mean easily, without having to create a new shader, or plugin for the platform or anything like that. Just by using what it comes with these two assets.

    Regards,
    Carlos
     
  40. Lanre

    Lanre

    Joined:
    Dec 26, 2013
    Posts:
    3,973
    Yes. You can record videos with NatCorder, and share videos using the native sharing sheet with NatShare.
     
  41. infinity135

    infinity135

    Joined:
    Feb 5, 2018
    Posts:
    17
    I have observed this error on devices using Andriod below lollipop. On the Above platforms it runs fine
     
  42. infinity135

    infinity135

    Joined:
    Feb 5, 2018
    Posts:
    17
    How can I use Audio Listener for recordinh Audio usign NAtCorder Api
     
  43. mathias_unity633

    mathias_unity633

    Joined:
    Jul 17, 2018
    Posts:
    35
    I managed to make it crash my editor from calling these two functions:


    NatCorder.StartRecording(Container.MP4, VideoFormat.Screen, AudioFormat.None, OnVideoFinish);
    NatCorder.StopRecording();

    It crashes when I try to call StopRecording.

    OnVideoFinish only Debug.Logs the path.

    I'm running Unity 2018.1.8f1 on macOS.
     
  44. Lanre

    Lanre

    Joined:
    Dec 26, 2013
    Posts:
    3,973
    You can use the AudioRecorder class. Check out the ReplayCam example for how we use the AudioRecorder to record an AudioSource (it has an overload for an AudioListener).
     
  45. Lanre

    Lanre

    Joined:
    Dec 26, 2013
    Posts:
    3,973
    This is expected behaviour. You have to record something before calling StopRecording. Check out the README for recording using our CameraRecorder component, or recording frames manually with the NatCorder.CommitFrame function.
     
  46. viniverso

    viniverso

    Joined:
    Sep 11, 2015
    Posts:
    20
    Hi Lanren, how are you?

    I am a augmented reality developer what is looking for ways to bring the next level to the experience.
    I would like to know if the Natcoder can record some augmented reality experience with a good result (30 fps or medium quality). Is that possible?

    Best wishes,
    Vinicius
     
  47. unity_r4mSHKj0yZb-4g

    unity_r4mSHKj0yZb-4g

    Joined:
    Sep 11, 2017
    Posts:
    9
    Cool I'll be waiting for that, also I had some memory issues a couple times on the iPhone X, what do you recommend on that case? to do the same as the included CameraRecorder and record every nth frame = 2?
     
  48. phill_gmg

    phill_gmg

    Joined:
    Sep 2, 2018
    Posts:
    1
    Hi,

    We are trialing game recording plugins and yours seems to fit our requirements, however, we are having trouble with the audio recording.
    We are using FMOD and using AudioRecorder.Create or an AudioGetter for the audioListener do not work.
    Is there support for FMOD?

    Thanks
     
  49. Lanre

    Lanre

    Joined:
    Dec 26, 2013
    Posts:
    3,973
    Yes, NatCorder supports ARCore, ARKit, and Vuforia.
     
  50. Lanre

    Lanre

    Joined:
    Dec 26, 2013
    Posts:
    3,973
    Make sure you are not recording at a resolution higher than 1920x1080. And yes, you can record every second frame, which will effectively halve the framerate of your video.