Swiftpack.co - fuziki/VideoCreator as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
See all packages published by fuziki.
fuziki/VideoCreator v0.3.0
Unity iOS Asset to Export Texture and pcm to movie file. Support .mov, .wav, Live Photos, .png, .jpeg and HLS.
⭐️ 25
🕓 21 weeks ago
iOS macOS
.package(url: "https://github.com/fuziki/VideoCreator.git", from: "v0.3.0")

VideoCreator

  • This plugin helps you to implement the recording of wav and mov files in your Unity app.
  • Writing textures creates a video, and writing float arrays creates an audio.
  • You can get support for AVAssetWriter, a powerful framework created by apple.

Example

example

Installation

Features

Export movie file
  • Video
    • Codec
      • h264
      • hevcWithAlpha
    • Source
      • Unity Texture (e.g. RenderTexture, Texture2D, etc)
  • Audio
    • Codec
      • aac
    • Source
      • float array
  • Container
    • mov
    • Live Photos
    • mp4
Export audio file
  • Source
    • float array
  • Container
    • wav
HLS
  • Codec
    • h264
    • hevcWithAlpha
  • Source
    • Unity Texture (e.g. RenderTexture, Texture2D, etc)
  • Audio
    • Codec
      • aac
    • Source
      • float array
  • Manifesto
    • HLS
    • Low-Latency HLS

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.
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.
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.
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.
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.
long startTimeOffset = 0;
MediaCreator.Start(startTimeOffset);

Write Texture

  • Give a time based on start and any texture.
  • The time unit is microseconds.
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.
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.
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.
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.
MediaSaver.SaveLivePhotos(texture, uuid, cachePath);

Save Texture to album app

  • You can choose the format from "jpeg", "jpg", "heif", and "png".
MediaSaver.SaveImage(texture, "png");

Examples

UnityExample

  • Example for Unity
  • Unity Version: 2020.3.5
  • Build for iOS

camera_layout

  • In the scene of the Unity sample project, there are two cameras placed.
  • One is the Main Camera, and the other is the Recording Camera.
  • The video from the main camera is displayed on the screen.
  • Record the video from the recording camera and the audio from the microphone as a .mov file and save it to the Photos app.

NativeExamples

MovExample

  • Export Metal Texture & PCM data to movie file.

HlsExample

  • Stream Metal Texture as HLS.

LivePhotosExample

  • Save Metal Texture & PCM data as Live Photos.

SharedGameView.framework

  • View to screen capture SCNView.

WavExample

  • Export PCM data to wav file.

Build Custom Framework

This is the command to build the UnityVideoCreator.framework.

make framework

Replace the built framework with the existing framework.

Inside Plugin

GitHub

link
Stars: 25
Last commit: 1 week ago
jonrohan Something's broken? Yell at me @ptrpavlik. Praise and feedback (and money) is also welcome.

Release Notes

support hls
22 weeks ago
  • support hls
  • upgrade native example

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics