Search Unity

NatCorder - Video Recording API

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

  1. PlasticApps

    PlasticApps

    Joined:
    Mar 4, 2017
    Posts:
    13
    Hi, thankyou, now its cant find "pathToReplay" :))) Sorry for the dumb questions.
     

    Attached Files:

  2. PlasticApps

    PlasticApps

    Joined:
    Mar 4, 2017
    Posts:
    13
    Now my code is:
    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using NatCorderU.Core;
    5. using NatCorderU.Extensions;
    6.  
    7. public class Record : MonoBehaviour
    8. {
    9.     public AudioListener Audio;
    10.  
    11.     void OnClick()
    12.     {
    13.        
    14.         if (Replay.IsRecording)
    15.         {
    16.             Replay.StopRecording();
    17.             Debug.Log("Recording Stoped");
    18.         }
    19.         else
    20.         {
    21.             Replay.StartRecording(Camera.main,Configuration.Screen, OnShare, Audio);
    22.             Debug.Log("Recording Started");
    23.         }
    24.     }
    25.  
    26.     // Invoked by UI when user clicks share button
    27.     void OnShare (string path)
    28.     {
    29.         // Share the replay using the native sharing UI
    30.         Sharing.Share(path);
    31.         Sharing.SaveToCameraRoll(path);
    32.     }
    33. }
    And its works, but recorded files are still in Android/Data/com.mycomp.myapp/Files... How can i move it to /sdcard/myapp ?
     
  3. Lanre

    Lanre

    Joined:
    Dec 26, 2013
    Posts:
    3,971
    I'm glad you could finally get it to work. No worries.
    In your OnShare function, you can move the video to a directory of your choosing using the System.IO.File.Move function.
     
  4. niv_onehamsa

    niv_onehamsa

    Joined:
    Oct 30, 2016
    Posts:
    13
    Hey devs!

    First off, your plugin is so well written (compared to any other video recording plugin i've tried/used) and it actually works consistently which is about ****ing time ;) So thanks for writing this up it was sorely missing in the Unity landscape. (and another 5 start review pending).

    One request though .... if you could somehow optimize StartRecording(), right now it takes a second+ to start recording and that creates and unwanted hiccup (UX wise). I would like to be able to do a 'prepForRecording()' call at a convenient time and then have 'StartRecording()' work instantly - makes sense?

    Other than that - thank you thank you thank you, I was so happy deleting the entire Everyplay folder from my project.
     
  5. Lanre

    Lanre

    Joined:
    Dec 26, 2013
    Posts:
    3,971
    Thank you :D
    Are you recording with microphone audio? And what platform are you experiencing this lag on?
     
  6. UniversalSaransk

    UniversalSaransk

    Joined:
    Jul 5, 2013
    Posts:
    5
    Hello, guys! We have purchased NarCorder and tried it in our app. Android works well, but iOS have some problem - app crashes after 2-3 second of record. We tried demo ReplayCam without other plugins. Logs doesn't give clear information:

    [B]natcordertest[3860:984504] NatCorder Logging: Prepared video track at resolution 1364x1024@30Hz with average bitrate 5909759 and keyframe interval 3s
    WARNING -> applicationDidReceiveMemoryWarning()[/B]
    Message from debugger: Terminated due to memory issue

    Strange detail - memory consumption is just about 60-80mb. We use: Unity 2017.3.0f3 (64bit), iPad Air 1 gen.
    Thank you in advance for your cooperation!
     
  7. Lanre

    Lanre

    Joined:
    Dec 26, 2013
    Posts:
    3,971
    I am not sure why the app crashes with a memory error, but the app memory isn't going up. We have an update scheduled for later this week (version 1.2) that significantly improves recording stability and performance on iOS. I am confident that it would take care of this issue.
     
  8. Lanre

    Lanre

    Joined:
    Dec 26, 2013
    Posts:
    3,971
    Hi all!

    We have decided to make the Sharing API into its own independent API. Don't worry, it's free :)

    NatShare on GitHub

    Make sure to check out the release article.
    ___

    As a result of this, we will be deprecating the Sharing API from NatCorder in the next release, 1.2. More news about 1.2 will be coming in the next few days. We expect to have the new version live by next week.
     
    marcipw likes this.
  9. marcipw

    marcipw

    Joined:
    Apr 18, 2013
    Posts:
    239
    Hey @Lanre, Is there any chance you could post an example of this in action?

    Everything else is running smoothly now and this is the last piece of the puzzle.
     
  10. Lanre

    Lanre

    Joined:
    Dec 26, 2013
    Posts:
    3,971
    Something like this:
    Code (CSharp):
    1. void OnReplay (string path) {
    2.     // Define destination path and file name
    3.     string movePath = "/storage/emulated/0/video.mp4";
    4.     // Move the recording there
    5.     File.Move(path, movePath);
    6.     // Play the recording from its new location
    7.     Handheld.PlayFullScreenMovie(movePath);
    8. }
     
    Last edited: Apr 19, 2018
    marcipw likes this.
  11. marcipw

    marcipw

    Joined:
    Apr 18, 2013
    Posts:
    239
    Yes!
    @Lanre you beauty! That worked perfectly. I had to add a capital 'S' in screen but it has definitely moved it for me so I can now add in the rest of the bits. You have made my day!
     
  12. Lanre

    Lanre

    Joined:
    Dec 26, 2013
    Posts:
    3,971
    You're welcome :D
     
  13. henriqueranj

    henriqueranj

    Joined:
    Feb 18, 2016
    Posts:
    177
    Hello @Lanre ,

    I am currently trying to integrate NatCorder 1.1f1 and NatCam 2.0f1 and there is a class conflict with NatCamU.Dispatch.RenderDispatch being declared in both plugins.

    How should I handle this? The code for these classes is different for NatCorder and NatCam.
     
  14. Lanre

    Lanre

    Joined:
    Dec 26, 2013
    Posts:
    3,971
    I sent you an email for handling this.
     
    henriqueranj likes this.
  15. marcipw

    marcipw

    Joined:
    Apr 18, 2013
    Posts:
    239
    Is this only needed for the Android build? I have not built to iOS yet as I prefer to test on Android first as its a lot quicker.
     
  16. Lanre

    Lanre

    Joined:
    Dec 26, 2013
    Posts:
    3,971
    Yes, this is Android only (because of the path). The process on iOS is the same. If you have some directory you want to move the file to, then use `File.Move`.
     
  17. dustin_red

    dustin_red

    Joined:
    Feb 7, 2018
    Posts:
    46
    I'm building an ARkit app that uses NatCam to record and I'm getting sporadic crashes while recording. I have 3 test devices: iPhone 6s, iPhone 7, and iPhone X. I get zero crashes on the iPhone7, but random crashes while recording on the iPhone 6s and iPhone X. Sometimes a recording works fine, then crashes 30% into the second recording. And sometimes it crashes 50% into the first recording.

    The crash log says something about exceeding wakeups limit? Not sure if its related to NatCam recording or just memory issues.

    Here is a crash log from the iPhone X:

    Code (CSharp):
    1.  
     
  18. FlashyGoblin

    FlashyGoblin

    Joined:
    Apr 1, 2017
    Posts:
    23
    Can this plugin record audio from multiple sources? I need to record video from an iOS device's front facing camera, with audio from the microphone as well as the audio from the Unity scene. Is this possible?

    As a test, I took the ReplayCam scene that came with the plugin. I added audio to the scene, and checked the "Record Microphone Audio" property in the Replay Cam component. The scene audio stops when I start recording.

    Thanks!
     
  19. Lanre

    Lanre

    Joined:
    Dec 26, 2013
    Posts:
    3,971
    I presume you mean NatCorder--just making sure.
    From the logs this is neither a memory or NatCorder issue. If it was a NatCorder issue, then there would be at least one stack frame referring to `libNatCorder.a`. And if it was a memory issue, you wouldn't have a stack trace. I recommend taking this to Apple developer forums.
     
  20. Lanre

    Lanre

    Joined:
    Dec 26, 2013
    Posts:
    3,971
    Yes it is. NatCorder doesn't impose any restrictions or constraints for recording audio. The Replay API that allows for recording from AudioSources or AudioListeners only does so for convenience. All that NatCorder expects is raw PCM data. You might have to do some custom mixing to make sure certain sounds get recorded but not played in the scene (especially for microphone audio). I recommend looking over our audio workflow tutorial.
     
  21. FlashyGoblin

    FlashyGoblin

    Joined:
    Apr 1, 2017
    Posts:
    23
    Thanks! That audio tutorial is nicely worded and makes sense. However I'm not familiar with custom mixing. It would be helpful to have the ReplayCam example show how to also include the game audio as well as the microphone.
     
    DrSharky likes this.
  22. alejobrainz

    alejobrainz

    Joined:
    Sep 10, 2005
    Posts:
    288
    Lanre,

    Are you opening an official Natshare thread? I am wondering if you have planned or think its feasible for us to extend your plugin to have custom action buttons that call in game functions. A simple use case would be. I have a video I want to share OR maybe post in the in game chat. This way a single action sheet is presented to the player, and they choose if sharing externally or within the game. And if they choose the internal action, a method is triggered on the client code to handle it.
     
  23. Lanre

    Lanre

    Joined:
    Dec 26, 2013
    Posts:
    3,971
    Mixing might have been the wrong word. In this case, you'd be muting the audio source that is playing the microphone clip. See AudioRecorder.cs in NatCorder > Plugins > Managed > Replay for how this is done.
     
  24. Lanre

    Lanre

    Joined:
    Dec 26, 2013
    Posts:
    3,971
    Already did.
    I want to make sure I understand correctly. Here's what (I think) your use case is:
    (Unity) User clicks share button > (Native) Sharing UI pops up, user clicks in-game action > (Unity) Handler gets invoked
    If so, then why not just:
    (Unity) User clicks share button > (Unity) Handler gets invoked.
    And in case the user clicked 'external' sharing, then:
    (Unity) User clicks share button > (Native) Sharing UI pops up, user clicks 'external' action

    Basically, there would be no need to first go to the native layer, then go back to Unity. Also, doing this would be much more complicated because the host app would have to be registered with the OS as being able to receive the object that is being shared.
     
  25. sinjimonkey

    sinjimonkey

    Joined:
    Jul 31, 2013
    Posts:
    72
    Hi - I'm having some trouble with this on an Android build. I'm getting a weird behaviour where the recording is 'flickering' between a proper camera render and empty space (the default blue skybox)

    While it is recording it looks fine on the screen, but the recording is showing a flickering. My code is basically the code from the Playback example.

    In case there's some conflict - I am using Vuphoria and the content being rendered is predominantly the background plane (which is a render from the device camera) I get this issue even when that's all there is and I don't have a target rendering.
     
  26. Lanre

    Lanre

    Joined:
    Dec 26, 2013
    Posts:
    3,971
    Can you email me the recorded video, and the logs from logcat? Thanks.
     
    sinjimonkey likes this.
  27. sinjimonkey

    sinjimonkey

    Joined:
    Jul 31, 2013
    Posts:
    72
    Just for the benefit of anyone else - Lanre helped me solve my issue. I was using an outdated version of the code and when I was working around a glitch in my code I had to move the recording script off my camera and I had a RequireComponent(typeof(Camera)) that added a camera to my button.
     
    DrSharky likes this.
  28. Lanre

    Lanre

    Joined:
    Dec 26, 2013
    Posts:
    3,971
    Thank you!
     
  29. sinjimonkey

    sinjimonkey

    Joined:
    Jul 31, 2013
    Posts:
    72
    I'm building this on iOS for my boss to review. Do I need to add any special permissions key for saving videos? I already have Photo Library Additions for screenshots (That was a pain to figure out)

    EDIT: Based on what it's doing on Android it looks like it's just saving to my app directory. Would you mind sharing instructions on how to move them over to the camera roll as well as the correct permissions key on iOS?

    Yeah .. I just didn't want someone seeing this and thinking it went unresolved. It did get resolved. I intend to rate you highly on the Asset Store when I get a chance.
     
    Last edited: Apr 21, 2018
    Lanre likes this.
  30. Lanre

    Lanre

    Joined:
    Dec 26, 2013
    Posts:
    3,971
    You can't 'move' the video to the camera roll, as there is no publicly accessible camera roll directory. Instead, download the NatShare API and use the SaveToCameraRoll function. NatShare will automatically add the `NSPhotoLibraryUsageDescription` key to your Info.plist.
     
    sinjimonkey likes this.
  31. sinjimonkey

    sinjimonkey

    Joined:
    Jul 31, 2013
    Posts:
    72
    Awesome. I was vaguely aware of NatShare (Saw it mentioned in the docs and elsewhere in this thread). My boss was wanting me to implement social media integration - can it do that too or do I need another solution?
     
  32. Lanre

    Lanre

    Joined:
    Dec 26, 2013
    Posts:
    3,971
    Social media integration is pretty broad. What functionality exactly? Also, let's move this specific conversation to the NatShare thread.
     
    sinjimonkey likes this.
  33. UniversalSaransk

    UniversalSaransk

    Joined:
    Jul 5, 2013
    Posts:
    5
    Hello! I've updated plugin in project to version 1.2f1. What has been changed? Unity shows only some sample scenes. Problem is still there.
    But I noticed something - if I stop record before crash - then everything works correctly. Also on the first attempt record is a little laggy, on next attempts - smooth and perfect.
     
  34. buckUnity

    buckUnity

    Joined:
    Apr 23, 2018
    Posts:
    10
    Hi, I'm trying to upgrade the project to version 1.2f1 but there is no change to the plugin when I try to import it in. I deleted the plugin and reimported and in the change log it says that the version is at 1.1f1.
     
  35. sinjimonkey

    sinjimonkey

    Joined:
    Jul 31, 2013
    Posts:
    72
    I'm showing 1.1f1 as well (but it seems to work for me)
     
  36. dattb1408

    dattb1408

    Joined:
    Aug 17, 2015
    Posts:
    1
    to buy and use, video recording ok, but i can't recording audio. help me
     
  37. dkkk_stonypark

    dkkk_stonypark

    Joined:
    Mar 15, 2017
    Posts:
    2
    hi~
    I will buy your NatCorder product. Is it available in the Unity 5.xxx version?
     
  38. marcipw

    marcipw

    Joined:
    Apr 18, 2013
    Posts:
    239
    Hey @Lanre, Does Natshare do an auto refresh on the android gallery? I managed to move the images using the code you gave me last week but the images only show up when the phone is switched off and on again.
     
  39. alan_motionlab

    alan_motionlab

    Joined:
    Nov 27, 2014
    Posts:
    99
    Hi,

    I've updated to the 1.2, but I'm getting division by zero error when trying to record using the Replay in Windows editor 2017.4.1f1. Not tried on device yet. I'm using the Configuration.Screen as my set up, targeting 60fps. It seems to fail in the OnRenderImage on the if statement:

    Code (csharp):
    1. if (IsRecording && !IsPaused && UnityEngine.Time.frameCount % frameSkip == 0) {
    Anything I can do, or will I have to revert for now?
     
  40. Lanre

    Lanre

    Joined:
    Dec 26, 2013
    Posts:
    3,971
    Delete NatCorder from your project then try reimporting it.
    Make sure that you are getting the updated libraries. If deleting and reimporting doesn't work, then email me and we'll go on from there.
     
  41. Lanre

    Lanre

    Joined:
    Dec 26, 2013
    Posts:
    3,971
    This might be a problem with Unity's servers. On the Asset Store (in a web browser), can you confirm what the current version is 1.2? If so, then is it also 1.2 in the Unity Editor?
     
  42. Lanre

    Lanre

    Joined:
    Dec 26, 2013
    Posts:
    3,971
    If it says 1.1, then you need to update. Did you delete NatCorder from your project before updating?
     
  43. Lanre

    Lanre

    Joined:
    Dec 26, 2013
    Posts:
    3,971
    Can you share some code?
     
  44. Lanre

    Lanre

    Joined:
    Dec 26, 2013
    Posts:
    3,971
    NatCorder supports Unity 5.3 and newer. The reason why the Asset Store says 2017.3 is because that was the version of Unity that was used to upload the package.
     
  45. Lanre

    Lanre

    Joined:
    Dec 26, 2013
    Posts:
    3,971
    I don't know that an 'auto-refresh' can be triggered. If the images don't show in the gallery until the device is rebooted, then open an issue on GitHub or post on the NatShare forum thread. We want to keep discussions about NatCorder and NatShare separate.
     
  46. Lanre

    Lanre

    Joined:
    Dec 26, 2013
    Posts:
    3,971
    You can remove the last condition:
    Code (CSharp):
    1. if (IsRecording && !IsPaused) {
    But this is only a workaround. When you call StartRecording, can you log Application.targetFramerate and Configuration.Screen, and tell me what is logged? Thanks.
     
  47. alan_motionlab

    alan_motionlab

    Joined:
    Nov 27, 2014
    Posts:
    99
    @Lanre - done a bit more digging - it seems there is a shader missing? The Hidden/Natcorder/AspectFitter doesn't seem to be included anywhere in the package
     
  48. alan_motionlab

    alan_motionlab

    Joined:
    Nov 27, 2014
    Posts:
    99
    I removed the load and it doesn't throw the divide by zero exception anymore, but it fails on the Graphics.Blit() as the aspectFitter is null, which makes sense. but the shader seems to be missing for sure
     
  49. Lanre

    Lanre

    Joined:
    Dec 26, 2013
    Posts:
    3,971
    Can you confirm your version of NatCorder? The shader should be in NatCorder > Resources, along with the Transform shader. If not, then delete and reimport NatCorder. Also, let me know what the target framerate and Configuration.Screen are. Removing that check is only a temporary workaround, not a fix.
     
  50. alan_motionlab

    alan_motionlab

    Joined:
    Nov 27, 2014
    Posts:
    99
    Just to follow up once again - removing all references to the aspectFitter, it works correctly again.