Untitled diff
6 removals
56 lines
4 additions
54 lines
const { PassThrough } = require('stream')
const { PassThrough } = require('stream')
const { promisify } = require('util')
const { promisify } = require('util')
const axios = require('axios')
const axios = require('axios')
const MultiStream = require('multistream')
const MultiStream = require('multistream')
const ffprobePath = require('@ffprobe-installer/ffprobe').path
const ffprobePath = require('@ffprobe-installer/ffprobe').path
const ffmpeg = require('fluent-ffmpeg')
const ffmpeg = require('fluent-ffmpeg')
ffmpeg.setFfprobePath(ffprobePath)
ffmpeg.setFfprobePath(ffprobePath)
const ffprobeAsync = promisify(ffmpeg.ffprobe)
const ffprobeAsync = promisify(ffmpeg.ffprobe)
const cl = console.log
const cl = console.log
async function run () {
async function run () {
const url = 'https://storage.arc.io/arc/homepage_demo_files/vacations.mp4'
const url = 'https://storage.arc.io/arc/homepage_demo_files/vacations.mp4'
const res = await axios.get(url, { responseType: 'stream' })
const res = await axios.get(url, { responseType: 'stream' })
const contentLength = Number(res.headers['content-length'])
const contentLength = Number(res.headers['content-length'])
const tee = new PassThrough()
const tee = new PassThrough()
const multiPass = new PassThrough()
const lenPass = new PassThrough()
const ffmpegPass = new PassThrough()
const ffmpegPass = new PassThrough()
const multistream = new MultiStream([multiPass])
res.data.pipe(tee)
res.data.pipe(tee)
tee.pipe(multiPass)
tee.pipe(lenPass)
tee.pipe(ffmpegPass)
tee.pipe(ffmpegPass)
const p1 = ffprobeAsync(ffmpegPass).then(metadata => {
const p1 = ffprobeAsync(ffmpegPass).then(metadata => {
tee.unpipe(ffmpegPass)
tee.unpipe(ffmpegPass)
// ffmpegPass.destroy()
// ffmpegPass.destroy()
return metadata
return metadata
})
})
const p2 = new Promise(resolve => {
const p2 = new Promise(resolve => {
let len = 0
let len = 0
multistream.on('data', chunk => {
lenPass.on('data', chunk => {
len += chunk.length
len += chunk.length
})
})
multistream.on('end', () => {
lenPass.on('end', () => {
resolve(len)
resolve(len)
})
})
})
})
const [res1, length] = await Promise.all([p1, p2])
const [res1, length] = await Promise.all([p1, p2])
console.log(contentLength, length)
console.log(contentLength, length)
if (contentLength !== length) {
if (contentLength !== length) {
cl('LENGTH MISMATCH')
cl('LENGTH MISMATCH')
} else {
} else {
cl('okay')
cl('okay')
}
}
}
}
run()
run()