Created
July 28, 2018 09:25
-
-
Save rigelk/95e41dacb66df652039e59350a9eb7b4 to your computer and use it in GitHub Desktop.
check streamability
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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