// Name: Video Speed // Description: Change the playback speed of a video file. // Author: Strajk import '@johnlindquist/kit';// Get the video file path, either from selection or prompt const videoPath = await getSelectedFile() || await path({ placeholder: 'Select a video file' }); // Define available speed options with labels const speedOptions = [ { name: '1.5x', value: 1.5 }, { name: '2x', value: 2 }, { name: '3x', value: 3 }, { name: '5x', value: 5 }, { name: 'Custom', value: 'custom' }, ]; // Prompt user to select a speed const selectedSpeed = await arg('Select speed', speedOptions.map(option => option.name)); let speed: number; if (selectedSpeed === 'Custom') { // If custom speed selected, prompt for the custom speed and validate input const customSpeedStr = await arg({ placeholder: 'Enter custom speed' }); const parsedCustomSpeed = parseFloat(customSpeedStr); if (isNaN(parsedCustomSpeed) || parsedCustomSpeed <= 0) { await div('Invalid custom speed'); exit(); } speed = parsedCustomSpeed } else { // Find the selected speed from predefined options const selectedOption = speedOptions.find(option => option.name === selectedSpeed); if (!selectedOption || typeof selectedOption.value === 'string') { await div("Invalid speed selected") exit() } speed = selectedOption.value } // Extract directory, base name, and extension from the video pathconst { dir, name, ext } = path.parse(videoPath); // Construct the output path with '-speed' suffix const outputPath = path.join(dir, `${name}-speed${ext}`); // Execute ffmpeg command to change video speed and audio tempo try { await term( `ffmpeg -i "${videoPath}" -filter:v "setpts=${ 1 / speed }*PTS" -filter:a "atempo=${speed}" "${outputPath}"` ); } catch (error) { console.error("FFmpeg command failed:", error); await div("Error processing video"); exit(); } // Reveal output file in the system's file explorer await revealFile(outputPath);