tauri-plugin-ffmpeg 0.1.0

FFmpeg plugin for Tauri 2: run ffmpeg/ffprobe with progress on desktop/mobile
Documentation
# Tauri Plugin FFmpeg

A cross-platform Tauri plugin for media transcoding using FFmpeg. Supports both desktop (Windows, macOS, Linux) and mobile (Android, iOS) platforms.

## Features

- **Video Transcoding**: Convert videos to MP4 format with hardware acceleration support
- **Audio Transcoding**: Convert audio files to MP3 format
- **Progress Callback**: Real-time transcoding progress updates
- **Cross-Platform**: Works on desktop (exe) and mobile (FFmpegKit)
- **Hardware Acceleration**: Automatically detects and uses hardware encoders when available

## Installation

### Install the Plugin

```bash
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`:

```toml
[dependencies]
tauri-plugin-ffmpeg = { path = "path/to/tauri-plugin-ffmpeg" }
```

### Register the Plugin

In your Tauri application's `main.rs` or `lib.rs`:

```rust
fn main() {
    tauri::Builder::default()
        .plugin(tauri_plugin_ffmpeg::init())
        .run(tauri::generate_context!())
        .expect("error while running tauri application");
}
```

### Permissions

Add the plugin permissions to your `capabilities` configuration:

```json
{
  "permissions": [
    "ffmpeg:default"
  ]
}
```

## Usage

### Basic Example

```typescript
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()
```

### Advanced Usage

```typescript
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
})
```

## API Reference

### `transcode(options: TranscodeOptions): Promise<TranscodeResult>`

Transcode a media file (video or audio).

**Parameters:**
- `options.inputPath` (string): Path to the input file
- `options.outputPath` (string): Path to the output file
- `options.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 updates

**Returns:** `Promise<UnlistenFn>` - Function to stop listening

**Progress Payload:**
- `progress` (number): Progress percentage (0-100), -1 indicates error
- `currentTimeMs` (number, optional): Current processing time in milliseconds
- `totalDurationMs` (number, optional): Total duration in milliseconds

## Platform-Specific Details

### Desktop (Windows, macOS, Linux)

- Uses FFmpeg executable
- Automatically detects hardware encoders:
  - **macOS**: h264_videotoolbox
  - **Windows**: h264_nvenc (NVIDIA), h264_qsv (Intel), h264_amf (AMD)
  - **Linux**: h264_v4l2m2m
  - **Fallback**: libx264 (software encoding)
- Requires FFmpeg to be installed or provided via `ffmpegPath`

### Mobile (Android)

- Uses FFmpegKit library
- Hardware acceleration via h264_mediacodec
- Automatically manages temporary files
- Progress updates via FFmpegKit statistics callback

### Mobile (iOS)

- Uses FFmpegKit library (implementation pending)

## Video Encoding

**Format**: MP4 (H.264 + AAC)
**Encoder Priority** (desktop):
1. h264_videotoolbox (macOS)
2. h264_nvenc (NVIDIA GPU)
3. h264_qsv (Intel Quick Sync)
4. h264_amf (AMD GPU)
5. h264_v4l2m2m (Linux)
6. libx264 (software fallback)

**Mobile**: h264_mediacodec (Android)

## Audio Encoding

**Format**: MP3
**Encoder**: libmp3lame
**Quality**: VBR quality 2 (high quality)

## License

MIT

## Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

## Roadmap

- [x] Windows desktop support
- [x] Android mobile support
- [ ] macOS desktop support (implementation complete, testing pending)
- [ ] Linux desktop support (implementation complete, testing pending)
- [ ] iOS mobile support
- [ ] Custom encoding parameters
- [ ] Multiple output formats
- [ ] Video filters support