import { writeFileSync } from 'fs' ; import { sleep } from 'misc-utils-of-mine-generic' ; import { VideoCapture } from '../src/capture' ; async function rgba480x320 ( ) { const c = new VideoCapture ( { port : 8012 , width : 480 , height : 320 , mime : 'rgba' , constrains : { video : { width : 480 , height : 320 } } } ) ; let counter = 0 ; c . addFrameListener ( f => { counter ++ ; } ) ; const t = setInterval ( ( ) => { console . log ( `rgba480x320 ${ counter ++ } FPS` ) ; counter = 0 ; } , 1000 ) ; setTimeout ( async ( ) => { clearInterval ( t ) ; await sleep ( 1200 ) ; c . stop ( ) ; } , 15000 ) ; await c . start ( ) ; } async function jpg480x320 ( ) { const c = new VideoCapture ( { port : 8013 , width : 480 , height : 320 , mime : 'image/jpeg' , constrains : { video : { width : 480 , height : 320 } } } ) ; let counter = 0 ; c . addFrameListener ( f => { counter ++ ; } ) ; const t = setInterval ( ( ) => { console . log ( `jpg480x320 ${ counter ++ } FPS` ) ; counter = 0 ; } , 1000 ) ; setTimeout ( async ( ) => { clearInterval ( t ) ; writeFileSync ( 'tmp_jpg480x320.jpg' , ( await c . readFrame ( ) ) . data ) ; await sleep ( 1200 ) ; await c . stop ( ) ; } , 5000 ) ; await c . start ( ) ; } ( async ( ) => { await jpg480x320 ( ) ; } ) ( ) ;