expo-ffmpeg
v0.0.14
Published
FFmpeg Kit for React Native/Expo with pre-configured binaries and Expo config plugin
Downloads
160
Maintainers
Readme
expo-ffmpeg
FFmpeg Kit for React Native/Expo with pre-configured full-gpl binaries and Expo config plugin.
This is a fork of ffmpeg-kit-react-native with:
- Pre-patched configuration for
full-gplbinaries - Bundled Expo config plugin for automatic setup
- Utility class for common FFmpeg operations
Features
- Includes both
FFmpegandFFprobe - Supports both
AndroidandiOS - FFmpeg
v6.0 - Full GPL license with all codecs enabled
- 25+ external libraries including x264, x265, and more
Installation
yarn add expo-ffmpegExpo Configuration
Add the plugin to your app.json or app.config.js:
{
"expo": {
"plugins": [
[
"expo-ffmpeg",
{
"iosUrl": "https://github.com/Daniel-Griffiths/expo-ffmpeg/releases/download/binaries/ffmpeg-kit-ios-full-gpl.zip",
"androidUrl": "https://github.com/Daniel-Griffiths/expo-ffmpeg/releases/download/binaries/ffmpeg-kit-android-full-gpl.aar"
}
]
]
}
}Then rebuild your app:
npx expo prebuild --cleanUsage
Basic FFmpeg Commands
import { FFmpegKit, ReturnCode } from 'expo-ffmpeg';
// Execute any FFmpeg command
const session = await FFmpegKit.execute('-i input.mp4 -c:v libx264 output.mp4');
const returnCode = await session.getReturnCode();
if (ReturnCode.isSuccess(returnCode)) {
console.log('Success!');
}FFmpeg Utility Class
The package includes a utility class with common operations:
import { FFmpeg } from 'expo-ffmpeg';
// Mux video and audio
const result = await FFmpeg.mux(videoPath, audioPath, outputPath);
// Download HLS stream
const result = await FFmpeg.downloadHls(hlsUrl, outputPath, (progress) => {
console.log(`Progress: ${progress}%`);
});
// Convert video
const result = await FFmpeg.convert(inputPath, outputPath, {
codec: 'libx264',
videoBitrate: '2M',
});
// Extract audio
const result = await FFmpeg.extractAudio(videoPath, audioPath, {
format: 'mp3',
});
// Trim video
const result = await FFmpeg.trim(inputPath, outputPath, '00:00:10', '00:00:30');
// Check if URL is HLS
if (FFmpeg.isHlsUrl(url)) {
// Handle HLS stream
}
// Get temp file path
const tempPath = FFmpeg.getTempPath('video', 'mp4');
// Cleanup files
await FFmpeg.cleanup(tempPath1, tempPath2);Request headers
By default, downloads and probes use the platform's default user agent. On iOS
that string is derived from CFBundleName, so every media server you fetch from
sees your app's name and version. Set headers once at startup to control this:
FFmpeg.setDefaultHeaders({
'User-Agent': 'Mozilla/5.0 (iPhone; CPU iPhone OS 17_0 like Mac OS X) ...',
'Accept-Language': 'en-US,en;q=0.9',
});These apply to downloadFile, downloadHls, probeUrl, and
findAccessibleUrl — including the segment requests FFmpeg itself makes while
downloading an HLS stream. Any call can override them:
await FFmpeg.downloadFile(url, path, onProgress, {
headers: { Authorization: `Bearer ${token}` },
});Credits
Based on ffmpeg-kit by ARTHENICA.
