-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathget_grad_vmaf.ts
60 lines (42 loc) · 1.41 KB
/
get_grad_vmaf.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
52
53
54
55
56
57
58
59
60
import scene_pos from "./scenes.json" assert { type: "json" }
interface Point {
crf: string,
bitrate: number,
filesize: number,
vmaf: number,
start: number,
frames: number
}
const vmafCurves: Record<number, Point[]> = {}
for (const scene of scene_pos) {
vmafCurves[scene] = JSON.parse(await Deno.readTextFile(`convexes/${scene}.json`))
}
console.log(vmafCurves[0])
let csv = "grad,size,bitrate,vmaf"
const targetVmaf = 9
const targetGrad = 0.0001
// for (let targetGrad = 0.00001; targetGrad < 0.01; targetGrad += 0.00001) {
let size = 0
let vmafSum = 0
for (const scene of scene_pos) {
const convexes = vmafCurves[scene]
const lines = []
for (let i = 0; i < convexes.length - 1; i++) {
const a = convexes[i]
const b = convexes[i + 1]
const grad = (b.vmaf - a.vmaf) / (b.bitrate - a.bitrate)
//
lines.push([b.filesize, b.vmaf, grad, a.frames])
}
const closest = lines.reduce((prev, curr) => {
const prevDiff = Math.abs(prev[2] - targetGrad)
const currDiff = Math.abs(curr[2] - targetGrad)
return prevDiff < currDiff ? prev : curr
})
size += closest[0]
vmafSum += closest[1] * closest[3]
}
console.log(targetGrad, size, size / 34047 * 24 * 8, vmafSum / 34047)
// csv += `\n${targetGrad},${size},${size / 34047 * 24 * 8},${vmafSum / 34047}`
// }
// await Deno.writeTextFile("grad-size-vmaf.csv", csv)