@@ -9,6 +9,8 @@ import { FastStats } from './stats'
9
9
const log = logger ( 'webrtcperf:vmaf' )
10
10
11
11
export interface IvfFrame {
12
+ pts : number
13
+ recognizedPts ?: number
12
14
index : number
13
15
position : number
14
16
size : number
@@ -204,7 +206,7 @@ async function parseIvf(fpath: string, runRecognizer = false) {
204
206
let index = 0
205
207
let position = 32
206
208
let bytesRead = 0
207
- let frames = new Map < number , IvfFrame > ( )
209
+ const frames = new Map < number , IvfFrame > ( )
208
210
let firstTimestamp = 0
209
211
let lastTimestamp = 0
210
212
do {
@@ -222,7 +224,7 @@ async function parseIvf(fpath: string, runRecognizer = false) {
222
224
/* log.debug(`IVF file ${fname}: pts ${pts} already present, skipping`) */
223
225
skipped ++
224
226
} else {
225
- frames . set ( pts , { index, position, size : size + 12 } )
227
+ frames . set ( pts , { pts , index, position, size : size + 12 } )
226
228
index ++
227
229
if ( ! firstTimestamp ) {
228
230
firstTimestamp = pts / frameRate
@@ -242,19 +244,11 @@ ts: ${firstTimestamp.toFixed(2)}-${lastTimestamp.toFixed(2)} (${(lastTimestamp -
242
244
if ( runRecognizer ) {
243
245
const { frames : ptsToRecognized , participantDisplayName : name } = await recognizeFrames ( fpath )
244
246
participantDisplayName = name
245
- const recognizedFrames = new Map < number , IvfFrame > ( )
246
- //log.debug(path.basename(fpath), 'frames', [...frames.keys()])
247
- for ( const [ pts , frame ] of frames ) {
248
- let recognizedPts = ptsToRecognized . get ( pts )
247
+ for ( const [ pts , frame ] of frames . entries ( ) ) {
248
+ const recognizedPts = ptsToRecognized . get ( pts )
249
249
if ( ! recognizedPts ) continue
250
- while ( recognizedFrames . has ( recognizedPts ) ) {
251
- recognizedPts += 1
252
- }
253
- recognizedFrames . set ( recognizedPts , frame )
250
+ frame . recognizedPts = recognizedPts
254
251
}
255
- //log.debug(path.basename(fpath), 'recognizedFrames', [...recognizedFrames.keys()])
256
- frames . clear ( )
257
- frames = recognizedFrames
258
252
}
259
253
260
254
return {
@@ -299,15 +293,21 @@ export async function fixIvfFrames(filePath: string, keepSourceFile = true) {
299
293
let writtenFrames = 0
300
294
301
295
const ptsIndex = Array . from ( frames . keys ( ) ) . sort ( ( a , b ) => a - b )
296
+ const writtenPts = new Set < number > ( )
302
297
for ( const pts of ptsIndex ) {
303
298
const frame = frames . get ( pts )
304
- if ( ! frame ) {
299
+ if ( ! frame || ! frame . recognizedPts ) {
305
300
log . warn ( `fixIvfFrames ${ fname } : pts ${ pts } not found, skipping` )
306
301
continue
307
302
}
303
+ let recognizedPts = frame . recognizedPts
304
+ while ( writtenPts . has ( recognizedPts ) ) {
305
+ recognizedPts += 1
306
+ }
307
+ writtenPts . add ( recognizedPts )
308
308
const frameView = new DataView ( new ArrayBuffer ( frame . size ) )
309
309
await fd . read ( frameView , 0 , frame . size , frame . position )
310
- frameView . setBigUint64 ( 4 , BigInt ( pts ) , true )
310
+ frameView . setBigUint64 ( 4 , BigInt ( recognizedPts ) , true )
311
311
await fixedFd . write ( new Uint8Array ( frameView . buffer ) , 0 , frameView . byteLength , position )
312
312
position += frameView . byteLength
313
313
writtenFrames ++
@@ -716,9 +716,11 @@ if (require.main === module) {
716
716
case 'convert' :
717
717
await convertToIvf ( process . argv [ 3 ] , process . argv [ 4 ] , false )
718
718
break
719
- case 'parse' :
720
- await parseIvf ( process . argv [ 3 ] , true )
719
+ case 'parse' : {
720
+ const { frames } = await parseIvf ( process . argv [ 3 ] , true )
721
+ console . log ( frames )
721
722
break
723
+ }
722
724
case 'fix' :
723
725
await fixIvfFrames ( process . argv [ 3 ] , true )
724
726
break
0 commit comments