Created
September 20, 2019 03:54
-
-
Save 599316527/ca43d1a9c004ed262887e9ba9e735521 to your computer and use it in GitHub Desktop.
米家摄像头 分钟 视频合并
This file contains 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
const path = require('path'); | |
const fs = require('fs'); | |
const cameraVideoDir = '/mnt/d/Oolong/xiaomi/xiaomi_camera_videos/04cf8cc737da'; | |
let videoDateHourMinutes = fs.readdirSync(cameraVideoDir).filter(function (name) { | |
return /^\d{10}$/.test(name); | |
}).reduce(function (ret, name) { | |
let date = name.substring(0, 8); | |
if (!ret[date]) ret[date] = []; | |
ret[date].push(name); | |
return ret; | |
}, {}); | |
console.log(`Found ${Object.keys(videoDateHourMinutes).length} days' videos`); | |
Object.entries(videoDateHourMinutes).forEach(function ([date, dirnames]) { | |
let filenames = dirnames.reduce(function (ret, dirname) { | |
return ret.concat(fs.readdirSync(path.join(cameraVideoDir, dirname)).filter(function (filename) { | |
return filename.endsWith('.mp4'); | |
}).sort(function (a, b) { | |
return parseInt(a.substring(0, 2), 10) > parseInt(b.substring(0, 2), 10) ? 1 : -1; | |
}).map(function (filename) { | |
return path.join(cameraVideoDir, dirname, filename); | |
})); | |
}, []); | |
console.log('Saving video list to file'); | |
let outputFilename = `videolist_${date}.txt`; | |
fs.writeFileSync(outputFilename, filenames.map(function (filename) { | |
return `file '${filename}'`; | |
}).join('\n')); | |
console.log(`ffmpeg -y -f concat -safe 0 -i ${outputFilename} -vf "setpts=0.1*PTS" -c:v libx265 -crf 28 -c:a aac -b:a 128k v${date}.mp4`); | |
}); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment