Skip to content

Commit

Permalink
Merge pull request #30 from fuziki/refactor/remove-video-creator
Browse files Browse the repository at this point in the history
Refactor/remove video creator
  • Loading branch information
fuziki authored Jul 28, 2021
2 parents 3ada316 + df195a4 commit 52ca882
Show file tree
Hide file tree
Showing 70 changed files with 300 additions and 599 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ class GameViewController: UIViewController {
}

var link: CADisplayLink?
var vc: UnsafePointer<VideoCreatorUnity>?
var recording: Bool = false
var tmpUrl: NSString?
var sentFirstFrame: Bool = false
Expand Down Expand Up @@ -98,7 +97,8 @@ class GameViewController: UIViewController {
UnityMediaCreator_initAsMovWithNoAudio(tmpUrl?.utf8String,
"h264",
Int64(view.frame.width),
Int64(view.frame.height))
Int64(view.frame.height),
"")
recording = true
link!.isPaused = false
}
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

File renamed without changes.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -1489,22 +1489,13 @@ GameObject:
m_Component:
- component: {fileID: 1015514869}
- component: {fileID: 1015514868}
- component: {fileID: 1015514867}
m_Layer: 0
m_Name: Recording Camera
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!81 &1015514867
AudioListener:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1015514866}
m_Enabled: 1
--- !u!20 &1015514868
Camera:
m_ObjectHideFlags: 0
Expand Down
File renamed without changes.
113 changes: 113 additions & 0 deletions Examples/UnityExample/Assets/VideoCreator/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
# VideoCreator

* iOS Native Plugin to Export Texture and pcm to movie file.
* Support .mov, .wav, Live Photos, .png and .jpeg.

# Usage
## Setup
### Setup MediaCreator for mov file (no audio)
* Set the tmp file location as absolute path.
* "h264" or "hevcWithAlpha"
* If you want to record a video with an alpha channel, you need to specify the "hevcWithAlpha".
* Set video width and height.

```c#
string cachePath = "file://" + Application.temporaryCachePath + "/tmp.mov";
MediaCreator.InitAsMovWithAudio(cachePath, "h264", width, height);
```

### Setup MediaCreator for mov file (with audio)
* In addition to no audio, set the number of channels and sampling rate for audio.

```c#
string cachePath = "file://" + Application.temporaryCachePath + "/tmp.mov";
MediaCreator.InitAsMovWithAudio(cachePath, "h264", texture.width, texture.height, 1, 48_000);
```

### Setup MediaCreator for Live Photos
* In addition to the usual mov, set Content Identifier.

```c#
string uuid = System.Guid.NewGuid().ToString();
string cachePath = "file://" + Application.temporaryCachePath + "/tmp.mov";
MediaCreator.InitAsMovWithAudio(cachePath, "h264", width, height, uuid);
```

### Setup MediaCreator for wav file
* In addition to the number of audio channels and sampling rate, set the Bit Depth.

```c#
string cachePath = "file://" + Application.temporaryCachePath + "/tmp.wav";
MediaCreator.InitAsWav(cachePath, 1, 48000, 32);
```

## Start Recording

* Set a start time in the timeline of the source samples.
* The time unit is microseconds.

```c#
long startTimeOffset = 0;
MediaCreator.Start(startTimeOffset);
```

## Write Texture

* Give a time based on start and any texture.
* The time unit is microseconds.

```c#
Texture texture = Get Texture;
long time = startTimeOffset + Elapsed time from Start;
MediaCreator.WriteVideo(texture, time);
```

## Write Audio PCM

* Give a time based on start and pcm float array.
* The time unit is microseconds.

```c#
float[] pcm = Get PCM float array;
long time = startTimeOffset + Elapsed time from Start;
MediaCreator.WriteAudio(pcm, time);
```

## Finish Recording

* Save recording files synchronously
* This process may take some time.

```c#
MediaCreator.FinishSync();
```

## Save mov to album app (optional)

* If you want to save your recorded videos to an album, you can use MediaSaver to do so.

```c#
MediaSaver.SaveVideo(cachePath);
```

## Save Live Photos to album app

* If you want to save your recorded Live Photos to an album, you can use MediaSaver to do so.
* Set the thumbnail and the same Content Identifier as the video.

```c#
MediaSaver.SaveLivePhotos(texture, uuid, cachePath);
```

## Save Texture to album app

* You can choose the format from "jpeg", "jpg", "heif", and "png".

```c#
MediaSaver.SaveImage(texture, "png");
```

# Demo
* Unity Version: 2020.3.5
* Build for iOS
* Set `Privacy - Photo Library Additions Usage Description` and `Privacy - Photo Library Usage Description`
7 changes: 7 additions & 0 deletions Examples/UnityExample/Assets/VideoCreator/README.md.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,6 @@ typedef unsigned int swift_uint4 __attribute__((__ext_vector_type__(4)));
#if __has_warning("-Watimport-in-framework-header")
#pragma clang diagnostic ignored "-Watimport-in-framework-header"
#endif
@import ObjectiveC;
#endif

#pragma clang diagnostic ignored "-Wproperty-attribute-mismatch"
Expand Down Expand Up @@ -217,20 +216,6 @@ void UnityMediaCreator_writeVideo(void const * _Nullable texturePtr, int64_t mic
void UnityMediaSaver_saveImage(void const * _Nullable texturePtr, char const * _Nullable type);
void UnityMediaSaver_saveLivePhotos(void const * _Nullable texturePtr, char const * _Nullable contentIdentifier, char const * _Nullable url);
void UnityMediaSaver_saveVideo(char const * _Nullable url);

SWIFT_CLASS("_TtC17UnityVideoCreator17VideoCreatorUnity")
@interface VideoCreatorUnity : NSObject
- (nonnull instancetype)init SWIFT_UNAVAILABLE;
+ (nonnull instancetype)new SWIFT_UNAVAILABLE_MSG("-init is unavailable");
@end

void videoCreator_append(VideoCreatorUnity * _Nonnull const * _Nullable creator, void const * _Nullable texturePtr);
void videoCreator_finishRecording(VideoCreatorUnity * _Nonnull const * _Nullable creator);
VideoCreatorUnity * _Nonnull const * _Nonnull videoCreator_init(char const * _Nullable tmpFilePath, BOOL enableAudio, int64_t videoWidth, int64_t videoHeight) SWIFT_WARN_UNUSED_RESULT;
VideoCreatorUnity * _Nonnull const * _Nonnull videoCreator_initWithVideoCodec(char const * _Nullable tmpFilePath, BOOL enableAudio, int64_t videoWidth, int64_t videoHeight, char const * _Nullable videoCodec) SWIFT_WARN_UNUSED_RESULT;
BOOL videoCreator_isRecording(VideoCreatorUnity * _Nonnull const * _Nullable creator) SWIFT_WARN_UNUSED_RESULT;
void videoCreator_release(VideoCreatorUnity * _Nonnull const * _Nullable creator);
void videoCreator_startRecording(VideoCreatorUnity * _Nonnull const * _Nullable creator);
#if __has_attribute(external_source_symbol)
# pragma clang attribute pop
#endif
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading

0 comments on commit 52ca882

Please sign in to comment.