How to execute ffmpeg binary file within Application.PersistentDataPath after UnityWebRequest?
Hey guys,
My goal is to use a Process to execute ffmpeg on Android. I have built the Android version ffmpeg binary file and tested in Android emulator (Termux), everything works normally.
In my script, I use UnityWebRequest to request ffmpeg (which is stored within "StreamingAssets" folder before building) and store it in the Application.PersistentDataPath. Then I want to execute ffmpeg as a Process and output the available encoders.
Following is the code:
IEnumerator DownloadFile()
{
var url = Path.Combine(Application.streamingAssetsPath, "SPINACH/Media/ffmpeg/Android/ffmpeg");
// https://docs.unity3d.com/Manual/UnityWebRequest-CreatingDownloadHandlers.html
var uwr = new UnityWebRequest(url, UnityWebRequest.kHttpVerbGET);
path = Path.Combine(Application.persistentDataPath, "ffmpeg");
uwr.downloadHandler = new DownloadHandlerFile(path);
yield return uwr.SendWebRequest();
if (uwr.isNetworkError || uwr.isHttpError)
UnityEngine.Debug.LogError(uwr.error);
else
UnityEngine.Debug.Log("File successfully downloaded and saved to " + path);
}
StartCoroutine(DownloadFile());
UnityEngine.Debug.Log(string.Format("ffmpeg file exist?: {0}", File.Exists(path)));
Process _sessionProcess = new Process();
_sessionProcess.StartInfo = new ProcessStartInfo
{
FileName = path,
UseShellExecute = false,
CreateNoWindow = true,
RedirectStandardOutput = true,
RedirectStandardError = true,
Arguments = "--encoders"
};
_sessionProcess.Start();
UnityEngine.Debug.Log(_sessionProcess.StandardOutput.ReadToEnd());
UnityEngine.Debug.Log(_sessionProcess.StandardError.ReadToEnd());
_sessionProcess.WaitForExit();
The picture below is the adb logcat output:
I initially suspect that it is the permission issue of ffmpeg file, then I use 'chmod 777', but it still give me the same 'Native error: Acess Denied' even after using 'chmod'. And ffmpeg fiie is indeed requested and stored in the Application.persistentDataPath. But why I cannot execute ffmpeg file !!!!?????
Is there any other way to execute ffmpeg file as a Process on Android?
Appreciated in advanced
Your answer
![](https://koobas.hobune.stream/wayback/20220613022021im_/https://answers.unity.com/themes/thub/images/avi.jpg)