Skip to content

FFmpegKit SAF Protocol

Taner Sener edited this page Jul 5, 2026 · 2 revisions

ffkitsaf: lets FFmpegKit use Android Storage Access Framework documents in FFmpeg and FFprobe commands. Use it when a user selected a content://... URI with Android's document picker.

This protocol is Android-only.

Android

Read from a selected document:

val inputUrl = FFmpegKitConfig.getSafParameterForRead(context, uri)

FFmpegKit.execute("-i $inputUrl -c:v mpeg4 ${context.cacheDir}/output.mp4")

Write to a selected document:

val outputUrl = FFmpegKitConfig.getSafParameterForWrite(context, uri)

FFmpegKit.execute("-i ${context.cacheDir}/input.mp4 -c:v mpeg4 $outputUrl")

For a custom Android file open mode:

val url = FFmpegKitConfig.getSafParameter(context, uri, "rw")

SAF URLs are single-use by default. To reuse one:

FFmpegKitConfig.setSafUrlsReusable(true)
val url = FFmpegKitConfig.getSafParameterForRead(context, uri)

// Use url in one or more FFmpeg commands.

FFmpegKitConfig.unregisterSafProtocolUrl(url)
FFmpegKitConfig.setSafUrlsReusable(false)

SAF support requires Android API level 19 or newer. On older Android versions, the helper returns an empty URL.

Flutter

Flutter exposes the SAF helpers through FFmpegKitConfig:

final inputUrl = await FFmpegKitConfig.getSafParameterForRead(uriString);
final outputUrl = await FFmpegKitConfig.getSafParameterForWrite(uriString);
final customUrl = await FFmpegKitConfig.getSafParameter(uriString, 'rw');

Use the returned URL in an FFmpeg command:

await FFmpegKit.execute('-i $inputUrl -c:v mpeg4 output.mp4');

These Flutter methods are Android-only. They fail on iOS and macOS.

React Native

React Native exposes the SAF helpers through FFmpegKitConfig:

const inputUrl = await FFmpegKitConfig.getSafParameterForRead(uriString);
const outputUrl = await FFmpegKitConfig.getSafParameterForWrite(uriString);
const customUrl = await FFmpegKitConfig.getSafParameter(uriString, 'rw');

Use the returned URL in an FFmpeg command:

await FFmpegKit.execute(`-i ${inputUrl} -c:v mpeg4 output.mp4`);

These React Native methods are Android-only.

Notes

  • Do not build ffkitsaf: URLs yourself. Use the helper methods.
  • ffkitsaf: URLs represent registered Android document descriptors, not real filesystem paths.
  • Delete, move, and existence-check operations are not supported through this protocol.

Clone this wiki locally