| Crates.io | tauri-plugin-ffmpeg |
| lib.rs | tauri-plugin-ffmpeg |
| version | 0.1.0 |
| created_at | 2025-10-29 15:06:45.557902+00 |
| updated_at | 2025-10-29 15:06:45.557902+00 |
| description | FFmpeg plugin for Tauri 2: run ffmpeg/ffprobe with progress on desktop/mobile |
| homepage | |
| repository | |
| max_upload_size | |
| id | 1906773 |
| size | 163,460 |
A cross-platform Tauri plugin for media transcoding using FFmpeg. Supports both desktop (Windows, macOS, Linux) and mobile (Android, iOS) platforms.
npm install tauri-plugin-ffmpeg-api
# or
yarn add tauri-plugin-ffmpeg-api
# or
pnpm add tauri-plugin-ffmpeg-api
Add the plugin to your Cargo.toml:
[dependencies]
tauri-plugin-ffmpeg = { path = "path/to/tauri-plugin-ffmpeg" }
In your Tauri application's main.rs or lib.rs:
fn main() {
tauri::Builder::default()
.plugin(tauri_plugin_ffmpeg::init())
.run(tauri::generate_context!())
.expect("error while running tauri application");
}
Add the plugin permissions to your capabilities configuration:
{
"permissions": [
"ffmpeg:default"
]
}
import { transcodeVideo, transcodeAudio, onProgress } from 'tauri-plugin-ffmpeg-api'
// Listen to progress events
const unlisten = await onProgress((payload) => {
console.log(`Progress: ${payload.progress}%`)
if (payload.currentTimeMs && payload.totalDurationMs) {
const elapsed = (payload.currentTimeMs / 1000).toFixed(1)
const total = (payload.totalDurationMs / 1000).toFixed(1)
console.log(`Time: ${elapsed}s / ${total}s`)
}
})
// Transcode video to MP4
const videoResult = await transcodeVideo(
'/path/to/input.avi',
'/path/to/output.mp4'
)
if (videoResult.success) {
console.log('Video transcoded successfully:', videoResult.outputPath)
} else {
console.error('Video transcode failed:', videoResult.error)
}
// Transcode audio to MP3
const audioResult = await transcodeAudio(
'/path/to/input.wav',
'/path/to/output.mp3'
)
if (audioResult.success) {
console.log('Audio transcoded successfully:', audioResult.outputPath)
} else {
console.error('Audio transcode failed:', audioResult.error)
}
// Clean up listener when done
unlisten()
import { transcode, MediaType, onProgress } from 'tauri-plugin-ffmpeg-api'
// Custom FFmpeg path (desktop only)
const result = await transcode({
inputPath: '/path/to/input.mkv',
outputPath: '/path/to/output.mp4',
mediaType: MediaType.Video,
ffmpegPath: '/custom/path/to/ffmpeg' // optional
})
transcode(options: TranscodeOptions): Promise<TranscodeResult>Transcode a media file (video or audio).
Parameters:
options.inputPath (string): Path to the input fileoptions.outputPath (string): Path to the output fileoptions.mediaType (MediaType): Type of media (MediaType.Video or MediaType.Audio)options.ffmpegPath (string, optional): Custom FFmpeg executable path (desktop only)Returns: Promise<TranscodeResult>
transcodeVideo(inputPath: string, outputPath: string, ffmpegPath?: string): Promise<TranscodeResult>Convenience method to transcode video to MP4 with hardware acceleration.
transcodeAudio(inputPath: string, outputPath: string, ffmpegPath?: string): Promise<TranscodeResult>Convenience method to transcode audio to MP3.
onProgress(handler: (payload: ProgressPayload) => void): Promise<UnlistenFn>Listen to transcoding progress events.
Parameters:
handler: Callback function that receives progress updatesReturns: Promise<UnlistenFn> - Function to stop listening
Progress Payload:
progress (number): Progress percentage (0-100), -1 indicates errorcurrentTimeMs (number, optional): Current processing time in millisecondstotalDurationMs (number, optional): Total duration in millisecondsffmpegPathFormat: MP4 (H.264 + AAC) Encoder Priority (desktop):
Mobile: h264_mediacodec (Android)
Format: MP3 Encoder: libmp3lame Quality: VBR quality 2 (high quality)
MIT
Contributions are welcome! Please feel free to submit a Pull Request.