-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Cannot get executeSync working under Unity for Android app #1128
Description
ffmpeg-kit-min:6.0-2.LTS
Unity 6
The apk is built Ok. The command like '-version' using 'execute' method works fine. But when I try to encode video using 'executeAsync' it fails.
Please help!
Logcat:
2025.03.22 23:22:43.316 7573 7677 Error Unity at com.unity3d.player.ReflectionHelper.getMethodID(SourceFile:0)
2025.03.22 23:22:43.316 7573 7677 Error Unity at UnityEngine._AndroidJNIHelper.GetMethodID (System.IntPtr jclass, System.String methodName, System.String signature, System.Boolean isStatic) [0x00000] in <00000000000000000000000000000000>:0
2025.03.22 23:22:43.316 7573 7677 Error Unity at UnityEngine.AndroidJavaObject._CallStatic (System.String methodName, System.Object[] args) [0x00000] in <00000000000000000000000000000000>:0
2025.03.22 23:22:43.316 7573 7677 Error Unity at UnityEngine.Events.UnityEvent.Invoke () [0x00000] in <000
C# code:
void RunFFmpegCommandAsync(string command)
{
using (AndroidJavaClass configClass = new AndroidJavaClass("com.arthenica.ffmpegkit.FFmpegKitConfig")){
AndroidJavaObject paramVal = new AndroidJavaClass("com.arthenica.ffmpegkit.Signal").GetStatic("SIGXCPU");
configClass.CallStatic("ignoreSignal", new object[] { paramVal });
using (AndroidJavaClass ffmpeg = new AndroidJavaClass("com.arthenica.ffmpegkit.FFmpegKit"))
{
FFmpegSessionCompleteCallback callback = new FFmpegSessionCompleteCallback();
ffmpeg.CallStatic("executeAsync", new object[] { command, callback });
}
}
}
class FFmpegSessionCompleteCallback : AndroidJavaProxy
{
public FFmpegSessionCompleteCallback() : base("com.arthenica.ffmpegkit.FFmpegSessionCompleteCallback") { }
void apply(AndroidJavaObject session)
{
string returnCode = session.Call<AndroidJavaObject>("getReturnCode").Call<string>("toString");
string failStackTrace = session.Call<string>("getFailStackTrace");
Debug.Log($"FFmpeg session completed. Return Code: {returnCode}");
if (!string.IsNullOrEmpty(failStackTrace))
{
Debug.LogError($"Error: {failStackTrace}");
}
}
}