Skip to content

Using FFmpegKit in Unity

Taner Şener edited this page Mar 13, 2021 · 4 revisions

1. Android

  • Download the latest ffmpeg-kit-<package>-<version>.aar file from the Releases page and copy it under the <Your Unity Project Name>/Assets/Plugins/Android folder.

    • Please note that Main releases support API Level 24 and LTS releases support API Level 16.
  • Disable the handling of SIGXCPU signal by running the following code block.

    AndroidJavaClass configClass = new AndroidJavaClass("com.arthenica.ffmpegkit.FFmpegKitConfig");
    AndroidJavaObject paramVal = new AndroidJavaClass("com.arthenica.ffmpegkit.Signal").GetStatic<AndroidJavaObject>("SIGXCPU");
    configClass.CallStatic("ignoreSignal", new object[] { paramVal });
    
  • Use the following code block to call execute method and run ffmpeg commands.

    AndroidJavaClass javaClass = new AndroidJavaClass("com.arthenica.ffmpegkit.FFmpegKit");
    AndroidJavaObject session = javaClass.CallStatic<AndroidJavaObject>("execute", new object[] {"-version"});
    
    AndroidJavaObject returnCode = session.Call<AndroidJavaObject>("getReturnCode", new object[] {});
    int rc = returnCode.Call<int>("getValue", new object[] {});
    
  • You can call other ffmpeg-kit API methods using a similar approach.

    string output = session.Call<string>("getOutput", new object[] {});
    Debug.Log("Output " + output);
    

2. iOS / tvOS

Unity Cloud Build does support importing Xcode frameworks. So it should be possible to import ffmpeg-kit frameworks using the Xcode frameworks guide. Unfortunately, it is not tested and documented yet.

There are unofficial blogs about using Cocoapods under Unity. If you can make them work then you can import ffmpeg-kit by adding ffmpeg-kit dependency into your Podfile as described in README.

Clone this wiki locally