-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathanalyse.ts
51 lines (42 loc) · 1.61 KB
/
analyse.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import { fileExists } from "./utils.ts"
// ffmpeg -i '/segments/0-107.y4m' -i 'encodes/0/1.webm' -lavfi libvmaf=log_fmt=json:log_path=analysis/0/1.json -f null /dev/null
export async function analyse(key: number, segment: number[], crf: number, segmentPath: string, outPath: string, retries = 0): Promise<void> {
if (await fileExists(`analyses/${key}/${crf}.json`)) {
console.log(`Skipping analysing ${key} with crf ${crf} because file already exists`)
return
}
await Deno.mkdir("analyses/" + key, { recursive: true }).catch(() => { })
const pFfmpeg = Deno.run({
cmd: [
"ffmpeg",
"-y",
"-r",
"23.98",
"-i",
segmentPath,
"-r",
"23.98",
"-i",
`${outPath}/${key}/${crf}.webm`,
"-lavfi",
`libvmaf=log_fmt=json:log_path=analyses/${key}/${crf}.json:n_threads=1`,
"-f",
"null",
"/dev/null"
],
stdin: "piped",
stdout: "piped",
stderr: "piped",
})
const { code } = await pFfmpeg.status()
if (code !== 0) {
console.log(`analysing segment ${key} with crf ${crf} failed`, segmentPath, `${outPath}/${key}/${crf}.webm`)
// console.log(new TextDecoder().decode(await pSvt.stderrOutput()))
// console.log(new TextDecoder().decode(await pFfmpeg.stderrOutput()))
if (retries > 1) {
return
}
return analyse(key, segment, crf, segmentPath, outPath, retries + 1)
}
console.log(`analysing segment ${key} with crf ${crf} successful`)
}