Search Unity

NatCorder - Video Recording API

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

  1. CPUDohyeong

    CPUDohyeong

    Joined:
    Mar 5, 2019
    Posts:
    1
    Code (CSharp):
    1. public void StartRecording()
    2.         {
    3.             StartRec();
    4.  
    5.             // Create a recording configuration
    6.             const float DownscaleFactor = 2f / 3;
    7.             var configuration = new Configuration((int)(Screen.width * DownscaleFactor), (int)(Screen.height * DownscaleFactor));
    8.  
    9.             // Start recording with microphone audio
    10.             if (recordMicrophoneAudio)
    11.             {
    12.                 // Start the microphone
    13.                 audioSource.clip = Extensions.Microphone.StartRecording();
    14.                 audioSource.loop = true;
    15.                 audioSource.Play();
    16.                 // Start recording with microphone audio
    17.                 Replay.StartRecording(Camera.main, configuration, OnReplay, audioSource, true);
    18.                 Debug.Log("microphone function");
    19.             }
    20.  
    21.             // Start recording without microphone audio
    22.             else
    23.             {
    24.                 Replay.StartRecording(Camera.main, configuration, OnReplay, audioSource, false);
    25.                 Debug.Log("else function");
    26.             }
    27.  
    28.              
    29.         }
    There is no problem with the quality of the recorded video, but the quality of the audio is very bad. Do you know how to adjust the sound quality?

    Please help me...
     
    Last edited: Apr 24, 2019
  2. Vision222114

    Vision222114

    Joined:
    Oct 14, 2014
    Posts:
    17
    I have a question.
    How do I get my camera resolution
    I want to use the highest resolution to recorder.
     
  3. Lanre

    Lanre

    Joined:
    Dec 26, 2013
    Posts:
    3,971
    I'm not at all familiar with this. I have a no clue as to why switching a camera in Vuforia will invert normals. This seems to be a known issue in Vuforia:
    - https://developer.vuforia.com/forum/issues-and-bugs/front-camera-issue-mirror-image
    - https://developer.vuforia.com/forum...has-inverted-normals-uwp-after-using-arcamera
     
  4. Lanre

    Lanre

    Joined:
    Dec 26, 2013
    Posts:
    3,971
    NatCorder doesn't have any video editing functionality. Anything that has to do with "after the video has been recorded" gets out of scope for NatCorder.
     
  5. Lanre

    Lanre

    Joined:
    Dec 26, 2013
    Posts:
    3,971
    You are recording from Unity's Microphone API, which is known to produce glitchy audio. We created our own native microphone API, NatMic, because of this.

    PS: Upgrade to the latest version of NatCorder. You are using a very old version.
     
  6. Lanre

    Lanre

    Joined:
    Dec 26, 2013
    Posts:
    3,971
  7. adre

    adre

    Joined:
    Mar 28, 2014
    Posts:
    38
    Hi @Lanre,
    when i record using the camera of the device, the video is very very slow, very low fps. Is it normal having these low performances?
     
  8. seneka123

    seneka123

    Joined:
    Jun 16, 2013
    Posts:
    30
    Hello! How to implement microphone recording in video with the help of NatCorder and NatMic?
     
  9. Lanre

    Lanre

    Joined:
    Dec 26, 2013
    Posts:
    3,971
    Depends on what the framerate of the camera and resolution of the recording is. I would need more information to advise you in any way. What device, what OS version, what is the camera framerate, what is the recording resolution, can you share some recording code?
     
  10. Lanre

    Lanre

    Joined:
    Dec 26, 2013
    Posts:
    3,971
    See the NatMicCorder Demo.
     
  11. seneka123

    seneka123

    Joined:
    Jun 16, 2013
    Posts:
    30
    Help me!
     

    Attached Files:

  12. Lanre

    Lanre

    Joined:
    Dec 26, 2013
    Posts:
    3,971
    Your script must implement NatMic's IAudioProcessor interface.
     
  13. seneka123

    seneka123

    Joined:
    Jun 16, 2013
    Posts:
    30
    How can I do it?
     
  14. Lanre

    Lanre

    Joined:
    Dec 26, 2013
    Posts:
    3,971
  15. adre

    adre

    Joined:
    Mar 28, 2014
    Posts:
    38
    Solved.
    Basically i was recording with a FixedIntervalClock at 25fps, because i needed 25fps the output. But the app was going at 60fps, so it was basically slowing down the video. Solved just forcing the app at 25fps during the recording and then back to 60.

    Thanks.
     
    Lanre likes this.
  16. anatoogle

    anatoogle

    Joined:
    May 25, 2018
    Posts:
    6
    Hi,
    is it possible to export a jpg image sequence in addition / or instead of the mp4 or GIF?
    I'm using NatCorder on my Android.
     
  17. Lanre

    Lanre

    Joined:
    Dec 26, 2013
    Posts:
    3,971
    No this is not supported by NatCorder.
     
  18. Mr-Rouf

    Mr-Rouf

    Joined:
    Mar 1, 2015
    Posts:
    10
    Last edited: May 1, 2019
  19. Lanre

    Lanre

    Joined:
    Dec 26, 2013
    Posts:
    3,971
    Can you try deleting and reimporting NatMic into your project? Also, note that armv7 support will be removed in the next updates of our API's because we will be targeting iOS 11, which formally deprecates armv7. So a longer-term fix here will be to simply not build an armv7 slice.
     
  20. Mr-Rouf

    Mr-Rouf

    Joined:
    Mar 1, 2015
    Posts:
    10
    I re-imported NatMic as you suggested - nothing has changed.
    Next step - I set IOS version to 11, and now it work fine. Thanks.
     
    Lanre likes this.
  21. davidborbis

    davidborbis

    Joined:
    May 2, 2019
    Posts:
    27
    I am interested in purchasing this asset. With this asset is it possible to record an AR session while mirroring the session live to an apple TV/miracast dongle with IOS or android?
     
  22. Lanre

    Lanre

    Joined:
    Dec 26, 2013
    Posts:
    3,971
    NatCorder functions entirely within Unity Engine. As a result, there is no support for things like mirroring.
     
  23. davidborbis

    davidborbis

    Joined:
    May 2, 2019
    Posts:
    27
    Thanks for the response. I did not word my question properly. I was wondering if it was possible to record through your asset in my application, and still be able to mirror outside of the application with the operating system.

    For example I will mirror my Ipad to my apple tv, then open my unity app. I tried using replay kit with IOS to record my screen within my unity app.
    https://docs.unity3d.com/ScriptReference/Apple.ReplayKit.ReplayKit.html
    When I am mirroring, it becomes unavailable until I stop mirroring, it's like IOS can handle one or the other and not both at the same time.

    With Android, I have tried using a screen recorder app, and then using smart view to connect to a miracast dongle, and then open my unity app. I tried several apps and whenever I get this message from an app “(app name) will start capturing everything that's displayed on your screen” I will get kicked off the miracast device. I tried using this plugin with my unity project so I could just record from my app.
    https://github.com/thanh-nguyen-kim/Unity_Android_Screen_Recorder
    And it gave me that same message with my app that I got with the screen recording apps and kicked me off.

    So I didn’t mean to ask if your asset could mirror, sorry for the confusion. I was just wondering if I could still mirror from my device, and record from my unity app using your asset, or if I would get the same limitations.
     
  24. unity_noMf5kG54sxntg

    unity_noMf5kG54sxntg

    Joined:
    Nov 18, 2018
    Posts:
    4
    Hello.
    I bought NatCorder.

    I could mp4 saved :) (ReplayCam_ok.cs)
    But I want use device microphone and I bought nat mic.
    And I changed from ReplayCam_ok.cs to ReplayCam_bad.cs.
    It doesn't work. I couldn't save.
    What should I do??

    I changed Android Manifest
    Code (CSharp):
    1. "  <uses-feature android:name="android.hardware.microphone" android:required="true" />
    2. "
     

    Attached Files:

  25. Lanre

    Lanre

    Joined:
    Dec 26, 2013
    Posts:
    3,971
    I would imagine that NatCorder would see the same constraints when mirroring. The hardware encoder likely becomes unavailable when mirroring (it is probably being used to transmit frames for mirroring).
     
    davidborbis likes this.
  26. Lanre

    Lanre

    Joined:
    Dec 26, 2013
    Posts:
    3,971
    Can you share logs from logcat?
     
  27. unity_noMf5kG54sxntg

    unity_noMf5kG54sxntg

    Joined:
    Nov 18, 2018
    Posts:
    4
    Thanks your replay.
    There is no error log, but i solved :)

    I changed from "public class ReplayCam : IAudioProcessor" to "public class ReplayCam : MonoBehaviour,
    IAudioProcessor" and created new prefab.
     
    Lanre likes this.
  28. davidborbis

    davidborbis

    Joined:
    May 2, 2019
    Posts:
    27
    Thank you for your response.

    I found out over the weekend, with the google app "play games", you can screen record and mirror the game your are playing, so it is possible, and I didn't get pop up message. Does anyone who has made an app with this asset in android know if you get the “(app name) will start capturing everything that's displayed on your screen” alert message from your android when you record video?
     
  29. davidborbis

    davidborbis

    Joined:
    May 2, 2019
    Posts:
    27
    I went ahead and purchased it, and it works! I can mirror and record with IOS. I am excited :D
     
    Lanre likes this.
  30. Lanre

    Lanre

    Joined:
    Dec 26, 2013
    Posts:
    3,971
    Nope, because NatCorder is technically not a screen recorder; it is a texture recorder that can--in effect--record the screen.
    Sounds great!
     
  31. HappyShip

    HappyShip

    Joined:
    Jun 15, 2017
    Posts:
    7
    I've been trying to record my AR scenario with this, but been running into problems.
    Using the plugin, videos do seem to get saved to my (Android) phone (in the persistent datapath folder), however these .mp4 files seem to have a length of 0 seconds. They cannot be played by a videoplayer, they do not show up in the gallery of the phone, but they do take up memory.

    Am I missing something obvious that i should have done? I'll attach the code I'm using, which is pretty similar to the code used in your ReplayCam example.

    EDIT: It seems like I did miss something obvious; I overlooked that in the example, the AudioSource is assigned in the inspector. Mine was never assigned to, therefor throwing a NullReference and breaking the recording. Woops... :(
     

    Attached Files:

    Last edited: May 7, 2019
  32. Lanre

    Lanre

    Joined:
    Dec 26, 2013
    Posts:
    3,971
    Sounds good.
     
  33. PYJ11

    PYJ11

    Joined:
    Jan 29, 2019
    Posts:
    7
    Can I use NatCorder to record my voice?
     
  34. PYJ11

    PYJ11

    Joined:
    Jan 29, 2019
    Posts:
    7
    내 음성과 게임 화면을 동시에 녹음 할 수 있습니까?
     
  35. Lanre

    Lanre

    Joined:
    Dec 26, 2013
    Posts:
    3,971
    NatCorder is a video recorder. It is not a microphone, and does not record only audio (there must be video).
     
  36. PYJ11

    PYJ11

    Joined:
    Jan 29, 2019
    Posts:
    7
    Thanks!bb
     
  37. creat327

    creat327

    Joined:
    Mar 19, 2009
    Posts:
    1,756
  38. Lanre

    Lanre

    Joined:
    Dec 26, 2013
    Posts:
    3,971
    NatCorder does not support UWP, only Windows 10.
    NatCorder is strictly a video recorder. It does not have any social functionality.
    I'm not familiar with this package, but it looks like a screen recorder. NatCorder is technically a texture recorder, so it is much more versatile and supports more platforms.
     
  39. worstoo

    worstoo

    Joined:
    Nov 10, 2016
    Posts:
    1
    I have purchased natcorder. I have had a few issues getting it working.

    On an older version of natcorder the editor worked fine, but recordings were corrupt and unplayable on iOS & Android. I have upgraded to the latest version of natcorder and now my editor recordings are recording very slowly (1 frame every second or two.) And the resulting videos are sometimes corrupt. The plugin is completely unusable as it is.

    I've re-imported natcorder completely but the results are the same. The greyworld and replay camera examples both exhibit the issue. Likewise, the recording doesn't work on iOS or Android as expected.

    Am I doing something wrong???

    Editor:
    MacBook Pro (15-inch, 2018)
    Mac OS 10.14.4 (18E226)
    Unity 2018.3.14f1 & Unity 2019.1.2f1
     
  40. Lanre

    Lanre

    Joined:
    Dec 26, 2013
    Posts:
    3,971
    I haven't had any report of an issue like this. You say the ReplayCam and GreyWorld examples exhibit this same behaviour of 1 frame every second or two? Can you upload one such corrupt video? I'd like to analyse it.
     
  41. anatoogle

    anatoogle

    Joined:
    May 25, 2018
    Posts:
    6
    When I use the VideoPlayer in Unity, the recorded Video from NatCorder does not play correctly.
    In the Editor the video appears to jump a few frames. On the Android it will only play a few frames and then stops.
    I created a Debug.Log to inspect what might happen (See Upload Picture).
    It looks like that some frames are getting skipped and some frames are being played several times.
    (sometimes it skip or repeat up to 6 times/frames)
    This problem happens with any Video I create in the Editor or on Android with NatCorder (latest Version).
    Other video files are working without any issue.

    Any idea what might cause my problem?
     

    Attached Files:

  42. Lanre

    Lanre

    Joined:
    Dec 26, 2013
    Posts:
    3,971
    Email me the recorded video itself. The Unity VideoPlayer adds another layer of possibilities that could be a factor in this issue. I need to isolate it to NatCorder to confirm that it is in fact a NatCorder bug.
     
  43. anatoogle

    anatoogle

    Joined:
    May 25, 2018
    Posts:
    6
    Thanks for your quick response. I just send the Email.
     
    Lanre likes this.
  44. summer_zc

    summer_zc

    Joined:
    Dec 14, 2018
    Posts:
    4
    when I use this asset in android , I found this crash when i play Animation complete to stop NatCorder mp4Recorder, the android thread killed, can you help me?
     

    Attached Files:

  45. nikosurfing

    nikosurfing

    Joined:
    Mar 11, 2014
    Posts:
    45
    Hi, for the latest version i've got warning error:


    Assets\NatCorder\Examples\ReplayCam\CameraPreview.cs(29,39): warning CS0649: Field 'CameraPreview.useFrontCamera' is never assigned to, and will always have its default value false



    Eeven it's not crucial, but i need to delete this warning. How to fix it?
     
  46. nikosurfing

    nikosurfing

    Joined:
    Mar 11, 2014
    Posts:
    45
    @Lanre : Can you write the script example to do this? Please i am not coder/programmer. I need to record from audioListener NOT Microphone.

    EDIT:
    audioRecorder = AudioRecorder.Create(audioListener, recordingClock);

    This code no longer work :(

    UPDATE:
    Finally got it. For someone who want to record from audio listener, not from microphone this is the code:
    audioInput = new AudioInput(videoRecorder, recordingClock, audioListener);
     
    Last edited: May 15, 2019
    Lanre likes this.
  47. glutvort

    glutvort

    Joined:
    Apr 13, 2019
    Posts:
    31
    I need your help. I Use ARCore and i need to record video. I use latest vercion of plugin. My code
    Code (CSharp):
    1.  
    2. _clock = new RealtimeClock();
    3. _mediaRecorder = new MP4Recorder(Screen.width,Screen.height,30,0,1,OnRecording);
    4. _cameraInput =  new CameraInput(_mediaRecorder,_clock,Camera.main);
    5. _audioInput = new AudioInput(_mediaRecorder,_clock,Camera.main.GetComponent<AudioListener>());
    When i start recording my app freezing and dont record. Also my saved video is 480p((
     
    Last edited: May 15, 2019
  48. Lanre

    Lanre

    Joined:
    Dec 26, 2013
    Posts:
    3,971
    You are using an older version of NatCorder. Upgrade to 1.5.1 on the Asset Store. If the crash remains, upload the logs in a .txt file (instead of taking a screenshot).
     
  49. Lanre

    Lanre

    Joined:
    Dec 26, 2013
    Posts:
    3,971
    Your sample rate and channel count arguments (when creating the MP4 recorder) are wrong. They should match that of the Unity audio engine (check AudioSettings).
     
  50. AndreaSpace1

    AndreaSpace1

    Joined:
    Dec 22, 2017
    Posts:
    2
    Hi, I bought the plugin in order to record MP4 videos on Android using the device camera. Testing the NatCorder in an empty project (only NatCorder, Unity WebCamTexture and a bit of UI to start and stop the recording, no audio), on Samsung S3 device:

    - When recording in 1920x1080 30fps no audio, the application crashes after ~7 seconds of recording.
    - When recording in 1280x720 30fps no audio, it crashes after ~30 seconds.
    - Recording at 640x360 30fps seems fine, it went on for about 10 minutes without crashing (after 10 minutes the recording was manually stopped).

    Both crashes produced the same logcat, which is attached in this post. Is there any way to record in 720p / 1080p without it crashing?

    Here the Unity code:

    Code (CSharp):
    1.  
    2. using NatCorder;
    3. using NatCorder.Clocks;
    4. using System;
    5. using UnityEngine;
    6. using UnityEngine.UI;
    7.  
    8. public class SceneController : MonoBehaviour {
    9.  
    10.     public Text FeedbackText;
    11.     public Text VideoPathText;
    12.  
    13.     protected virtual bool IsRecording { get; set; }
    14.    
    15.     protected virtual WebCamTexture WebCamTexture { get; set; }
    16.     protected virtual IClock RecordingClock { get; set; }
    17.     protected virtual IMediaRecorder MediaRecorder { get; set; }
    18.     protected virtual string VideoPath { get; set; }
    19.  
    20.     protected virtual int RecordingResolutionWidth { get; set; }
    21.     protected virtual int RecordingResolutionHeight { get; set; }
    22.  
    23.     void Awake()
    24.     {
    25.         SetRecordingResolution(640, 360);
    26.     }
    27.  
    28.     void LateUpdate ()
    29.     {
    30.         if (IsRecording)
    31.         {
    32.             var renderFrame = MediaRecorder.AcquireFrame();
    33.             Graphics.Blit(WebCamTexture, renderFrame);
    34.             MediaRecorder.CommitFrame(renderFrame, RecordingClock.Timestamp);
    35.         }
    36.     }
    37.  
    38.     public void DidTapOn360()
    39.     {
    40.         SetRecordingResolution(640, 360);
    41.     }
    42.  
    43.     public void DidTapOn480()
    44.     {
    45.         SetRecordingResolution(854, 480);
    46.     }
    47.  
    48.     public void DidTapOn720()
    49.     {
    50.         SetRecordingResolution(1280, 720);
    51.     }
    52.  
    53.     public void DidTapOn1080()
    54.     {
    55.         SetRecordingResolution(1920, 1080);
    56.     }
    57.  
    58.     public void DidTapOnStart()
    59.     {
    60.         Debug.Log($"{nameof(SceneController)}.{nameof(DidTapOnStart)}");
    61.  
    62.         if (!IsRecording)
    63.         {
    64.             try
    65.             {
    66.                 WebCamTexture = new WebCamTexture();
    67.                 WebCamTexture.Play();
    68.  
    69.                 RecordingClock = new RealtimeClock();
    70.  
    71.                 MediaRecorder = new MP4Recorder(RecordingResolutionWidth, RecordingResolutionHeight, 30, 0, 0, OnVideoRecorded);
    72.  
    73.                 IsRecording = true;
    74.             }
    75.             catch (Exception e)
    76.             {
    77.                 Debug.LogError($"{nameof(SceneController)}.{nameof(DidTapOnStart)}: ({e})");
    78.             }
    79.         }
    80.  
    81.         UpdateFeedbackText();
    82.     }
    83.  
    84.     public void DidTapOnStop()
    85.     {
    86.         Debug.Log($"{nameof(SceneController)}.{nameof(DidTapOnStop)}: {nameof(VideoPath)} ({VideoPath})");
    87.  
    88.         if (IsRecording)
    89.         {
    90.             IsRecording = false;
    91.  
    92.             try
    93.             {
    94.                 MediaRecorder.Dispose();
    95.                 MediaRecorder = null;
    96.  
    97.                 RecordingClock = null;
    98.  
    99.                 WebCamTexture.Stop();
    100.                 Destroy(WebCamTexture);
    101.                 WebCamTexture = null;
    102.             }
    103.             catch (Exception e)
    104.             {
    105.                 Debug.LogError($"{nameof(SceneController)}.{nameof(DidTapOnStop)}: ({e})");
    106.             }
    107.         }
    108.  
    109.         UpdateFeedbackText();
    110.     }
    111.  
    112.     protected virtual void SetRecordingResolution(int width, int height)
    113.     {
    114.         if (!IsRecording)
    115.         {
    116.             RecordingResolutionWidth = width;
    117.             RecordingResolutionHeight = height;
    118.         }
    119.     }
    120.  
    121.     protected virtual void OnVideoRecorded(string videoPath)
    122.     {
    123.         Debug.Log($"{nameof(SceneController)}.{nameof(OnVideoRecorded)}");
    124.  
    125.         VideoPath = videoPath;
    126.         VideoPathText.text = VideoPath;
    127.     }
    128.  
    129.     protected virtual void UpdateFeedbackText()
    130.     {
    131.         FeedbackText.text = IsRecording ? $"Recording at {RecordingResolutionWidth}x{RecordingResolutionHeight}" : "Stopped";
    132.     }
    133. }
    134.  
     

    Attached Files: