import { createFFmpeg } from '@ffmpeg/ffmpeg' ; import ComponentStore from '../store/componentStore' ; import { FFmpegDataType } from '../types/ffmpegType' ; const { ProgressStore , updateLoaded , updateLoadError } = ComponentStore ; const { updateProgress } = ProgressStore ; const ffmpeg = createFFmpeg ( { log : true , progress : ( input ) => { const value = input . ratio * 100.0 ; if ( value > 0 ) { console . info ( `Completed ${ value . toFixed ( 2 ) }%` ) ; updateProgress ( value ) ; } } } ) ; /** Checks if FFmpeg is supported on that browser */ const loadFFmpeg = async ( ) => { try { await ffmpeg . load ( ) ; } catch ( err ) { console . error ( 'Error' , window . navigator . userAgent , err . message ) ; const loadError = new Error ( `${ err . message } This is because it either timed out or we do not support your browser yet. Please try reloading or using another browser, sorry for the inconvenience.` ) ; updateLoadError ( true , loadError ) ; } updateLoaded ( true ) ; } ; param file retuns const ffmpegWriter = async ( file ) => { const { name } = file ; await ffmpeg . write ( name , file ) ; /**
     * Returning object with name and empty path to keep object symetric for electron
     */ return { name , path : '' } ; } ; param fileName return const ffmpegReader = async ( fileName ) => { const processedFile = ffmpeg . read ( `${ fileName }` ) ; return processedFile ; } ; param fileName param ffmpegData is the parameters of the executed and are of type  FFmpegDataType return const ffmpegRunner = async ( inputFileCommand , ffmpegData ) => { const { outputFile , threads , ffmpegCommands } = ffmpegData ; const commandString = `${ inputFileCommand } -threads ${ threads } ${ ffmpegCommands } -strict -2 ${ outputFile . name }` ; try { await ffmpeg . run ( commandString ) ; return outputFile ; } catch ( err ) { console . trace ( ) ; console . error ( err . message ) ; } } ; const ffmpegGarbageCollector = async ( oldFileNames ) => { for ( const oldFile of oldFileNames ) { if ( oldFile ) { await ffmpeg . remove ( oldFile ) ; } } } ; export default ffmpeg ; export { ffmpegGarbageCollector , ffmpegReader , ffmpegRunner , ffmpegWriter , loadFFmpeg } ;