import { path as ffprobePath } from 'node-ffprobe-installer' ; import * as execa from 'execa' ; import * as isStream from 'is-stream' ; import { Readable } from 'stream' ; function getFFprobeWrappedExecution ( input ) { const params = [ '-v' , 'error' , '-show_format' , '-show_streams' ] ; if ( typeof input === 'string' ) { return execa ( ffprobePath , [ ... params , input ] ) ; } if ( isStream ( input ) ) { return execa ( ffprobePath , [ ... params , '-i' , 'pipe:0' ] , { reject : false , input , } ) ; } throw new Error ( 'Given input was neither a string nor a Stream' ) ; } param { Stream | String } input return { Promise } async function getVideoDurationInSeconds ( input ) { const { stdout } = await getFFprobeWrappedExecution ( input ) ; const matched = stdout . match ( /duration="?(\d*\.\d*)"?/ ) ; if ( matched && matched [ 1 ] ) return parseFloat ( matched [ 1 ] ) ; throw new Error ( 'No duration found!' ) ; } export default getVideoDurationInSeconds ; export { getVideoDurationInSeconds } ;