2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

[Unity]Live Photosを作成する

Posted at

Unity の iOS 実機で Live Photos を作成する

  • Unity の RenderTexture から Live Photos を作成する事ができました

リポジトリ

  • リポジトリはこちら

アセットの導入

  • Examples/UnityExample/Assets/Plugin/VideoCreator をコピーしてプロジェクトに取り込みます

Live Photos を作成する

  • Live Photos の実体は mov と jpeg ファイルです
  • それぞれ同一の Content Identifier を設定する必要があります
  • そこで、mov の作成の時に、uuidを生成し渡します
string uuid = System.Guid.NewGuid().ToString();
string cachePath = "file://" + Application.temporaryCachePath + "/tmp.mov";
MediaCreator.InitAsMovWithAudio(cachePath, "h264", width, height, uuid);
  • マイクロ秒で時刻を指定して、録画を開始します
long startTimeOffset = 0;
MediaCreator.Start(startTimeOffset);
  • Texture を動画に書き込みます
  • サンプルでは RenderTexture を利用しています
Texture texture = Get Texture;
long time = startTimeOffset + Elapsed time from Start;
MediaCreator.WriteVideo(texture, time);
  • 書き込みを終了します
  • Live Photos には時間制限があるので注意です
MediaCreator.FinishSync();
  • mov が指定されたパスに保存されているので、サムネイルに使う texture と動画と同じ uuid を指定して Live Photos を保存します
MediaSaver.SaveLivePhotos(texture, uuid, cachePath);

終わりに

  • Unity から見た時にシンプルなインタフェースで、Live Photos を作成させる事ができました
  • Live Photos は時間の制限などありますが、iOS 固有の機能などで活用して行きたいです
2
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?