Skip to content

Commit 67fde51

Browse files
committed
adjust deg video for vmaf
1 parent fbd44c3 commit 67fde51

File tree

2 files changed

+13
-7
lines changed

2 files changed

+13
-7
lines changed

scripts/save-tracks.js

+7-3
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ const saveFileWorkerFn = () => {
121121
async write(/** @type VideoFrame */ frame) {
122122
const { codedWidth, codedHeight, timestamp, duration } = frame
123123
try {
124-
log(`encode ${timestamp} ${duration} ${codedWidth}x${codedHeight} ${frame.format}`)
124+
//log(`encode ${timestamp} ${duration} ${codedWidth}x${codedHeight} ${frame.format}`)
125125
if (!codedWidth || !codedHeight) return
126126
if (x || y || (width && width !== codedWidth) || (height && height !== codedHeight)) {
127127
const w = Math.min(width, codedWidth)
@@ -150,15 +150,19 @@ const saveFileWorkerFn = () => {
150150
},
151151
close() {
152152
log(`saveTrack ${url} close`)
153-
encoder?.flush()
153+
if (encoder?.state === 'configured') {
154+
encoder.flush()
155+
}
154156
encoder?.close()
155157
ws.close()
156158
websocketControllers.delete(id)
157159
postMessage({ name: 'close', id, kind })
158160
},
159161
abort(reason) {
160162
log(`saveTrack ${url} abort reason:`, reason)
161-
encoder?.flush()
163+
if (encoder?.state === 'configured') {
164+
encoder.flush()
165+
}
162166
encoder?.close()
163167
ws.close()
164168
websocketControllers.delete(id)

src/vmaf.ts

+6-4
Original file line numberDiff line numberDiff line change
@@ -111,13 +111,13 @@ export async function recognizeFrames(fpath: string, recover = false, debug = fa
111111
fpath,
112112
'video',
113113
'frame=pts,frame_tags=lavfi.ocr.text,lavfi.ocr.confidence',
114-
`crop=w=min(iw\\,ih):h=max((ih/15)\\,32):x=(iw-ow)/2:y=0:exact=1,ocr=whitelist=0123456789-`,
114+
`scale=w=1280:h=-1:flags=bicubic,crop=w=min(iw\\,ih):h=max((ih/15)\\,32):x=(iw-ow)/2:y=0:exact=1,ocr=whitelist=0123456789-`,
115115
frame => {
116116
const pts = parseInt(frame.pts)
117117
if ((!frames.has(pts) || !frames.get(pts)) && frameRate) {
118118
const confidence = parseFloat(frame.tag_lavfi_ocr_confidence?.trim() || '0')
119119
const textMatch = regExp.exec(frame.tag_lavfi_ocr_text?.trim() || '')
120-
if (confidence > 50 && textMatch) {
120+
if (confidence > 0 && textMatch) {
121121
const { name, time } = textMatch.groups as { name: string; time: string }
122122
participantDisplayName = `Participant-${name.padStart(6, '0')}`
123123
const recognizedTime = parseInt(time)
@@ -165,6 +165,7 @@ ts: ${firstTimestamp.toFixed(2)}-${lastTimestamp.toFixed(2)} (${(lastTimestamp -
165165
}
166166

167167
async function parseIvf(fpath: string, runRecognizer = false) {
168+
const { width, height } = await parseVideo(fpath)
168169
const fname = path.basename(fpath)
169170
const fd = await fs.promises.open(fpath, 'r')
170171
const headerData = new ArrayBuffer(32)
@@ -174,8 +175,6 @@ async function parseIvf(fpath: string, runRecognizer = false) {
174175
await fd.close()
175176
throw new Error('Invalid IVF file')
176177
}
177-
const width = headerView.getUint16(12, true)
178-
const height = headerView.getUint16(14, true)
179178
const den = headerView.getUint32(16, true)
180179
const num = headerView.getUint32(20, true)
181180
const frameRate = den / num
@@ -291,6 +290,8 @@ export async function fixIvfFrames(filePath: string, keepSourceFile = true) {
291290
writtenFrames++
292291
}
293292

293+
headerView.setUint16(12, width, true)
294+
headerView.setUint16(14, height, true)
294295
headerView.setUint32(24, writtenFrames, true)
295296
await fixedFd.write(new Uint8Array(headerView.buffer), 0, headerView.byteLength, 0)
296297

@@ -461,6 +462,7 @@ export async function runVmaf(
461462

462463
const filter = `\
463464
[0:v]\
465+
scale=w=-1:h=${degHeight}:flags=bicubic,\
464466
${cropFilter(crop.deg, 0, ',')}\
465467
${splitFilter(['deg_vmaf', 'deg_psnr', preview ? 'deg_preview' : ''])};\
466468
[1:v]\

0 commit comments

Comments
 (0)