File tree Expand file tree Collapse file tree 1 file changed +18
-1
lines changed Expand file tree Collapse file tree 1 file changed +18
-1
lines changed Original file line number Diff line number Diff line change 11let duration = 0 ;
2+ let frames = 0 ;
3+ let readFrames = false ;
24let ratio = 0 ;
35
46const ts2sec = ( ts ) => {
@@ -14,11 +16,26 @@ module.exports = (message, progress) => {
1416 progress ( { duration : d , ratio } ) ;
1517 if ( duration === 0 || duration > d ) {
1618 duration = d ;
19+ readFrames = true ;
1720 }
21+ } else if ( readFrames && message . startsWith ( ' Stream' ) ) {
22+ const match = message . match ( / ( [ \d \. ] + ) f p s / ) ;
23+ if ( match ) {
24+ const fps = parseFloat ( match [ 1 ] ) ;
25+ frames = duration * fps ;
26+ } else {
27+ frames = 0 ;
28+ } ;
29+ readFrames = false ;
1830 } else if ( message . startsWith ( 'frame' ) || message . startsWith ( 'size' ) ) {
1931 const ts = message . split ( 'time=' ) [ 1 ] . split ( ' ' ) [ 0 ] ;
2032 const t = ts2sec ( ts ) ;
21- ratio = t / duration ;
33+ const f = parseFloat ( message . match ( / f r a m e = \s * ( \d + ) / ) [ 1 ] ) ;
34+ if ( frames ) {
35+ ratio = Math . min ( f / frames , 1 ) ;
36+ } else {
37+ ratio = t / duration ;
38+ } ;
2239 progress ( { ratio, time : t } ) ;
2340 } else if ( message . startsWith ( 'video:' ) ) {
2441 progress ( { ratio : 1 } ) ;
You can’t perform that action at this time.
0 commit comments