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 1
1
let duration = 0 ;
2
+ let frames = 0 ;
3
+ let readFrames = false ;
2
4
let ratio = 0 ;
3
5
4
6
const ts2sec = ( ts ) => {
@@ -14,11 +16,26 @@ module.exports = (message, progress) => {
14
16
progress ( { duration : d , ratio } ) ;
15
17
if ( duration === 0 || duration > d ) {
16
18
duration = d ;
19
+ readFrames = true ;
17
20
}
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 ;
18
30
} else if ( message . startsWith ( 'frame' ) || message . startsWith ( 'size' ) ) {
19
31
const ts = message . split ( 'time=' ) [ 1 ] . split ( ' ' ) [ 0 ] ;
20
32
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
+ } ;
22
39
progress ( { ratio, time : t } ) ;
23
40
} else if ( message . startsWith ( 'video:' ) ) {
24
41
progress ( { ratio : 1 } ) ;
You can’t perform that action at this time.
0 commit comments