Search Unity

NatCorder - Video Recording API

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

  1. DanielSuperKing

    DanielSuperKing

    Joined:
    Mar 26, 2019
    Posts:
    11
    Already communicated through email.. but my video flickering issue was resolved by removing the Metal renderer from the list of renderers for the build.
     
    Lanre likes this.
  2. xujiezhige

    xujiezhige

    Joined:
    Apr 7, 2015
    Posts:
    7
    NatCorder 1.61 Unity 2018.3 Android6 crash
     

    Attached Files:

  3. Luciano-Pinna

    Luciano-Pinna

    Joined:
    Jul 29, 2014
    Posts:
    3
    Quick test with newest version of Unity 2019.2.3f1, alas, does not solve Metal color problem, nor the failed to restart properly.
     
  4. Lanre

    Lanre

    Joined:
    Dec 26, 2013
    Posts:
    2,442
    Hm this is weird because we explicitly fixed this JNI error and there haven't been reports of it since. Did you freshly download NatCorder 1.6.1 from the Asset Store before running this test?
     
  5. Lanre

    Lanre

    Joined:
    Dec 26, 2013
    Posts:
    2,442
    I'm going to implement our custom readback solution on macOS instead of relying on Unity's. I'm still working on the editor freezing; it hasn't been fixed yet.
     
  6. jedai747

    jedai747

    Joined:
    Oct 31, 2018
    Posts:
    36
    I use simple scpirt and my video recorging without sound
    Code (CSharp):
    1. clock = new RealtimeClock();
    2.         _videoRecorder = new MP4Recorder(720,1280,30,0,0,OnRecordStop);
    3.         _cameraInput = new CameraInput(_videoRecorder,_clock,Camera.main);
    4.         _audioInput = new AudioInput(_videoRecorder,_clock,Camera.main.GetComponent<AudioListener>());
    Platform - PC, trying build and check on android
    When i start my game(editor), i recording and have mp4 file. I Off my game(editor) and want start again, my editor freez and only go to task manager
     
  7. Lanre

    Lanre

    Joined:
    Dec 26, 2013
    Posts:
    2,442
    Don't create an `AudioInput` if you don't specify a sample rate and channel count. This is undefined behaviour, and can cause a crash.
     
  8. jedai747

    jedai747

    Joined:
    Oct 31, 2018
    Posts:
    36
    if not creating AudioInput, i will have audio recording?? Or you can give me advice me about sample rate and channel count?
     
  9. jedai747

    jedai747

    Joined:
    Oct 31, 2018
    Posts:
    36
    where i can find required sample rate and channel count for my project?
     
  10. Lanre

    Lanre

    Joined:
    Dec 26, 2013
    Posts:
    2,442
    See Unity's AudioSettings class, and how we use it in the ReplayCam example.
     
    jedai747 likes this.
  11. jedai747

    jedai747

    Joined:
    Oct 31, 2018
    Posts:
    36
    somewhere i made mistake. I dont have sound in mp4 file and after restart game my editor freezing forewer
    Code (CSharp):
    1.  _clock = new RealtimeClock();
    2.         _videoRecorder = new MP4Recorder(720,1280,30,AudioSettings.outputSampleRate,(int) AudioSettings.speakerMode,OnRecordStop);
    3.         _cameraInput = new CameraInput(_videoRecorder,_clock,Camera.main);
    4.         _audioInput = new AudioInput(_videoRecorder,_clock,Camera.main.GetComponent<AudioListener>());
    also i tryed that and i also dont have sound, and editor freezing too
    Code (CSharp):
    1.  
    2. _clock = new RealtimeClock();
    3.         _videoRecorder = new MP4Recorder(720,1280,30,0,0,OnRecordStop);
    4.         _cameraInput = new CameraInput(_videoRecorder,_clock,Camera.main);
    5.         //_audioInput = new AudioInput(_videoRecorder,_clock,Camera.main.GetComponent<AudioListener>());
    6.  
     
  12. Lanre

    Lanre

    Joined:
    Dec 26, 2013
    Posts:
    2,442
    The editor freezing is a known issue; I'm still looking for a fix.
     
  13. jedai747

    jedai747

    Joined:
    Oct 31, 2018
    Posts:
    36
    ok, thank you, what about sound in my video?
     
  14. Lanre

    Lanre

    Joined:
    Dec 26, 2013
    Posts:
    2,442
    Is there sound in the game? Your code looks good.
     
  15. jedai747

    jedai747

    Joined:
    Oct 31, 2018
    Posts:
    36
    yes. Now i open empty project, import plugin, and build ReplayCam scene. When i start on device my screen was full white i cant see real world and i made this -> http://prntscr.com/ozobr5 and sound doesn`t exist in video
     
  16. jedai747

    jedai747

    Joined:
    Oct 31, 2018
    Posts:
    36
    if recordMicrophone == true i have sound. If recordMicrophone == false and i have play back audio source i dont have sound in video
     
  17. jedai747

    jedai747

    Joined:
    Oct 31, 2018
    Posts:
    36
  18. sam598

    sam598

    Joined:
    Sep 21, 2014
    Posts:
    49
    I'm really glad to see that support for RenderTextureInput was added back in!

    However I am having a fatal crash on iOS 13.1

    Code (CSharp):
    1. 2019-08-30 12:58:52.436147-0700 arkitapp[1234:123456] NatCorder: Prepared MP4 video encoder at resolution 1280x720@30Hz with average bitrate 5909760 and keyframe interval 3s
    2. 2019-08-30 12:58:52.442397-0700 arkitapp[1234:123456] -[AGXA11FamilyCommandBuffer blitCommandEncoder], line 128: error 'A command encoder is already encoding to this command buffer'
    3. -[AGXA11FamilyCommandBuffer blitCommandEncoder]:128: failed assertion `A command encoder is already encoding to this command buffer'
    If I comment out lines 58 and 59 of RenderTextureInput.cs it works:

    Code (CSharp):
    1. public void CommitFrame (RenderTexture framebuffer) {
    2.             if (Application.platform == RuntimePlatform.Android)
    3.                 CommitAndroid(framebuffer);
    4.             //else if (Application.platform == RuntimePlatform.IPhonePlayer)
    5.             //    CommitiOS(framebuffer);
    6.             else if (SystemInfo.supportsAsyncGPUReadback)
    7.                 CommitAsync(framebuffer);
    8.             else
    9.                 CommitSync(framebuffer);
    10.         }
    But I assume that this is skipping over the new fast iOS feature. Not critical, but would be very nice to have.
     
  19. BaseOfCoding

    BaseOfCoding

    Joined:
    Jul 27, 2018
    Posts:
    5
    With Natcorder and Natmic updated, you can no longer use old code.
    If you're using Unity's built-in recording chords, you'll still hear poor sound quality.
    I want to know how I can re-record using Natcorder and Natmic assets.
     
  20. nsmith1024

    nsmith1024

    Joined:
    Mar 18, 2014
    Posts:
    642
    Hello,

    Im using NatCorder to combine two different videos. By playing both videos one after the other and using NATCORDER to record both playbacks (voice and video) the result is one video which is a combination of both.

    It works except after playing the first video, it takes maybe a second to start playing the second video, during that time NATCORDER is still recording, so the final video ends up with a blank spot between the videos.

    Is there a way to PAUSE the NATCORDER recording after the first video has ended, and then resume recording after the second video starts playing, then end recording after the second has completed.

    So my question is how to make NATCORDER do a pause and resume recording (video and audio). Im using Android and IOS.

    Thanks
     
  21. Lanre

    Lanre

    Joined:
    Dec 26, 2013
    Posts:
    2,442
    If the screen is white, then check the camera permissions. Also, the ReplayCam example will replace whatever clip you have with the microphone clip. Write your own script to record the audio source as-is, instead of using the ReplayCam example since it works differently.
     
  22. Lanre

    Lanre

    Joined:
    Dec 26, 2013
    Posts:
    2,442
    I'll check this out. Thanks for reporting.
     
  23. Lanre

    Lanre

    Joined:
    Dec 26, 2013
    Posts:
    2,442
    What old code are you referring to? The NatMicCorder demo is up to date.
     
    BaseOfCoding likes this.
  24. Lanre

    Lanre

    Joined:
    Dec 26, 2013
    Posts:
    2,442
    See the "Pausing Recording" section of this article.
     
  25. jedai747

    jedai747

    Joined:
    Oct 31, 2018
    Posts:
    36
    I fixed it. But problem with sound issue is still. Do you watch my apk?
     
  26. jedai747

    jedai747

    Joined:
    Oct 31, 2018
    Posts:
    36
    We bougth your assets for recording in our game. We think we can rely on it. Can you check please
     
  27. Lanre

    Lanre

    Joined:
    Dec 26, 2013
    Posts:
    2,442
    I haven't had time to test your APK. Can you describe the sound issue you are facing?
     
  28. jedai747

    jedai747

    Joined:
    Oct 31, 2018
    Posts:
    36
    I made build reply scene, disable mic recording, change Audio source to Play on awake and add audio clip. When i start game i have sound. When i record video, i dont have sound in my video clip. I use your code from sample scene
     
  29. nsmith1024

    nsmith1024

    Joined:
    Mar 18, 2014
    Posts:
    642
    Hello,

    I copied the Replay Example into my own project, and record using the StartRecording/StopRecording function, however when recorded video is played back the video is rotated and plays sideways, do you know how to make it straight?

    I also noticed that in your example video is being recorded from a RawImage, while mine is being recorded from regular texture.

    Also with your example its being played back using HandHeld.PlayFullScreen, while mine is being played back using a differnet player UMP (Universal Movie Player).

    I dont know if any of those are a factor that causes the video to be shown sideways. Seems no matter what i do i cannot fix the problem, i tried rotating/flipping/reversing the texture, but then either the recorded video is rotated/flipped/reversed in some other way, or the playback is rotated/flipped/reversed.

    Thanks
     
    Last edited: Sep 2, 2019
  30. jedai747

    jedai747

    Joined:
    Oct 31, 2018
    Posts:
    36
    did you have sound in your video if microphone is disable??
     
  31. jedai747

    jedai747

    Joined:
    Oct 31, 2018
    Posts:
    36
    I use vuforia, in game my real book has sizes
    upload_2019-9-2_14-39-57.png
    after recording, my in video sizes was changed, squeezed
    upload_2019-9-2_14-40-40.png
    my Code: start recording
    upload_2019-9-2_14-41-26.png
    stop recording.
    upload_2019-9-2_14-41-51.png
    my Phone Samsung A30
     
  32. nsmith1024

    nsmith1024

    Joined:
    Mar 18, 2014
    Posts:
    642
    I used the same code (StartRecording, StopRecording) from the ReplayCam, but i dont really understand what you mean, but seems the resulting recorded video when played back to the same texture it was recorded from is always sideways. I know the player isnt causing it to be sideways becuase i played a test video to the same texture and it plays fine, so i know its not the player that is causing it. So the only other possibilities is the recorder, or the WebCam. I dont think its the webcam because it looks correct while recording (the webcam is displayed live on the texture while recording), so it must be the recorder that is recording sideways for some reason. I tried so many things over several days to a week, but still the problem remains. Maybe be its the shader, or something else i dont know, im just using the standard shader/material on the texture.

    The only difference is that ReplayCam example uses a RawImage, while im using a Texture, dont know if that has anything to do with it.
     
  33. jedai747

    jedai747

    Joined:
    Oct 31, 2018
    Posts:
    36
    maybe you can help me... i have AR ap(vuforia), when my target is found i create game object. Inside this GO i have audio source. In editor\andriod build i have sound in game, but when i record my video, i dont have sound in .mp4 and i also use scripts from ReplayCam
     
  34. nsmith1024

    nsmith1024

    Joined:
    Mar 18, 2014
    Posts:
    642
    I dont know if there is audio because im still trying to get the video to record properly (its recording sideways), but i will check for audio in my next build and let you know if it works.
     
  35. Lanre

    Lanre

    Joined:
    Dec 26, 2013
    Posts:
    2,442
    This is my point. The ReplayCam code will replace your audio clip with the microphone clip and record that. Write your own code to ensure that this doesn't happen.

    EDIT: Can you share your recording code?
     
  36. Lanre

    Lanre

    Joined:
    Dec 26, 2013
    Posts:
    2,442
    Does your project use any plugins that might affect how game cameras are rendered? Can you share a screenshot? You might be seeing WebCamTexture's rotation/flip. We have a script in ReplayCam that rotates the webcamtexture to be upright.
    The example records a game camera. The game camera just happens to be 'looking at' a RawImage.
     
  37. Lanre

    Lanre

    Joined:
    Dec 26, 2013
    Posts:
    2,442
    Apparently Vuforia modifies the game camera, preventing the aspect ratio from being correct. Try to record at a resolution that has the same aspect ratio as the screen:
    Code (CSharp):
    1. width = 1920;
    2. height = (int)((float)Screen.height / Screen.width * width);
     
  38. nsmith1024

    nsmith1024

    Joined:
    Mar 18, 2014
    Posts:
    642
    I tried and the audio does not get recorded! I will try building the example and see if that works
     
  39. nsmith1024

    nsmith1024

    Joined:
    Mar 18, 2014
    Posts:
    642
    Hello,

    I have problem where the recorded video when played back is sideways. Im using the ReplayCam example that records from a RawImage, and sets up the aspect ratio using the AspectRatioFitter component.

    The problem is that recording from a regular texture and not a UI element with a RawImage attached. SO I cant use the AspectRatioFitter since that only works with a canvas, and im not using that im using a regulat old styled texture.

    Do you know how i can get a proper aspect ratio without using AspectRatioFitter. Maybe this is why the recorded video is reversed??

    Thanks
     
  40. BaseOfCoding

    BaseOfCoding

    Joined:
    Jul 27, 2018
    Posts:
    5
    sorry, I found out on Github. I'll try it!
     
  41. jedai747

    jedai747

    Joined:
    Oct 31, 2018
    Posts:
    36
    problems upload_2019-9-3_12-15-35.png
     
  42. thesanketkale

    thesanketkale

    Joined:
    Dec 14, 2016
    Posts:
    16
    Hello Guys,

    After the latest Natcorder update 1.6.1, I am seeing a crash every time I record video with in-game audio in my android device Xiomi Redmi Note 3. The app crashes immediately after StopRecording(). I tried the same app on a different device like Poco f1 and iPhone 5S and it is working fine there. But specifically it is crashing every time on Xiomi Redmi Note 3. My code is as below and records in-game audio and three cameras outputs.

    Code (CSharp):
    1. private CameraInput cameraInput;
    2. private IMediaRecorder videoRecorder;
    3. private IClock recordingClock;
    4. private AudioInput audioInput;
    5. private AudioSource MicrophoneSource;
    6. private AudioListener AudioListenerSource;
    7.  
    8. public Camera MainCamera; //Perspective Camera Depth 0
    9. public Camera UICamera; //Orthographic Camera Depth 2
    10. public Camera BackgroundCamera; //Orthographic Depth -1
    11.  
    12. private void StartRecording()
    13. {
    14.     Debug.Log("Setting up recorder...");
    15.     // Create recording configurations
    16.     var width = Screen.width;
    17.     var height = Screen.height;
    18.     var framerate = 30;
    19.     // Create a recording clock for generating timestamps
    20.     // Start recording
    21.     recordingClock = new RealtimeClock();
    22.     videoRecorder = new MP4Recorder(
    23.         width,
    24.         height,
    25.         framerate,
    26.         AudioSettings.outputSampleRate,
    27.         (int)AudioSettings.speakerMode,
    28.         OnRecordingStopped
    29.     );
    30.     // Create recording inputs
    31.     cameraInput = new CameraInput(videoRecorder, recordingClock, BackgroundCamera, MainCamera, UICamera);
    32.     audioInput = new AudioInput(videoRecorder, recordingClock, AudioListenerSource);
    33. }
    34.  
    35. private void StopRecording() {
    36.     audioInput.Dispose();
    37.     cameraInput.Dispose();
    38.     videoRecorder.Dispose();
    39. }
    The crash logs are attached with this post.

    Note that the recording use to run as expected in the older version of Natcorder asset 1.6, but since the recent update, it crashes in this specific device (and maybe more but I have just tested in the mentioned devices).

    Is anyone else experiencing this? Could you guys make out the reason behind the crash from the logs?
     

    Attached Files:

  43. Lanre

    Lanre

    Joined:
    Dec 26, 2013
    Posts:
    2,442
    You'll need to manually orient your texture before you record it. We do something similar to display the WebCamTexture upright in the example scenes.
     
  44. Lanre

    Lanre

    Joined:
    Dec 26, 2013
    Posts:
    2,442
    Your recording resolution is too high, and your height is an odd number. Try aspect scaling with respect to the height instead of width, and make sure that the numbers you have are even numbers.
     
  45. Lanre

    Lanre

    Joined:
    Dec 26, 2013
    Posts:
    2,442
    Sorry for the late response. Are you able to reproduce this crash if you don't record audio? To test this, pass 0 for sample rate and channel count in the MP4Recorder constructor, and comment out the audio input line.
     
  46. thesanketkale

    thesanketkale

    Joined:
    Dec 14, 2016
    Posts:
    16
    Hi Lanre,

    Yes, without recording in-game audio, the app doesn't crash in the said device and all is working as expected.
     
  47. nigel_unity184

    nigel_unity184

    Joined:
    May 3, 2019
    Posts:
    1
    Lanre, have you found a solution to recordings causing the editor to hang yet? If it helps your investigation, I noticed that a code recompile due to an edited script will also cause it to hang after a video is recorded
     
  48. Bongo_Studios

    Bongo_Studios

    Joined:
    Jan 26, 2019
    Posts:
    21
    Is there any fix yet on the corrupted videos when recording with audio or the editor crashing when recording in it? It's already been multiple weeks since this problems were identified and still there is no response or fix for this, which greatly disturbs the workflow when doing tests and forces us to remove the sharing videos functionality from our game until there is some solution to these issues.
     
  49. jedai747

    jedai747

    Joined:
    Oct 31, 2018
    Posts:
    36
    UI recording in canvas spaсe overlay is it real? in future?
     
    Last edited: Sep 4, 2019
  50. tonyhan

    tonyhan

    Joined:
    Dec 29, 2015
    Posts:
    8
    I have the same problem。