Search Unity

  1. Unity 2019.2 is now released.
    Dismiss Notice

NatCorder - Video Recording API

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

  1. Lanre

    Lanre

    Joined:
    Dec 26, 2013
    Posts:
    2,600
    What is your recording resolution?
     
  2. vuiss

    vuiss

    Joined:
    Apr 7, 2016
    Posts:
    3
    Recording resolution is 720x1280 px. We tryied to move down the bitrate and the crash is now after ~1 minute..
     
  3. Lanre

    Lanre

    Joined:
    Dec 26, 2013
    Posts:
    2,600
    What device are you recording on? There shouldn't be any memory issues on Android except the device you are recording on doesn't have a lot of memory.
     
  4. soundmartell

    soundmartell

    Joined:
    Oct 31, 2013
    Posts:
    10
    Hello,
    Is it anyway to try before buy? I was using Everyplay in my AR app. :-(
    Best regards.
     
  5. Lanre

    Lanre

    Joined:
    Dec 26, 2013
    Posts:
    2,600
    Unfortunately there isn't a try before you buy. The asset is entirely code, so we can't create a trial version.
     
  6. Celsyum

    Celsyum

    Joined:
    Mar 4, 2019
    Posts:
    1
    Do NatCorder works on standalone Windows build, which is executed on Windows 7 64bit ?
     
  7. ViuMoreSupport

    ViuMoreSupport

    Joined:
    May 2, 2017
    Posts:
    2
    Hi Lanre,

    When I record with 720p or 1080p on an Android device, the video can be played by media player or ES media player. However, there is white border as the device's screen is 16:10. So I set the video resolution using Screen.width and Screen.height. The video is recorded, but can not be played on the device. When I copy to computer, it can be opened by VLC player. Is there a list of supported video resolution or it can be any defined values?
     
  8. Lanre

    Lanre

    Joined:
    Dec 26, 2013
    Posts:
    2,600
    NatCorder only supports Windows 8 and 10, not 7.
     
  9. Lanre

    Lanre

    Joined:
    Dec 26, 2013
    Posts:
    2,600
    The safest thing is to record at a standard resolution like 720p or 1080p.
     
  10. ViuMoreSupport

    ViuMoreSupport

    Joined:
    May 2, 2017
    Posts:
    2
    Thanks!

    The plugin requires Android 6.0 and above. I have several smart glasses that runs on Android 5.1. What would happen if it runs on Android 5.1?
     
  11. Lanre

    Lanre

    Joined:
    Dec 26, 2013
    Posts:
    2,600
    It won't run on Android 5.1. NatCorder requires Android API's that were introduced in API level 23 (Android 6). Consider upgrading your smart glasses to Android 6.
     
  12. Piccastudio

    Piccastudio

    Joined:
    Apr 4, 2014
    Posts:
    29
    Hi Lanre. Here is the Logcat file
     

    Attached Files:

  13. Lanre

    Lanre

    Joined:
    Dec 26, 2013
    Posts:
    2,600
    These logs are incomplete. I need to see the logs without filtering. You seem to be filtering for Unity and ActivityManager tags, which don't show any errors.
     
  14. Piccastudio

    Piccastudio

    Joined:
    Apr 4, 2014
    Posts:
    29
    Sorry about that. I am new to this kind of debuging,
    Here is the unfiltered log (I think)
     

    Attached Files:

  15. Lanre

    Lanre

    Joined:
    Dec 26, 2013
    Posts:
    2,600
    These logs are full, but have no single mention of NatCorder. Are you taking the logs for long enough? You should take them from app start to crash in your case.
     
  16. Piccastudio

    Piccastudio

    Joined:
    Apr 4, 2014
    Posts:
    29
    Yes. The logs now are even after the crash. But I also dont see a mention of NatCorder.. I dont know what could it be

    The only strange message I found after the app crashes is this:
    unsupported csc_hw_type
     
  17. Piccastudio

    Piccastudio

    Joined:
    Apr 4, 2014
    Posts:
    29
    Ok, now I think I´ve got the right Log.
    Sorry for the other files.
     

    Attached Files:

  18. Lanre

    Lanre

    Joined:
    Dec 26, 2013
    Posts:
    2,600
    I need to see the logs from app start. These logs contain an exception stack trace, but not the reason for said exception.
     
  19. TonyAbraham

    TonyAbraham

    Joined:
    Mar 4, 2019
    Posts:
    1
    Hello @Lanre , I am creating an AR app that records the augmentation and the camera view including the Unity audio and NOT the microphone. I attached this script to the record button;

    Code (CSharp):
    1. namespace NatCorderU.Examples {
    2.  
    3.     #if UNITY_EDITOR
    4.     using UnityEditor;
    5.     #endif
    6.     using UnityEngine;
    7.     using UnityEngine.UI;
    8.     using System.Collections;
    9.     using Core;
    10.     using Core.Recorders;
    11.     using Core.Clocks;
    12.     using NatShareU;
    13.  
    14.     public class ReplayCam : MonoBehaviour {
    15.  
    16.         [Header("Recording")]
    17.         public int videoWidth = 1280;
    18.         public int videoHeight = 720;
    19.         public string pathfinder;
    20.  
    21.         private CameraRecorder videoRecorder;
    22.         private AudioRecorder audioRecorder;
    23.         private IClock recordingClock;
    24.         public AudioListener audioListener;
    25.  
    26.         public void StartRecording () {
    27.             // Create recording formats
    28.             var videoFormat = new VideoFormat(videoWidth, videoHeight);
    29.  
    30.             // Create an audio format
    31.             var audioFormat = new AudioFormat(
    32.                 AudioSettings.outputSampleRate, // Unity's audio sample rate
    33.                 (int)AudioSettings.speakerMode  // Unity's audio channel count
    34.             );
    35.  
    36.             // Create a recording clock for generating timestamps
    37.             recordingClock = new RealtimeClock();
    38.  
    39.             // Start recording
    40.             NatCorder.StartRecording(Container.MP4, videoFormat, audioFormat, OnReplay);
    41.             videoRecorder = CameraRecorder.Create(Camera.main, recordingClock);
    42.  
    43.             audioRecorder = audioListener.gameObject.AddComponent<AudioRecorder>();
    44.         }
    45.  
    46.  
    47.         public void StopRecording () {
    48.             // Stop the recording
    49.             videoRecorder.Dispose();
    50.             NatCorder.StopRecording();
    51.         }
    52.  
    53.  
    54.         private void OnReplay (string path) {
    55.             pathfinder = path;
    56.             Debug.Log("Saved recording to: "+path);
    57.             // Playback the video
    58.             #if UNITY_EDITOR
    59.             EditorUtility.OpenWithDefaultApp(path);
    60.             #elif UNITY_ANDROID
    61.             Handheld.PlayFullScreenMovie(path);
    62.             #endif
    63.         }
    64.  
    65.         public void OnShare()
    66.         {
    67.             NatShare.Share(pathfinder);
    68.         }
    69.     }
    70. }
    I wanted to get the audio from the audio listener attached to the main camera so added this script there;

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using NatCorderU.Core;
    5. using NatCorderU.Core.Clocks;
    6.  
    7. /**
    8. * We attach this script to an AudioSource/AudioListener
    9. * and forward the audio to NatCorder
    10. */
    11. public class AudioRecorder : MonoBehaviour
    12. {
    13.  
    14.     // We need a clock for generating timestamps
    15.     RealtimeClock clock = new RealtimeClock();
    16.  
    17.     void OnAudioFilterRead(float[] samples, int channels)
    18.     {
    19.         // Send to NatCorder for encoding
    20.         NatCorder.CommitSamples(samples, clock.CurrentTimestamp);
    21.     }
    22. }
    But I get this error;

    UnityException: get_persistentDataPath can only be called from the main thread.
    Constructors and field initializers will be executed from the loading thread when loading a scene.
    Don't use this function in the constructor or field initializers, instead move initialization code to the Awake or Start function.
    NatCorderU.Core.Platforms.NatCorderiOS..ctor () (at Assets/NatCorder/Plugins/Managed/Platforms/NatCorderiOS.cs:38)
    NatCorderU.Core.Platforms.NatCorderWindows..ctor () (at Assets/NatCorder/Plugins/Managed/Platforms/NatCorderWindows.cs:15)
    NatCorderU.Core.NatCorder..cctor () (at Assets/NatCorder/Plugins/Managed/NatCorder.cs:111)
    Rethrow as TypeInitializationException: The type initializer for 'NatCorderU.Core.NatCorder' threw an exception.
    NatCorderU.Core.Clocks.RealtimeClock.get_CurrentTimestamp () (at Assets/NatCorder/Plugins/Managed/Clocks/RealtimeClock.cs:32)
    AudioRecorder.OnAudioFilterRead (System.Single[] samples, System.Int32 channels) (at Assets/AudioRecorder.cs:20)

    Please help, I am on a deadline. What should I do to get unity game audio and the camera video together to save and share it from camera roll.
     
    Last edited: Mar 9, 2019
    nikosurfing likes this.
  20. Pendulum_

    Pendulum_

    Joined:
    Jul 30, 2015
    Posts:
    99
    Does this asset give the ability to start/stop recording multiple times to create one final clip?

    EDIT: Also, how does the gif generation compare to the gif generator in 'Easy Mobile'?
     
  21. Lanre

    Lanre

    Joined:
    Dec 26, 2013
    Posts:
    2,600
    Use the included AudioRecorder script instead of creating and attaching your own AudioRecorder script. The ReplayCam example already illustrates how to record an audio component using the AudioRecorder script. Walk through the example code, the README, and the included documentation. I highly recommend against repurposing example code without understanding how it works.
     
  22. Lanre

    Lanre

    Joined:
    Dec 26, 2013
    Posts:
    2,600
    Nope. One recording session can only record to one file. But you can 'pause' recording by suspending all frame committing to NatCorder.
    Can you be more specific with this question? I'm not sure how to compare GIF generation, and I'm not at all familiar with Easy Mobile so I don't have enough info to answer this.
     
  23. FromZed

    FromZed

    Joined:
    Oct 27, 2015
    Posts:
    3
    Hey there @Lanre, Im using Natcorder and every time I let go of the record button or reach the recording limit the app crashes without saving a video file. I am on Android version 9 and am using your example scene, GreyWorld. Below is what I was able to get from logcat. Please let me know what I need to do to fix this.
     

    Attached Files:

    • log3.txt
      File size:
      539.5 KB
      Views:
      337
  24. MeafQ

    MeafQ

    Joined:
    Mar 11, 2019
    Posts:
    1
    Could it be used for non-realtime render recordings?
     
    Last edited: Mar 11, 2019
  25. Aadhilkhan

    Aadhilkhan

    Joined:
    Dec 22, 2017
    Posts:
    2
    Where do I attach the AudioRecorder script and how do I call it from my Videorecorder script?
     
  26. Aadhilkhan

    Aadhilkhan

    Joined:
    Dec 22, 2017
    Posts:
    2
    Code (CSharp):
    1. namespace NatCorderU.Examples
    2. {
    3.  
    4. #if UNITY_EDITOR
    5.     using UnityEditor;
    6. #endif
    7.     using UnityEngine;
    8.     using UnityEngine.UI;
    9.     using System.Collections;
    10.     using Core;
    11.     using Core.Recorders;
    12.     using Core.Clocks;
    13.     using NatShareU;
    14.  
    15.     public class ScreenRecorder : MonoBehaviour
    16.     {
    17.         [Header("Recording")]
    18.         public int videoWidth = 720;
    19.         public int videoHeight = 1280;
    20.         public string pathfinder;
    21.  
    22.         private CameraRecorder videoRecorder;
    23.         private AudioRecorder audioRecorder;
    24.         private IClock recordingClock;
    25.  
    26.         public void StartRecording()
    27.         {
    28.             // Create recording formats
    29.             var videoFormat = new VideoFormat(videoWidth, videoHeight);
    30.             var audioFormat = new AudioFormat(AudioSettings.outputSampleRate, (int)AudioSettings.speakerMode);
    31.  
    32.             // Create a recording clock for generating timestamps
    33.             recordingClock = new RealtimeClock();
    34.            
    35.             // Start recording
    36.             NatCorder.StartRecording(Container.MP4, videoFormat, audioFormat, OnReplay);
    37.             videoRecorder = CameraRecorder.Create(Camera.main, recordingClock);
    38.             audioRecorder = AudioRecorder.Create(Camera.main.GetComponent<AudioListener>(), recordingClock);
    39.  
    40.         }
    41.  
    42.  
    43.         public void StopRecording()
    44.         {
    45.             // Stop the recording
    46.             videoRecorder.Dispose();
    47.             audioRecorder.Dispose();
    48.             NatCorder.StopRecording();
    49.         }
    50.  
    51.         private void OnReplay(string path)
    52.         {
    53.             Debug.Log("Saved recording to: " + path);
    54.             pathfinder = path;
    55.            
    56.             // Playback the video
    57. #if UNITY_EDITOR
    58.             EditorUtility.OpenWithDefaultApp(path);
    59. #elif UNITY_IOS
    60.             Handheld.PlayFullScreenMovie("file://" + path);
    61. #elif UNITY_ANDROID
    62.             Handheld.PlayFullScreenMovie(path);
    63. #endif
    64.         }
    65.  
    66.         public void OnShare()
    67.         {
    68.             NatShare.Share(pathfinder);
    69.         }
    70.     }
    71. }
    Is there anything wrong with my code? Why is it crashing when I press record on my non Snapdragon devices?
     
  27. Lanre

    Lanre

    Joined:
    Dec 26, 2013
    Posts:
    2,600
    I've gotten another report of this. I'm looking into it. Thanks for the logs.
     
  28. Lanre

    Lanre

    Joined:
    Dec 26, 2013
    Posts:
    2,600
    Yup. You can record in a for-loop. You just have to take special care with the timestamps that are being committed.
     
  29. Lanre

    Lanre

    Joined:
    Dec 26, 2013
    Posts:
    2,600
    You don't attach the AudioRecorder. You create it in code (the same way you create a CameraRecorder). Check out the ReplayCam code for how it is used.
     
  30. Lanre

    Lanre

    Joined:
    Dec 26, 2013
    Posts:
    2,600
    Your code looks good. I'm looking at the logs.
     
  31. Regone

    Regone

    Joined:
    Aug 1, 2014
    Posts:
    26
    Hi there :)
    Im having Issues on The iPhone X which I'm using 1Gb~1.2GB RAM steadily as I checked through Xcode.
    when I fire up the recording it jumps instantly to 1.78Gb RAM and crashes after 1~2 seconds.

    Natcorder 1.4.0
    Unity 2018.2.4f1
    iPhone X
    (12.1.2 - 16C101)
    Mac OS X High Sierra (10.13.6)
    Xcode 10.1

    Using the settings:
    Started to lower it down from

    720W1280H, 30fps, 1760000bp/s, 3kp/s
    to​
    540W960H, 30fps, 440000bp/s, 3kp/s​
    at minimum and didn't check any lower than that
    due to no changes that were visible :(

    Any idea how to fix that up?

    NatCorder: Initialized NatCorder 1.4 iOS backend

    NatCorderU.Core.NatCorder:.cctor()

    VideoRecorderManager:StartRecording()

    UnityEngine.Events.UnityEvent`1:Invoke(T0)

    UnityEngine.EventSystems.ExecuteEvents:Execute(GameObject, BaseEventData, EventFunction`1)

    UnityEngine.EventSystems.StandaloneInputModule:processTouchPress(PointerEventData, Boolean, Boolean)

    UnityEngine.EventSystems.StandaloneInputModule:processTouchEvents()

    UnityEngine.EventSystems.StandaloneInputModule:process()



    (Filename: /Users/builduser/buildslave/unity/build/Runtime/Export/Debug.bindings.h Line: 43)



    2019-03-11 14:41:11.513913+0200 app[2322:511428] NatCorder: Prepared MP4 video encoder at resolution 540x960@30Hz with average bitrate 440000 and keyframe interval 3s

    2019-03-11 14:41:11.514005+0200 app[2322:511428] NatCorder: MP4 recorder started recording

    2019-03-11 14:41:11.914279+0200 app[2322:511840] [Technique] World tracking performance is being affected by resource constraints [1]

    WARNING -> applicationDidReceiveMemoryWarning()

    WARNING -> applicationDidReceiveMemoryWarning()

    EDIT: And by the way, it works alright in UnityEditor, Jaggy though but it works.
     
    Last edited: Mar 11, 2019
  32. Lanre

    Lanre

    Joined:
    Dec 26, 2013
    Posts:
    2,600
    You need to update to 1.4.1. Delete NatCorder in your project then import 1.4.1 from the Asset Store.
     
  33. Regone

    Regone

    Joined:
    Aug 1, 2014
    Posts:
    26
    Thanks for the fast Reply, ...
    Edit: Pardon me for the stupidity that was written here before.
    The new version requires me to update unity, is there anyway not to upgrade Unity?
    This is crucial for me since I work in a team in a company and can't just upgrade it...
     
  34. Lanre

    Lanre

    Joined:
    Dec 26, 2013
    Posts:
    2,600
    Email me with your invoice number.
     
  35. sme855

    sme855

    Joined:
    Mar 13, 2016
    Posts:
    2
    Hi, i bought your asset a few days ago.
    Everything is working fine in the editor, it records and saves the video at the path; but it's not working in the windows build.

    In the windows build, whenever i call StopRecording(), my application just crashes completely. And i get this error in the debug. It's weird because it seems to be working fine in editor but not in the standalone build. I really need some help here...

    I'm recording from a camera which has a render texture attached to it.
    This is my function:

    public void btn_startRecodring()
    {
    //Enable recording camera
    RecorderCam.enabled = true;
    // Create a clock for generating timestamps
    recordingClock = new RealtimeClock();
    // Start recording
    NatCorder.StartRecording(
    Container.MP4,
    new VideoFormat(cameraTexture.width, cameraTexture.height),
    AudioFormat.None,
    OnVideo
    );

    StartCoroutine(RecordLoop());
    }
     

    Attached Files:

  36. Lanre

    Lanre

    Joined:
    Dec 26, 2013
    Posts:
    2,600
    Looks like you're running on Windows 10 32-bit. This is a known issue on 32-bit builds of Windows. I'm looking into it.
     
  37. texnoline21

    texnoline21

    Joined:
    Feb 6, 2016
    Posts:
    10
    Hello. We use for testing this configuration:
    Unity 18.3.2f1
    Device Mi Mix 3
    Android 9
    Minimun API Level 26
    When you try to stop recording, the application crashes. The resulting video file contains errors and does not play in any player.
    It was used as a test sample GreyWorld. The problem is the same, when you stop recording video, the application crashes.
    The code is very simple. I do not know what I'm doing wrong.

    Code (CSharp):
    1. namespace NatCorderU.Examples
    2. {
    3.  
    4. #if UNITY_EDITOR
    5.     using UnityEditor;
    6. #endif
    7.     using UnityEngine;
    8.     using UnityEngine.UI;
    9.     using System.Collections;
    10.     using Core;
    11.     using Core.Recorders;
    12.     using Core.Clocks;
    13.     using NatShareU;
    14.    
    15.  
    16.     public class VideoRecord : MonoBehaviour
    17.     {
    18.         [Header("Recording Video")]
    19.         public int videoWidth = 480;
    20.         public int videoHeight = 640;
    21.         public string localpatch;
    22.  
    23.         private CameraRecorder videoRecorder;
    24.         private AudioRecorder audioRecorder;
    25.         private IClock recordingClock;
    26.  
    27.     // Start record
    28.     public void StartRecord()
    29.         {
    30.             var videoFormat = new VideoFormat(videoWidth, videoHeight);
    31.             var audioFormat = new AudioFormat(AudioSettings.outputSampleRate, (int)AudioSettings.speakerMode);
    32.  
    33.             recordingClock = new RealtimeClock();
    34.  
    35.             NatCorder.StartRecording(Container.MP4, videoFormat, audioFormat, OnVideo);
    36.             videoRecorder = CameraRecorder.Create(Camera.main, recordingClock);
    37.             audioRecorder = AudioRecorder.Create(Camera.main.GetComponent<AudioListener>(), recordingClock);
    38.         }
    39.        
    40.         // Stop record
    41.         public void StopRecord()
    42.         {
    43.             videoRecorder.Dispose();
    44.             audioRecorder.Dispose();
    45.             NatCorder.StopRecording();
    46.         }
    47.  
    48.         void OnVideo(string path)
    49.         {
    50.             Debug.Log("Saved recording to: " + path);
    51.         }
    52.        
    53.         // Share video
    54.         public void OnShare()
    55.         {
    56.                 NatShare.Share(localpatch);
    57.         }
    58.     }
    59.  
    60. }
     

    Attached Files:

  38. Lanre

    Lanre

    Joined:
    Dec 26, 2013
    Posts:
    2,600
    This is a known issue. The fix will be on the Asset Store in a day or two.
     
  39. texnoline21

    texnoline21

    Joined:
    Feb 6, 2016
    Posts:
    10
    Thank you very much!
     
    Lanre likes this.
  40. Achoo

    Achoo

    Joined:
    Jun 4, 2015
    Posts:
    8
    the new Natcorder update causes the following error on stop recording of the video

    Code (CSharp):
    1. 03-12 15:42:44.436 12789-12846/com.test.nat E/Unity: NullReferenceException: Object reference not set to an instance of an object
    2.       at UnityEngine.GlobalJavaObjectRef.op_Implicit (UnityEngine.GlobalJavaObjectRef obj) [0x00001] in <b6d510486de34305839d30de90e040c0>:0
    3.       at UnityEngine.AndroidJavaObject._CallStatic[ReturnType] (System.String methodName, System.Object[] args) [0x0000f] in <b6d510486de34305839d30de90e040c0>:0
    4.       at UnityEngine.AndroidJavaObject.CallStatic[ReturnType] (System.String methodName, System.Object[] args) [0x00001] in <b6d510486de34305839d30de90e040c0>:0
    5.       at NatCorderU.Core.Readback.GLESReadback.<OnFrame>b__10_0 () [0x0001f] in D:\WorkSpace\Tests\Natcorder\Natcorder\Assets\NatCorder\Plugins\Managed\Readback\GLESReadback.cs:73
    6.       at NatCorderU.Core.Dispatch.RenderDispatcher.Update () [0x00013] in D:\WorkSpace\Tests\Natcorder\Natcorder\Assets\NatCorder\Plugins\Managed\Dispatch\RenderDispatcher.cs:48
    7.       at NatCorderU.Core.Dispatch.RenderDispatcher.OnRenderEvent (System.Int32 managedInstance) [0x00024] in D:\WorkSpace\Tests\Natcorder\Natco
     
    CorstiaanMediamonks likes this.
  41. Skjalg

    Skjalg

    Joined:
    May 25, 2009
    Posts:
    151
    Hi, we're currently trying to get the same out of NatCorder as we are getting when using Everyplay. As far as we can see the video sizes (in mb) is a bit higher than everyplay, this might be due to the audio compression not being the same.

    But the bigger issue is that Natcorder adds invisible (empty) frames at the beginning and end of the video, which has the side effect that the thumbnail of the video is missing. This is recorded in an iPhone X and shared to a mac and then previewed in quicktime.

    right side is everyplay, while left side is recorded in NatCorder.

    upload_2019-3-12_9-47-1.png
     
    Last edited: Mar 12, 2019
  42. sme855

    sme855

    Joined:
    Mar 13, 2016
    Posts:
    2
    Thanks a lot! It works now! I was building x86 version of my project before. Switched to x86_64 and it works now :D
     
    Lanre likes this.
  43. Regone

    Regone

    Joined:
    Aug 1, 2014
    Posts:
    26
    Thanks so much for the support, but unfortunately it still crashes... not after 2 seconds as I've encountered in 1.4.0 but 5 seconds...

    is there any way to trouble shoot it?

    same symptoms and situation as mentioned above -
    jumps from 1.1GB~ to 1.78GB Ram and crashes. :\
     
  44. Lanre

    Lanre

    Joined:
    Dec 26, 2013
    Posts:
    2,600
    Fix for this is getting submitted later today. Sorry for the inconvenience.
     
  45. Lanre

    Lanre

    Joined:
    Dec 26, 2013
    Posts:
    2,600
    Use `mediainfo` (get the command line tool) to inspect videos. You can directly affect the compression on NatCorder's videos by changing the video bitrate. The audio bitrate doesn't have a sizeable effect.
    I can't reproduce this, and NatCorder is programmed to specifically prevent this from being the case. We don't actually start recording until the first video frame is committed, so that the very first media packet (by timestamp) is always a video frame.
     
  46. Lanre

    Lanre

    Joined:
    Dec 26, 2013
    Posts:
    2,600
    I personally have no clue why Microsoft still chooses to publish a 32-bit version of Windows. 32-bit OS'es are now a thing of the past.
     
  47. Lanre

    Lanre

    Joined:
    Dec 26, 2013
    Posts:
    2,600
    I'll need to see logs, your recording code, and the frame time of your app when recording and when not recording.
     
  48. Regone

    Regone

    Joined:
    Aug 1, 2014
    Posts:
    26
    Sure

    NatCorder: Initialized NatCorder 1.4 iOS backend
    NatCorderU.Core.NatCorder:.cctor()
    VideoRecorderManager:StartRecording()
    UnityEngine.Events.UnityEvent:Invoke()
    TimerToUIFill:StartTimer()
    UnityEngine.Events.UnityEvent`1:Invoke(T0)
    UnityEngine.EventSystems.ExecuteEvents:Execute(GameObject, BaseEventData, EventFunction`1)
    UnityEngine.EventSystems.StandaloneInputModule:processTouchPress(PointerEventData, Boolean, Boolean)
    UnityEngine.EventSystems.StandaloneInputModule:processTouchEvents()
    UnityEngine.EventSystems.StandaloneInputModule:process()


    (Filename: /Users/builduser/buildslave/unity/build/Runtime/Export/Debug.bindings.h Line: 43)

    2019-03-12 16:12:36.572866+0200 app[3223:612955] NatCorder: Prepared MP4 video encoder at resolution 720x1280@30Hz with average bitrate 1320000 and keyframe interval 3s

    2019-03-12 16:12:36.572980+0200 app[3223:612955] NatCorder: MP4 recorder started recording

    WARNING -> applicationDidReceiveMemoryWarning()

    Code (CSharp):
    1. using UnityEditor;
    2.  
    3. using UnityEngine;
    4. using UnityEngine.UI;
    5. using System.Collections;
    6. using NatCorderU.Core.Recorders;
    7. using NatCorderU.Core.Clocks;
    8. using NatCorderU.Core;
    9. using System.IO;
    10. using System;
    11.  
    12. public class VideoRecorderManager : MonoBehaviour
    13. {
    14.  
    15.     [Header("Recording")]
    16.     public int videoWidth = 540;
    17.     public int videoHeight = 960;
    18.  
    19.     [Header("Microphone")]
    20.     public bool recordMicrophone;
    21.     public AudioSource microphoneSource;
    22.  
    23.     private CameraRecorder videoRecorder;
    24.     private AudioRecorder audioRecorder;
    25.     private IClock recordingClock;
    26.     private string savePath;
    27.  
    28.     public void StartStopToggle(bool start)
    29.     {
    30.         if (start)
    31.         {
    32.             StartRecording();
    33.         }
    34.         else
    35.         {
    36.             StopRecording();
    37.         }
    38.     }
    39.  
    40.     public void StartRecording()
    41.     {
    42.         // Create recording formats
    43.         var videoFormat = new VideoFormat(videoWidth, videoHeight, 30, 1320000);//Which is 0.22mb per second //Now it is actually 0.165mbp/s :D
    44.         var audioFormat = recordMicrophone ? AudioFormat.Unity : AudioFormat.None;
    45.         // Create a recording clock for generating timestamps
    46.         recordingClock = new RealtimeClock();
    47.         // Start recording
    48.         NatCorder.StartRecording(Container.MP4, videoFormat, audioFormat, OnFinishedRecording);
    49.         videoRecorder = CameraRecorder.Create(ModeStateSwitcher.Instance.SceneCameraManager.GetPlayerCamera(), recordingClock);
    50.         // Start microphone and create audio recorder
    51.         if (recordMicrophone)
    52.         {
    53.             StartMicrophone();
    54.             audioRecorder = AudioRecorder.Create(microphoneSource, true, recordingClock);
    55.         }
    56.     }
    57.  
    58.     private void StartMicrophone()
    59.     {
    60. #if !UNITY_WEBGL || UNITY_EDITOR // No `Microphone` API on WebGL :(
    61.         // Create a microphone clip
    62.         microphoneSource.clip = Microphone.Start(null, true, 60, 48000);
    63.         while (Microphone.GetPosition(null) <= 0) ;
    64.         // Play through audio source
    65.         microphoneSource.timeSamples = Microphone.GetPosition(null);
    66.         microphoneSource.loop = true;
    67.         microphoneSource.Play();
    68. #endif
    69.     }
    70.  
    71.     public void StopRecording()
    72.     {
    73.         // Stop the microphone if we used it for recording
    74.         if (recordMicrophone)
    75.         {
    76.             StopMicrophone();
    77.             audioRecorder.Dispose();
    78.         }
    79.         // Stop the recording
    80.         videoRecorder.Dispose();
    81.         NatCorder.StopRecording();
    82.     }
    83.  
    84.     private void StopMicrophone()
    85.     {
    86. #if !UNITY_WEBGL || UNITY_EDITOR
    87.         Microphone.End(null);
    88.         microphoneSource.Stop();
    89. #endif
    90.     }
    91.  
    92.     private void OnFinishedRecording(string path)
    93.     {
    94.        
    95.         If we will want to Auto Open the video - this is the way
    96.                           VVVVVVVVVVVVVVVV
    97.         Debug.Log("Saved recording to: " + path);
    98.          Playback the video
    99.         #if UNITY_EDITOR
    100.                 EditorUtility.OpenWithDefaultApp(path);
    101.         #elif UNITY_IOS
    102.                     Handheld.PlayFullScreenMovie("file://" + path);
    103.         #elif UNITY_ANDROID
    104.                     Handheld.PlayFullScreenMovie(path);
    105.         #endif
    106.     }
    107.  
    108.    
    109. }


    Btw: i've noticed that if i start recording and stop it after one second it jumps for example from 1.1gb to 1.35 gb and I can continue using the app and the memory doesn't clean itself...

    Oh and if record in editor it is super jaggy and stuttering but saves the file as expected. (and also the "jagginess" seen in the video)
     
  49. Lanre

    Lanre

    Joined:
    Dec 26, 2013
    Posts:
    2,600
    Can you try keeping the default bitrate to see if that affects anything? Your current setting is insanely low (the bitrate is specified in bits per second).
     
  50. Regone

    Regone

    Joined:
    Aug 1, 2014
    Posts:
    26
    Thanks again for the help :)

    Of-course it is insanely low(i've even set it to 440000 yesterday to check it out... :X), to hopefully minimize the impact on the memory.
    Sadly I get the same results using the default bitrate(5909759). :confused: