queue_conversion
Queues a new media conversion task. The task is validated, then added to the conversion queue and will start when a worker slot becomes available.
Signature
pub async fn queue_conversion(
app: AppHandle,
manager: tauri::State<'_, ConversionManager>,
id: String,
file_path: String,
output_name: Option<String>,
config: ConversionConfig,
) -> Result<(), ConversionError>
Parameters
Unique identifier for this conversion task. Used to track progress and control the task.
Absolute path to the input media file. File must exist and be readable.
Custom output filename (without extension). If null, defaults to {input}_converted.{container}.The output file is placed in the same directory as the input file.
Comprehensive conversion configuration object.
ConversionConfig Type
interface ConversionConfig {
// Processing mode
processingMode: 'reencode' | 'copy'; // Default: 'reencode'
// Output format
container: string; // e.g., 'mp4', 'mkv', 'webm', 'mov', 'gif'
// Video encoding
videoCodec: string; // e.g., 'libx264', 'libx265', 'h264_nvenc'
videoBitrateMode: string; // 'crf' or 'bitrate'
videoBitrate: string; // Bitrate in kbps (when mode is 'bitrate')
crf: number; // 0-51, lower = better quality
quality: number; // 0-100, Default: 50
preset: string; // e.g., 'slow', 'medium', 'fast'
// Audio encoding
audioCodec: string; // e.g., 'aac', 'mp3', 'opus'
audioBitrate: string; // e.g., '192k'
audioChannels: string; // e.g., 'stereo', 'mono'
audioVolume: number; // 0-200, Default: 100.0
audioNormalize: boolean; // Default: false
// Stream selection
selectedAudioTracks: number[]; // Stream indices
selectedSubtitleTracks: number[]; // Stream indices
subtitleBurnPath: string | null; // Path to subtitle file to burn in
// Video processing
resolution: string; // 'original', '1920x1080', 'custom', etc.
customWidth?: string; // When resolution is 'custom'
customHeight?: string; // When resolution is 'custom'
scalingAlgorithm: string; // 'bicubic', 'lanczos', 'bilinear'
fps: string; // 'original', '24', '30', '60'
// Trimming
startTime: string | null; // e.g., '00:01:30'
endTime: string | null; // e.g., '00:05:00'
// Metadata
metadata: {
mode: 'preserve' | 'clean' | 'replace'; // Default: 'preserve'
title?: string;
artist?: string;
album?: string;
genre?: string;
date?: string;
comment?: string;
};
// Transformations
rotation: string; // '0', '90', '180', '270', Default: '0'
flipHorizontal: boolean; // Default: false
flipVertical: boolean; // Default: false
crop?: {
enabled: boolean;
x: number;
y: number;
width: number;
height: number;
sourceWidth?: number;
sourceHeight?: number;
aspectRatio?: string;
};
// ML upscaling
mlUpscale: string | null; // 'none', 'esrgan-2x', 'esrgan-4x'
// Hardware acceleration
hwDecode: boolean; // Default: false
// NVENC options
nvencSpatialAq: boolean; // Default: false
nvencTemporalAq: boolean; // Default: false
// VideoToolbox options
videotoolboxAllowSw: boolean; // Default: false
// GIF options (when container is 'gif')
gifColors: number; // 2-256, Default: 256
gifDither: string; // 'none', 'bayer', 'floyd_steinberg', 'sierra2_4a'
gifLoop: number; // 0 = infinite, Default: 0
}
Validation
The command performs extensive validation (args.rs:419-670):
- File existence and accessibility
- Processing mode compatibility
- Time range validity (start < end)
- Resolution and dimension constraints
- Codec-container compatibility
- Stream copy mode restrictions
- ML upscale mode validation
- GIF-specific parameter validation
Example
import { invoke } from '@tauri-apps/api/core';
try {
await invoke('queue_conversion', {
id: crypto.randomUUID(),
filePath: '/Users/name/video.mp4',
outputName: 'output',
config: {
processingMode: 'reencode',
container: 'mp4',
videoCodec: 'libx264',
videoBitrateMode: 'crf',
videoBitrate: '5000',
crf: 23,
quality: 50,
preset: 'medium',
audioCodec: 'aac',
audioBitrate: '192k',
audioChannels: 'stereo',
audioVolume: 100,
audioNormalize: false,
selectedAudioTracks: [],
selectedSubtitleTracks: [],
subtitleBurnPath: null,
resolution: 'original',
scalingAlgorithm: 'bicubic',
fps: 'original',
startTime: null,
endTime: null,
metadata: { mode: 'preserve' },
rotation: '0',
flipHorizontal: false,
flipVertical: false,
mlUpscale: null,
hwDecode: false,
nvencSpatialAq: false,
nvencTemporalAq: false,
videotoolboxAllowSw: false,
gifColors: 256,
gifDither: 'sierra2_4a',
gifLoop: 0
}
});
console.log('Conversion queued successfully');
} catch (error) {
console.error('Failed to queue conversion:', error);
}
pause_conversion
Pauses a running conversion task by sending SIGSTOP (Unix) or NtSuspendProcess (Windows) to the FFmpeg process.
Signature
pub async fn pause_conversion(
manager: tauri::State<'_, ConversionManager>,
id: String,
) -> Result<(), ConversionError>
Parameters
The task ID to pause. Must be a currently running task.
Errors
TaskNotFound - Task with the given ID is not running
Shell - Failed to send pause signal to process
Example
try {
await invoke('pause_conversion', { id: 'task-123' });
console.log('Conversion paused');
} catch (error) {
console.error('Failed to pause:', error);
}
resume_conversion
Resumes a paused conversion task by sending SIGCONT (Unix) or NtResumeProcess (Windows) to the FFmpeg process.
Signature
pub async fn resume_conversion(
manager: tauri::State<'_, ConversionManager>,
id: String,
) -> Result<(), ConversionError>
Parameters
The task ID to resume. Must be a currently paused task.
Errors
TaskNotFound - Task with the given ID is not found
Shell - Failed to send resume signal to process
Example
try {
await invoke('resume_conversion', { id: 'task-123' });
console.log('Conversion resumed');
} catch (error) {
console.error('Failed to resume:', error);
}
cancel_conversion
Cancels a queued or running conversion task. If running, terminates the FFmpeg process with SIGKILL (Unix) or TerminateProcess (Windows). Cleans up temporary upscaling directories.
Signature
pub async fn cancel_conversion(
manager: tauri::State<'_, ConversionManager>,
id: String,
) -> Result<(), ConversionError>
Parameters
The task ID to cancel. Can be queued or running.
Behavior
- Marks task as cancelled in the manager
- If task is running, terminates the FFmpeg process
- Cleans up temporary upscaling directory at
/tmp/frame_upscale_{id}
- Removes task from active tasks map
Example
try {
await invoke('cancel_conversion', { id: 'task-123' });
console.log('Conversion cancelled');
} catch (error) {
console.error('Failed to cancel:', error);
}