Skip to content

Instantly share code, notes, and snippets.

@rigelk
Created July 28, 2018 09:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rigelk/95e41dacb66df652039e59350a9eb7b4 to your computer and use it in GitHub Desktop.
Save rigelk/95e41dacb66df652039e59350a9eb7b4 to your computer and use it in GitHub Desktop.
check streamability
async function isVideoFileStreamable (path: string): Promise<{ [key: string]: boolean }> {
let stream = fs.createReadStream(path, {
encoding: null,
start: 0,
end: 1024 * 1024
})
const isAVC = (await getVideoFileStream(path)).filter(s => {
return s['codec_name'] === 'h264' &&
s['bit_rate'] < 3000000
})
const isAAC = (await audio.get(ffmpeg, path)).filter(s => {
return s['codec_name'] === 'aac'
})
const hasFastStart = await new Promise<boolean>((res, rej) => {
ffmpeg(stream, { stdoutLines: 0 })
.inputOption('-v 56')
.on('error', rej)
.on('end', (stdout) => res(stdout.indexOf('type:\'moov\'') < stdout.indexOf('type:\'mdat\'')))
})
return {
hasFastStart,
isAVC,
isAAC
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment