NatCorder - Video Recording API

Great! PM me your email address.

Iā€™ll add you in; simply PM me your email address.

Thatā€™s great. PM me your email address!

Hi,
First of all after natcorder is finished it will be perfect package. You did a great job :smile:
Im writing down my impressions.
I tested the package on ā€œSamsung Note 2ā€.

1- At my first attempt I recorded the video then when I stopped recording it replayed it. And my video is recorded into my folders root. (/storage/emulated0/videoname). I tested it couple of times it was same and fine. But sometimes app crashes with error (timeout while trying to pause unity engine) when I stop recording. The video is still recorded with the name but with a broken video file. See the attached file. This maybe related with some memory issues. This bring us to my second impression :smile:

2- After 10-15 seconds it throws error ā€œNot enough memory left to execute commandā€.
I think the algorithm behind this package is , it captures each frame into a texture then combine them to a video. Simply like a gif generator. If it is like this it may cause some problems on long videos. When this issue happens some glitches occures. For example the cube is rotating glitchy.

2 Likes

Can you email me the full logs from logcat? The Note 2 is a very low-end device, so Iā€™m not too worried. I will look into better optimizing the API for such devices.

Hello, I just buy NatCam Pro and I want to to try your new recording asset in my project. Can you send me beta version?

2 Likes

Great! PM me your email address and Iā€™ll share the beta with you.

I am trying to record a RenderTexture without the performance hit from ReadPixels. This sounds like a great solution, on top of the NatCam Pro camera apis that has already solved the Android Exposure issues we encountered on Google Pixels and LG phones.

1 Like

Sounds great. Iā€™ve shared the beta with you.

Followed the read me about including ffmpeg for use in the editor, on Mac and on PC. Getting the following errors. I noticed that itā€™s putting the mp4 in the main directory, maybe itā€™s the wrong callback location?

Mac OS
Win32Exception: ApplicationName=ā€˜/Users/matt.jones/Documents/projects/truetv/TruTV-ImpracticalJokersApp/Assets/StreamingAssets/NatCorder/darwin/ffmpegā€™, CommandLine=ā€˜-y -f rawvideo -vcodec rawvideo -pixel_format rgb24
-video_size 357x200 -framerate 20 -loglevel warning
-i - -vcodec libx264 -pix_fmt yuv420p
-preset ultrafast recording_2017_12_12_10_22_26_515.mp4ā€™, CurrentDirectory=ā€˜ā€™
System.Diagnostics.Process.Start_noshell (System.Diagnostics.ProcessStartInfo startInfo, System.Diagnostics.Process process)
System.Diagnostics.Process.Start_common (System.Diagnostics.ProcessStartInfo startInfo, System.Diagnostics.Process process)
System.Diagnostics.Process.Start ()
(wrapper remoting-invoke-with-check) System.Diagnostics.Process:Start ()
NatCorderU.Core.Platforms.NatCorderStandalone.StartRecording (Configuration configuration, NatCorderU.Core.SaveCallback saveCallback, IAudioSource audioSource) (at Assets/NatCorder/Plugins/Managed/Platforms/NatCorderStandalone.cs:82)
NatCorderU.Core.NatCorder.StartRecording (Configuration configuration, NatCorderU.Core.SaveCallback saveCallback) (at Assets/NatCorder/Plugins/Managed/NatCorder.cs:47)
TRU.Photobooth.MPCamRender.StartRecording () (at Assets/TRU/Photobooth/Scripts/MPCamRender.cs:175)
TRU.Photobooth.MPCamRender.OnRecButtonClick (System.String recordMode) (at Assets/TRU/Photobooth/Scripts/MPCamRender.cs:247)
TRU.Photobooth.Photobooth.Record () (at Assets/TRU/Photobooth/Scripts/Photobooth.cs:120)
UnityEngine.Events.InvokableCall.Invoke () (at /Users/builduser/buildslave/unity/build/Runtime/Export/UnityEvent.cs:165)
UnityEngine.Events.UnityEvent.Invoke () (at /Users/builduser/buildslave/unity/build/Runtime/Export/UnityEvent_0.cs:58)
UnityEngine.UI.Button.Press () (at /Users/builduser/buildslave/unity/build/Extensions/guisystem/UnityEngine.UI/UI/Core/Button.cs:36)
UnityEngine.UI.Button.OnPointerClick (UnityEngine.EventSystems.PointerEventData eventData) (at /Users/builduser/buildslave/unity/build/Extensions/guisystem/UnityEngine.UI/UI/Core/Button.cs:45)
UnityEngine.EventSystems.ExecuteEvents.Execute (IPointerClickHandler handler, UnityEngine.EventSystems.BaseEventData eventData) (at /Users/builduser/buildslave/unity/build/Extensions/guisystem/UnityEngine.UI/EventSystem/ExecuteEvents.cs:50)
UnityEngine.EventSystems.ExecuteEvents.Execute[IPointerClickHandler] (UnityEngine.GameObject target, UnityEngine.EventSystems.BaseEventData eventData, UnityEngine.EventSystems.EventFunction`1 functor) (at /Users/builduser/buildslave/unity/build/Extensions/guisystem/UnityEngine.UI/EventSystem/ExecuteEvents.cs:261)
UnityEngine.EventSystems.EventSystem:Update()

Windows
Win32Exception: ApplicationName=ā€˜C:/MYFILE/Unity Projects/TruTV-ImpracticalJokersApp/Assets/StreamingAssets/NatCorder/win/ffmpeg.exeā€™, CommandLine=ā€˜-y -f rawvideo -vcodec rawvideo -pixel_format rgb24
-video_size 285x160 -framerate 20 -loglevel warning
-i - -vcodec libx264 -pix_fmt yuv420p
-preset ultrafast recording_2017_12_12_10_24_49_431.mp4ā€™, CurrentDirectory=ā€˜ā€™
System.Diagnostics.Process.Start_noshell (System.Diagnostics.ProcessStartInfo startInfo, System.Diagnostics.Process process)
System.Diagnostics.Process.Start_common (System.Diagnostics.ProcessStartInfo startInfo, System.Diagnostics.Process process)
System.Diagnostics.Process.Start ()
(wrapper remoting-invoke-with-check) System.Diagnostics.Process:Start ()
NatCorderU.Core.Platforms.NatCorderStandalone.StartRecording (Configuration configuration, NatCorderU.Core.SaveCallback saveCallback, IAudioSource audioSource) (at Assets/NatCorder/Plugins/Managed/Platforms/NatCorderStandalone.cs:82)
NatCorderU.Core.NatCorder.StartRecording (Configuration configuration, NatCorderU.Core.SaveCallback saveCallback) (at Assets/NatCorder/Plugins/Managed/NatCorder.cs:47)
TRU.Photobooth.MPCamRender.StartRecording () (at Assets/TRU/Photobooth/Scripts/MPCamRender.cs:176)
TRU.Photobooth.MPCamRender.OnRecButtonClick (System.String recordMode) (at Assets/TRU/Photobooth/Scripts/MPCamRender.cs:250)
TRU.Photobooth.Photobooth.Record () (at Assets/TRU/Photobooth/Scripts/Photobooth.cs:120)
UnityEngine.Events.InvokableCall.Invoke () (at C:/buildslave/unity/build/Runtime/Export/UnityEvent.cs:165)
UnityEngine.Events.UnityEvent.Invoke () (at C:/buildslave/unity/build/Runtime/Export/UnityEvent_0.cs:58)
UnityEngine.UI.Button.Press () (at C:/buildslave/unity/build/Extensions/guisystem/UnityEngine.UI/UI/Core/Button.cs:36)
UnityEngine.UI.Button.OnPointerClick (UnityEngine.EventSystems.PointerEventData eventData) (at C:/buildslave/unity/build/Extensions/guisystem/UnityEngine.UI/UI/Core/Button.cs:45)

NatCorderStandalone.cs
Line 44
return Application.streamingAssetsPath + ā€œ/NatCorder/darwin/ffmpegā€;

Read Me says to put them in here after you download from: GitHub - KeatsPeeks/ffmpeg-static: ffmpeg static binaries for Mac OSX and Linux and Windows

  • Assets/StreamingAssets/NatCorder/darwin if you are running on macOS.
  • Assets/StreamingAssets/NatCorder/win if you are running on Windows.

This is the file path when I followed the read me. Not sure if the x64 directory is igonored.
Assets/StreamingAssets/NatCorder/darwin/x64/ffmpeg

Do not place it in x64. Put the executable for your architecture in win/darwin/linux directly.

1 Like

Got the recording in the Editor working. Next issue, Iā€™m recording a RenderTexture that is capturing the Screen.width and Screen.height. We donā€™t want the recording to include the background. The NatCam feed is 100% width, height is dictated by the device camera. Is there a way to define a top value for recording? And then define the height to be the size of the camera feed in relation to the width of the device? Attached is a screen grab of the result to illustrate the issue.

This has to be handled on your end (when blitting your maskRT). NatCorder simply expects that you blit to an encoding render texture, which it provides. You might want to set the resolution of your recording to the width and height you want, rather than the width and height of the screen.

In the Editor, the mp4 is being rendered to the root folder, not Streaming Assets or Resources. What is the ideal placement of this file? For desktop editor, Android and IOS. I would like to make this consistent for testing purposes. Streaming Assets seems to be the preferred location.

Also, our app will have two render phases. 1. For the OpenCV facemask and props recording. 2. We pass the recording to a sticker scene, so the user can apply stickers. We plan on using ffmpegs watermark functionality for this, to avoid 2 passes of video compression.

So, we have a temporary recording that we want to keep inside of the app, then save the final file to userā€™s assets. I did notice that when we did thisā€¦

Once you have gotten the executable in place, open NatCorderStandalone.cs (in NatCorder>Plugins>Managed>Platforms) and uncomment the FFMPEG_API definition at the top of the file. You should now be all set.

ā€¦ on Android it no longer saved the mp4 in the Videos folder, but at the root of App Storage, found in ā€œMy Files.ā€

Is there a setting we are not seeing? Or is this a file path refinement that needs to be made on the beta?

There isnā€™t necessarily an ideal placement. We canā€™t save videos to StreamingAssets because on some platforms, it is read-only. As a result, we let NatCorder save to a convenient location (at its discretion) and return the path to the client (you). If you want to save the video to a specific location, then you can simply move the video file to such a location immediately you receive the path in the save callback.

Hey @Lanre , Iā€™m working with @upressplay on this issue. It appears there is a bug in the callback response for StartRecording and that ā€œpathā€ is only returning the filename and not the folder path. So we are unable via code to locate where the output file was saved.

Question: You say you are ā€œletting NatCorder save to a convenient locationā€ that seems to be arbitrary based on platform and folder permissions. Since this is a Unity plugin would it not be simpler to use Application.persistentDataPath or Application.temporaryCachePath to get the safe sandboxed location from Unity at least for iOS and Android?

I presume that this is occurring in the editor. Iā€™ll open an issue for it.

Itā€™s not arbitrary; on Android and iOS, it uses file paths provided by the platform APIā€™s. We will look into making NatCorder Android save in the applicationā€™s sandbox, but iOS and Standalone (FFMPEG) already do this.

@Lanre thank you. Iā€™ve looked into it further and it is in fact returning path on Android and Iā€™m able to find and move the file. It looks like in the editor itā€™s just returning a relative path instead of absolute as itā€™s saving to the project root. thanks for looking into it.

1 Like

Beta testing is going very well; so far, NatCorder is stable. Please let me know if you would like to test the second beta. We have added the Sharing API which allows you to get thumbnails of videos (and allows for getting thumbnails from custom times), and to share videos using the native sharing UI.

One last thing: please post any feature requests you have for NatCorder 1.0. Thank you!

How to use NatCam Core API Unitypackage? I donā€™t know well. I wanna set active camera(not device camera) and recording during the play game.