<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>videoJs</title>
</head>
<body>
<script type="text/javascript">
const originFile = 'C:/Users/mike/Desktop/test.mp4';
const target = './video';
let s = `ffmpeg -ss ST -to ET -accurate_seek -i ${originFile} -c copy -avoid_negative_ts 1 ${target}/index.mp4`;
let st = 0;
let span = 1;
let tal = 30;
let cnt = 1;
let txt = '';
while(st < tal) {
let et = st+span;
if (et > tal) {
et = tal;
}
// 替换开始和结束时间
txt += s.replace('ST', time(st)).replace('ET', time(et)).replace('index', cnt);
txt += '\n';
st += span;
cnt++;
}
console.log(txt);
function time(t) {
const h = Math.floor(t / (60 * 60));
const m = Math.floor((t - (h * 60 * 60)) / 60 );
const s = t % 60;
return (h < 10 ? ('0' + h) : h) + ':' + (m < 10 ? ('0' + m) : m) + ':' + (s < 10 ? ('0' + s) : s);
}
</script>
</body>
</html>