hazy
0a01583f56
Make CLI arguments use flags, support webm output encoding, allow running from any working directory, add optional profiles, add audio to spliced-in clips, various small fixes
45 lines
1.4 KiB
JavaScript
45 lines
1.4 KiB
JavaScript
import fs from 'fs'
|
|
import exec from './exec.js'
|
|
let videos = []
|
|
|
|
let videoDurations = {
|
|
|
|
}
|
|
|
|
async function getRandomVideo() {
|
|
let randomVideo = global.birdgenAssetPath+'video/'+videos[Math.floor(Math.random()*videos.length)]
|
|
let duration
|
|
if (videoDurations[randomVideo]) duration = videoDurations[randomVideo]
|
|
else {
|
|
const {stdout} = await exec(`ffprobe -i ${randomVideo} -v quiet -show_entries format=duration -hide_banner -of default=noprint_wrappers=1:nokey=1`)
|
|
duration = parseFloat(stdout.trim()) * 1000
|
|
videoDurations[randomVideo] = Math.floor(duration)
|
|
}
|
|
let response = {
|
|
start: 0,
|
|
end: videoDurations[randomVideo],
|
|
filePath: randomVideo
|
|
}
|
|
let partsOfName = randomVideo.split('/').pop().split('.')
|
|
if (partsOfName.length>2&&['music', 'sound'].includes(partsOfName.at(-2))) {
|
|
response.force = partsOfName.at(-2)
|
|
}
|
|
return response
|
|
}
|
|
|
|
export default async function addExtraVideos(sections) {
|
|
videos = fs.readdirSync(global.birdgenAssetPath+'video')
|
|
let newList = []
|
|
for (let i = 0; i < sections.length; i ++) {
|
|
newList.push(sections[i])
|
|
if (Math.random()>0.95) {
|
|
for (let j = 0; j < Math.floor(Math.random()*10); j ++) {
|
|
newList.push(sections[i])
|
|
}
|
|
}
|
|
if (Math.random()>0.9) {
|
|
newList.push(await getRandomVideo())
|
|
}
|
|
}
|
|
return newList
|
|
} |