Skip to content

Commit 8ff15b8

Browse files
committed
v1.7.0
Updated NatCorder version to 1.7.0. Updated OpenCVForUnity version to 2.3.8.
1 parent b3e6214 commit 8ff15b8

File tree

5 files changed

+39
-57
lines changed

5 files changed

+39
-57
lines changed

Assets/NatCorderWithOpenCVForUnityExample/NatCorderWithOpenCVForUnityExample.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ public class NatCorderWithOpenCVForUnityExample : MonoBehaviour
99
{
1010
public static string GetNatCorderVersion()
1111
{
12-
return "1.6.6";
12+
return "1.7.0";
1313
}
1414

1515
public Text exampleTitle;

Assets/NatCorderWithOpenCVForUnityExample/VideoRecordingExample/ComicFilter.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
using OpenCVForUnity.CoreModule;
22
using OpenCVForUnity.ImgprocModule;
3-
using OpenCVForUnity.UnityUtils;
3+
using OpenCVForUnity.UtilsModule;
44
using System;
55

66
namespace NatCorderWithOpenCVForUnityExample
@@ -37,7 +37,7 @@ public ComicFilter(int blackThresh = 60, int grayThresh = 120, int thickness = 5
3737
if (blackThresh <= i && i < grayThresh)
3838
lutArray[i] = 255;
3939
}
40-
Utils.copyToMat(lutArray, grayLUT);
40+
MatUtils.copyToMat(lutArray, grayLUT);
4141

4242
if (drawMainLine)
4343
{
@@ -57,7 +57,7 @@ public ComicFilter(int blackThresh = 60, int grayThresh = 120, int thickness = 5
5757
contrastAdjustmentsLUTArray[i] = (a > byte.MaxValue) ? (byte)255 : (byte)a;
5858

5959
}
60-
Utils.copyToMat(contrastAdjustmentsLUTArray, contrastAdjustmentsLUT);
60+
MatUtils.copyToMat(contrastAdjustmentsLUTArray, contrastAdjustmentsLUT);
6161
}
6262
}
6363

Assets/NatCorderWithOpenCVForUnityExample/VideoRecordingExample/VideoRecordingExample.cs

Lines changed: 33 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,7 @@ void Update()
315315
// Record frames
316316
if (videoRecorder != null && isVideoRecording && frameCount++ % recordEveryNthFrame == 0)
317317
{
318-
videoRecorder.CommitFrame((IntPtr)rgbaMat.dataAddr(), recordingClock.Timestamp);
318+
videoRecorder.CommitFrame((IntPtr)rgbaMat.dataAddr(), recordingClock.timestamp);
319319
}
320320
}
321321

@@ -353,8 +353,7 @@ private void StartRecording()
353353
recordingHeight,
354354
videoFramerate,
355355
audioSampleRate,
356-
audioChannelCount,
357-
OnVideo
356+
audioChannelCount
358357
);
359358
recordEveryNthFrame = 1;
360359
}
@@ -365,8 +364,7 @@ private void StartRecording()
365364
recordingHeight,
366365
videoFramerate,
367366
audioSampleRate,
368-
audioChannelCount,
369-
OnVideo
367+
audioChannelCount
370368
);
371369
recordEveryNthFrame = 1;
372370
}
@@ -375,17 +373,15 @@ private void StartRecording()
375373
videoRecorder = new GIFRecorder(
376374
recordingWidth,
377375
recordingHeight,
378-
frameDuration,
379-
OnVideo
376+
frameDuration
380377
);
381378
recordEveryNthFrame = 5;
382379
}
383380
else if (container == ContainerPreset.JPG) // macOS and Windows platform only.
384381
{
385382
videoRecorder = new JPGRecorder(
386383
recordingWidth,
387-
recordingHeight,
388-
OnVideo
384+
recordingHeight
389385
);
390386
recordEveryNthFrame = 5;
391387
}
@@ -411,24 +407,25 @@ private void StartRecording()
411407

412408
private void StartMicrophone()
413409
{
414-
#if !UNITY_WEBGL || UNITY_EDITOR // No `Microphone` API on WebGL :(
415410
// Create a microphone clip
416-
microphoneSource.clip = Microphone.Start(null, true, (int)MAX_RECORDING_TIME, (int)microphoneFrequency);
417-
while (Microphone.GetPosition(null) <= 0)
418-
;
419-
// Play through audio source
420-
microphoneSource.timeSamples = Microphone.GetPosition(null);
421411
microphoneSource.loop = true;
412+
microphoneSource.bypassEffects =
413+
microphoneSource.bypassListenerEffects = false;
414+
microphoneSource.clip = Microphone.Start(null, true, (int)MAX_RECORDING_TIME, (int)microphoneFrequency);
415+
while (Microphone.GetPosition(null) <= 0) { }
422416
microphoneSource.Play();
423-
#endif
424417
}
425418

426-
private void StopRecording()
419+
private async void StopRecording()
427420
{
428421
if (!isVideoRecording)
429422
return;
430423

424+
isVideoRecording = false;
425+
431426
Debug.Log("StopRecording ()");
427+
428+
StopCoroutine("Countdown");
432429
if (fpsMonitor != null)
433430
{
434431
fpsMonitor.consoleText = "";
@@ -442,22 +439,28 @@ private void StopRecording()
442439
}
443440

444441
// Stop recording
445-
videoRecorder.Dispose();
446-
447-
StopCoroutine("Countdown");
442+
try
443+
{
444+
var path = await videoRecorder.FinishWriting();
445+
videoPath = path;
446+
Debug.Log("Saved recording to: " + videoPath);
447+
savePathInputField.text = videoPath;
448+
}
449+
catch (Exception e)
450+
{
451+
Debug.Log(e.Message);
452+
savePathInputField.text = e.Message;
453+
}
448454

449455
ShowAllVideoUI();
450456
recordVideoButton.GetComponentInChildren<UnityEngine.UI.Text>().color = Color.black;
451-
452-
isVideoRecording = false;
453457
}
454458

455459
private void StopMicrophone()
456460
{
457-
#if !UNITY_WEBGL || UNITY_EDITOR
458-
Microphone.End(null);
461+
// Stop microphone
459462
microphoneSource.Stop();
460-
#endif
463+
Microphone.End(null);
461464
}
462465

463466
private IEnumerator Countdown()
@@ -482,15 +485,6 @@ private IEnumerator Countdown()
482485
StopRecording();
483486
}
484487

485-
private void OnVideo(string path)
486-
{
487-
Debug.Log("Saved recording to: " + path);
488-
489-
videoPath = path;
490-
491-
savePathInputField.text = videoPath;
492-
}
493-
494488
private void PlayVideo(string path)
495489
{
496490
if (isVideoPlaying || isVideoRecording || string.IsNullOrEmpty(path))
@@ -682,12 +676,6 @@ public void OnContainerDropdownValueChanged(int result)
682676
{
683677
container = (ContainerPreset)(result);
684678
}
685-
686-
#if UNITY_WEBGL && !UNITY_EDITOR
687-
// WebGL platform only supports MP4 format.
688-
containerDropdown.value = (int)ContainerPreset.MP4;
689-
container = ContainerPreset.MP4;
690-
#endif
691679
}
692680

693681
/// <summary>
@@ -768,13 +756,8 @@ public void OnPlayVideoButtonClick()
768756
}
769757

770758
// Playback the video
771-
#if UNITY_IOS
772-
PlayVideo("file://" + videoPath);
773-
#elif UNITY_WEBGL
774-
Debug.Log("Please open the video URL (" + videoPath + ") in a new browser tab.");
775-
#else
776-
PlayVideo(videoPath);
777-
#endif
759+
var prefix = Application.platform == RuntimePlatform.IPhonePlayer ? "file://" : "";
760+
PlayVideo(prefix + videoPath);
778761
}
779762

780763
/// <summary>
@@ -790,10 +773,9 @@ public void OnPlayVideoFullScreenButtonClick()
790773
// Playback the video
791774
#if UNITY_EDITOR
792775
UnityEditor.EditorUtility.OpenWithDefaultApp(videoPath);
793-
#elif UNITY_IOS
794-
Handheld.PlayFullScreenMovie("file://" + videoPath);
795-
#elif UNITY_ANDROID
796-
Handheld.PlayFullScreenMovie(videoPath);
776+
#elif UNITY_ANDROID || UNITY_IOS
777+
var prefix = Application.platform == RuntimePlatform.IPhonePlayer ? "file://" : "";
778+
Handheld.PlayFullScreenMovie(prefix + videoPath);
797779
#else
798780
Debug.LogWarning("Full-screen video playback is not supported on this platform.");
799781
#endif

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@
88
* Anddroid (Pixel) / iOS (iPhone8, iPhone6s)
99
* Unity >= 2018.3+ (Unity 2019.2 or higher is recommended due to [the Unity issue](https://issuetracker.unity3d.com/issues/android-video-player-cannot-play-files-located-in-the-persistent-data-directory-on-android-10?_ga=2.235187912.870386860.1577555830-195736471.1541757609))
1010
* Scripting backend MONO / IL2CPP
11-
* [NatCorder - Video Recording API](https://assetstore.unity.com/packages/tools/integration/natcorder-video-recording-api-102645?aid=1011l4ehR) 1.6.6+
11+
* [NatCorder - Video Recording API](https://assetstore.unity.com/packages/tools/integration/natcorder-video-recording-api-102645?aid=1011l4ehR) 1.7.0+
1212
* [NatShare - Mobile Sharing API](https://assetstore.unity.com/packages/tools/integration/natshare-mobile-sharing-api-117705?aid=1011l4ehR) 1.2.1+
13-
* [OpenCV for Unity](https://assetstore.unity.com/packages/tools/integration/opencv-for-unity-21088?aid=1011l4ehR) 2.3.7+
13+
* [OpenCV for Unity](https://assetstore.unity.com/packages/tools/integration/opencv-for-unity-21088?aid=1011l4ehR) 2.3.8+
1414

1515

1616
## Demo

0 commit comments

Comments
 (0)