File tree Expand file tree Collapse file tree 2 files changed +36
-2
lines changed Expand file tree Collapse file tree 2 files changed +36
-2
lines changed Original file line number Diff line number Diff line change @@ -25,6 +25,8 @@ module.exports = (_options = {}) => {
2525 let logging = optLog ;
2626 let progress = optProgress ;
2727 let duration = 0 ;
28+ let frames = 0 ;
29+ let readFrames = false ;
2830 let ratio = 0 ;
2931
3032 const detectCompletion = ( message ) => {
@@ -53,11 +55,26 @@ module.exports = (_options = {}) => {
5355 prog ( { duration : d , ratio } ) ;
5456 if ( duration === 0 || duration > d ) {
5557 duration = d ;
58+ readFrames = true ;
5659 }
60+ } else if ( readFrames && message . startsWith ( ' Stream' ) ) {
61+ const match = message . match ( / ( [ \d \. ] + ) f p s / ) ;
62+ if ( match ) {
63+ const fps = parseFloat ( match [ 1 ] ) ;
64+ frames = duration * fps ;
65+ } else {
66+ frames = 0 ;
67+ } ;
68+ readFrames = false ;
5769 } else if ( message . startsWith ( 'frame' ) || message . startsWith ( 'size' ) ) {
5870 const ts = message . split ( 'time=' ) [ 1 ] . split ( ' ' ) [ 0 ] ;
5971 const t = ts2sec ( ts ) ;
60- ratio = t / duration ;
72+ const f = parseFloat ( message . match ( / f r a m e = \s * ( \d + ) / ) [ 1 ] ) ;
73+ if ( frames ) {
74+ ratio = Math . min ( f / frames , 1 ) ;
75+ } else {
76+ ratio = t / duration ;
77+ } ;
6178 prog ( { ratio, time : t } ) ;
6279 } else if ( message . startsWith ( 'video:' ) ) {
6380 prog ( { ratio : 1 } ) ;
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