@fuzigiwa2 (義将 藤極)

Are you sure you want to delete the question?

Leaving a resolved question undeleted may help others!

OSX向けUnityアプリよりffmpegが呼び出せない

Unityで開発しております。

OSX向けアプリにffmpegを組み込みたく思い、MAC用のバイナリファイルをダウンロードしてStreamingAssetsに配置しました。
そこで以下のようなコードで呼び出しをしました。

private IEnumerator ffmpeg( string a_path )
{
    input   = "\'"+a_path+"\'";
    output  = "\'"+UnityEngine.Application.persistentDataPath + "/work/"+"hoge.mp4"+"\'";

    string ffmpegExePath = Application.streamingAssetsPath + "/KirinUtil/ffmpeg_mac/ffmpeg";
    Process process = new Process();

    string option = "-i";
    option += " "+input;
    option += " -vf";
    option += " scale=480:270";
    option += " -an";
    option += " -preset veryfast";
    option += " -tune film";
    option += " -crf 23";
    option += " -threads 2";
    option += " "+output;

    var info = new ProcessStartInfo(ffmpegExePath, option);
    info.CreateNoWindow = true;
    info.UseShellExecute = false;
    info.RedirectStandardError = true;
    info.RedirectStandardOutput = true;
    process.StartInfo = info;

    // イベント登録
    process.EnableRaisingEvents = true;
    process.ErrorDataReceived += new DataReceivedEventHandler(ProcessErrorDataReceived);
    process.OutputDataReceived += new DataReceivedEventHandler(ProcessOutputDataReceived);
    process.Exited += new EventHandler(ProcessExited);

    // 実行+Output読み取り
    process.Start();
    process.BeginOutputReadLine();
    process.BeginErrorReadLine();
}

こちらの方法ではエラーが出て呼び出しもできず、ターミナルに直接入力しても「ffmpeg」が認識されませんでした。
そこでPCにffmpegをインストールし、ターミナルで起動することを確認してから、

private IEnumerator ffmpeg( string a_path )
{
    input   = "\'"+a_path+"\'";
    output  = "\'"+UnityEngine.Application.persistentDataPath + "/work/"+"hoge.mp4"+"\'";

    string ffmpegExePath = "ffmpeg ";
    Process process = new Process();


    string option = "-i";
    option += " "+input;
    option += " -vf";
    option += " scale=480:270";
    option += " -an";
    option += " -preset veryfast";
    option += " -tune film";
    option += " -crf 23";
    option += " -threads 2";
    option += " "+output;

    string l_cmd = ffmpegExePath + option;

    process.StartInfo.FileName = "/bin/bash";
    process.StartInfo.Arguments = "-c \" " + l_cmd + " \"";
    process.StartInfo.CreateNoWindow = true;
    process.StartInfo.UseShellExecute = false;
    process.StartInfo.RedirectStandardError = true;
    process.StartInfo.RedirectStandardOutput = true;

    process.EnableRaisingEvents = true;
    process.ErrorDataReceived += new DataReceivedEventHandler(ProcessErrorDataReceived);
    process.OutputDataReceived += new DataReceivedEventHandler(ProcessOutputDataReceived);
    process.Exited += new EventHandler(ProcessExited);

    process.Start();
    process.BeginOutputReadLine();
    process.BeginErrorReadLine();
}

というように変更したのですが「ffmpeg」をコマンドとして認識しておらず、呼び出すことに失敗しております。

1.OSX用でPCにffmpegをインストールせずに呼び出す方法はないのでしょうか。
2.インストールしたffmpegを呼び出す方法はどのようにすればよいのでしょうか。

Unity 2020.3.1f1を使用しております。

よろしくお願い致します。

0 likes

No Answers yet.

Your answer might help someone💌