Skip to content

Commit

Permalink
Merge pull request #1 from chiepomme/osx
Browse files Browse the repository at this point in the history
WebM を経由して ffmpeg で mp4 にすることで osx でも動くようにしてみた
  • Loading branch information
chiepomme authored Jul 22, 2017
2 parents 02dbf3f + a462801 commit 328d864
Show file tree
Hide file tree
Showing 33 changed files with 786 additions and 41 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
/TwitterMVGenerator/
/audio.wav
/background.png
/Movie/
/ffmpeg/
/.vs/

/[Ll]ibrary/
Expand Down
85 changes: 78 additions & 7 deletions Assets/Controller.cs
Original file line number Diff line number Diff line change
@@ -1,42 +1,113 @@
using System.Collections;
using SFB;
using System;
using System.Collections;
using System.Diagnostics;
using System.IO;
using UnityEngine;
using UnityEngine.UI;
using UTJ.FrameCapturer;

public class Controller : MonoBehaviour
{
public static string LastPath { get; set; }

[SerializeField]
MovieRecorder mp4Recorder;
[SerializeField]
MovieRecorder recorder;
MovieRecorder webMRecorder;
[SerializeField]
RawImage image;

bool useWebMInsteadOfMp4;

string rootDirectory;

string GetFilePath(string relativePathFromRoot)
{
if (relativePathFromRoot.StartsWith("./"))
{
relativePathFromRoot = relativePathFromRoot.Substring(2);
}

return new FileInfo(rootDirectory + relativePathFromRoot).FullName.Replace("\\", "/");
}

IEnumerator Start()
{
rootDirectory = Application.dataPath + "/../";

if (Application.platform == RuntimePlatform.OSXEditor || Application.platform == RuntimePlatform.OSXPlayer)
{
useWebMInsteadOfMp4 = true;
}

Screen.SetResolution(512, 512, false);

if (File.Exists("background.png"))
if (Application.platform == RuntimePlatform.OSXPlayer)
{
var imageWWW = new WWW("file://" + Application.dataPath + "/../background.png");
// OSX の場合にはアプリが別のパスに隔離されてしまうので問い合わせが必要
var dir = PlayerPrefs.HasKey("RootDirectory") ? PlayerPrefs.GetString("RootDirectory") : "";
var paths = StandaloneFileBrowser.OpenFilePanel("audio.wav を選択してください", dir, "wav", false);
if (paths.Length == 0)
{
Application.Quit();
yield break;
}

rootDirectory = Uri.UnescapeDataString(Path.GetDirectoryName(paths[0]).Replace("file:", "") + "/");
PlayerPrefs.SetString("RootDirectory", rootDirectory);
}

print("rootDir:" + rootDirectory);

if (File.Exists(GetFilePath("background.png")))
{
print(GetFilePath("background.png"));
var imageWWW = new WWW("file://" + GetFilePath("background.png"));
yield return imageWWW;
image.texture = imageWWW.texture;
}
else if (File.Exists("background.jpg"))
else if (File.Exists(GetFilePath("background.jpg")))
{
var imageWWW = new WWW("file://" + Application.dataPath + "/../background.jpg");
print(GetFilePath("background.jpg"));
var imageWWW = new WWW("file://" + GetFilePath("background.jpg"));
yield return imageWWW;
image.texture = imageWWW.texture;
}

print(GetFilePath("audio.wav"));
var audiosource = gameObject.AddComponent<AudioSource>();
var audioWWW = new WWW("file://" + Application.dataPath + "/../audio.wav");
var audioWWW = new WWW("file://" + GetFilePath("audio.wav"));
yield return audioWWW;
audiosource.clip = audioWWW.GetAudioClip(false);
audiosource.Play();

var recorder = mp4Recorder;

if (useWebMInsteadOfMp4)
{
recorder = webMRecorder;
}

recorder.outputDir = new DataPath(GetFilePath("Movie"));

recorder.BeginRecording();
print(LastPath);
yield return new WaitWhile(() => audiosource.isPlaying);
recorder.EndRecording();

yield return new WaitForSeconds(2f);

if (useWebMInsteadOfMp4)
{
var webmPath = "\"" + LastPath + ".webm" + "\"";
var mp4Path = "\"" + LastPath + ".mp4" + "\"";
var exeExtension = Application.platform == RuntimePlatform.WindowsEditor || Application.platform == RuntimePlatform.WindowsPlayer ? ".exe" : "";
var process = Process.Start(GetFilePath("ffmpeg/ffmpeg" + exeExtension), "-i " + webmPath + " " + mp4Path);
process.WaitForExit();
File.Delete(LastPath + ".webm");
}

Application.Quit();
}
}
9 changes: 9 additions & 0 deletions Assets/Editor.meta

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

29 changes: 29 additions & 0 deletions Assets/Editor/Build.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
using System.Linq;
using UnityEditor;

public static class Build
{
[MenuItem("File/Build For All Platforms")]
public static void BuildForAllPlatforms()
{
var scenes = EditorBuildSettings.scenes.Select(s => s.path).ToArray();

var winOptions = new BuildPlayerOptions()
{
locationPathName = "TwitterMVGenerator/win/TwitterMVGenerator.exe",
target = BuildTarget.StandaloneWindows,
options = BuildOptions.None,
scenes = scenes,
};
BuildPipeline.BuildPlayer(winOptions);

var osxOptions = new BuildPlayerOptions()
{
locationPathName = "TwitterMVGenerator/osx/TwitterMVGenerator.app",
target = BuildTarget.StandaloneOSXIntel64,
options = BuildOptions.None,
scenes = scenes,
};
BuildPipeline.BuildPlayer(osxOptions);
}
}
12 changes: 12 additions & 0 deletions Assets/Editor/Build.cs.meta

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

Binary file modified Assets/Main.unity
Binary file not shown.
9 changes: 9 additions & 0 deletions Assets/StandaloneFileBrowser.meta

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

7 changes: 7 additions & 0 deletions Assets/StandaloneFileBrowser/IStandaloneFileBrowser.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace SFB {
public interface IStandaloneFileBrowser {
string[] OpenFilePanel(string title, string directory, ExtensionFilter[] extensions, bool multiselect);
string[] OpenFolderPanel(string title, string directory, bool multiselect);
string SaveFilePanel(string title, string directory, string defaultName, ExtensionFilter[] extensions);
}
}
12 changes: 12 additions & 0 deletions Assets/StandaloneFileBrowser/IStandaloneFileBrowser.cs.meta

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

21 changes: 21 additions & 0 deletions Assets/StandaloneFileBrowser/LICENSE.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2017 Gökhan Gökçe

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
8 changes: 8 additions & 0 deletions Assets/StandaloneFileBrowser/LICENSE.txt.meta

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

9 changes: 9 additions & 0 deletions Assets/StandaloneFileBrowser/Plugins.meta

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

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

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
@@ -0,0 +1,46 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>BuildMachineOSBuild</key>
<string>16E195</string>
<key>CFBundleDevelopmentRegion</key>
<string>English</string>
<key>CFBundleExecutable</key>
<string>StandaloneFileBrowser</string>
<key>CFBundleIdentifier</key>
<string>com.gkngkc.sfb</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>StandaloneFileBrowser</string>
<key>CFBundlePackageType</key>
<string>BNDL</string>
<key>CFBundleShortVersionString</key>
<string>1.0 </string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleSupportedPlatforms</key>
<array>
<string>MacOSX</string>
</array>
<key>CFBundleVersion</key>
<string>1.0</string>
<key>CSResourcesFileMapped</key>
<true/>
<key>DTCompiler</key>
<string>com.apple.compilers.llvm.clang.1_0</string>
<key>DTPlatformBuild</key>
<string>8E3004b</string>
<key>DTPlatformVersion</key>
<string>GM</string>
<key>DTSDKBuild</key>
<string>16E185</string>
<key>DTSDKName</key>
<string>macosx10.12</string>
<key>DTXcode</key>
<string>0833</string>
<key>DTXcodeBuild</key>
<string>8E3004b</string>
</dict>
</plist>

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

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

Binary file not shown.

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

Loading

0 comments on commit 328d864

Please sign in to comment.