diff --git a/.eslintrc b/.eslintrc index 42f8b3a..11f0e33 100644 --- a/.eslintrc +++ b/.eslintrc @@ -3,7 +3,8 @@ "rules": { "no-underscore-dangle": 0, "linebreak-style": 0, - "global-require": 0 + "global-require": 0, + "no-await-in-loop": 0, }, "env": { "browser": true, diff --git a/examples/browser/image2video.html b/examples/browser/image2video.html new file mode 100644 index 0000000..8f2aeee --- /dev/null +++ b/examples/browser/image2video.html @@ -0,0 +1,51 @@ + + + + + + +

Click start to transcode images to mp4 (x264) and play!

+
+ +

+ Data Set + + + diff --git a/examples/node/image2video.js b/examples/node/image2video.js new file mode 100755 index 0000000..ca14e2e --- /dev/null +++ b/examples/node/image2video.js @@ -0,0 +1,23 @@ +const fs = require('fs'); +const { createWorker } = require('../../src'); + +const worker = createWorker({ + progress: (p) => console.log(p), +}); + +(async () => { + console.log('Loading ffmpeg-core.js'); + await worker.load(); + console.log('Loading data'); + await worker.write('audio.ogg', '../../tests/assets/triangle/audio.ogg'); + for (let i = 0; i < 60; i += 1) { + const num = `00${i}`.slice(-3); + await worker.write(`tmp.${num}.png`, `../../tests/assets/triangle/tmp.${num}.png`); + } + console.log('Start transcoding'); + await worker.run('-framerate 30 -pattern_type glob -i *.png -i audio.ogg -c:a copy -shortest -c:v libx264 -pix_fmt yuv420p out.mp4'); + const { data } = await worker.read('out.mp4'); + console.log('Complete transcoding'); + fs.writeFileSync('out.mp4', Buffer.from(data)); + process.exit(0); +})(); diff --git a/src/utils/extractProgress.js b/src/utils/extractProgress.js index 2ccff67..7a02a85 100644 --- a/src/utils/extractProgress.js +++ b/src/utils/extractProgress.js @@ -8,7 +8,10 @@ const ts2sec = (ts) => { module.exports = ({ message }, progress) => { if (message.startsWith(' Duration')) { const ts = message.split(', ')[0].split(': ')[1]; - duration = ts2sec(ts); + const d = ts2sec(ts); + if (duration === 0 || duration > d) { + duration = d; + } } else if (message.startsWith('frame')) { const ts = message.split('time=')[1].split(' ')[0]; const t = ts2sec(ts); diff --git a/tests/assets/triangle/audio.ogg b/tests/assets/triangle/audio.ogg new file mode 100644 index 0000000..94bcb3e Binary files /dev/null and b/tests/assets/triangle/audio.ogg differ diff --git a/tests/assets/triangle/tmp.000.png b/tests/assets/triangle/tmp.000.png new file mode 100644 index 0000000..a576569 Binary files /dev/null and b/tests/assets/triangle/tmp.000.png differ diff --git a/tests/assets/triangle/tmp.001.png b/tests/assets/triangle/tmp.001.png new file mode 100644 index 0000000..2c371d0 Binary files /dev/null and b/tests/assets/triangle/tmp.001.png differ diff --git a/tests/assets/triangle/tmp.002.png b/tests/assets/triangle/tmp.002.png new file mode 100644 index 0000000..7f84201 Binary files /dev/null and b/tests/assets/triangle/tmp.002.png differ diff --git a/tests/assets/triangle/tmp.003.png b/tests/assets/triangle/tmp.003.png new file mode 100644 index 0000000..875b6da Binary files /dev/null and b/tests/assets/triangle/tmp.003.png differ diff --git a/tests/assets/triangle/tmp.004.png b/tests/assets/triangle/tmp.004.png new file mode 100644 index 0000000..7ec9432 Binary files /dev/null and b/tests/assets/triangle/tmp.004.png differ diff --git a/tests/assets/triangle/tmp.005.png b/tests/assets/triangle/tmp.005.png new file mode 100644 index 0000000..9efa064 Binary files /dev/null and b/tests/assets/triangle/tmp.005.png differ diff --git a/tests/assets/triangle/tmp.006.png b/tests/assets/triangle/tmp.006.png new file mode 100644 index 0000000..8882264 Binary files /dev/null and b/tests/assets/triangle/tmp.006.png differ diff --git a/tests/assets/triangle/tmp.007.png b/tests/assets/triangle/tmp.007.png new file mode 100644 index 0000000..e2fa319 Binary files /dev/null and b/tests/assets/triangle/tmp.007.png differ diff --git a/tests/assets/triangle/tmp.008.png b/tests/assets/triangle/tmp.008.png new file mode 100644 index 0000000..86517c1 Binary files /dev/null and b/tests/assets/triangle/tmp.008.png differ diff --git a/tests/assets/triangle/tmp.009.png b/tests/assets/triangle/tmp.009.png new file mode 100644 index 0000000..0cce90d Binary files /dev/null and b/tests/assets/triangle/tmp.009.png differ diff --git a/tests/assets/triangle/tmp.010.png b/tests/assets/triangle/tmp.010.png new file mode 100644 index 0000000..d4db4b4 Binary files /dev/null and b/tests/assets/triangle/tmp.010.png differ diff --git a/tests/assets/triangle/tmp.011.png b/tests/assets/triangle/tmp.011.png new file mode 100644 index 0000000..daf149a Binary files /dev/null and b/tests/assets/triangle/tmp.011.png differ diff --git a/tests/assets/triangle/tmp.012.png b/tests/assets/triangle/tmp.012.png new file mode 100644 index 0000000..c077a90 Binary files /dev/null and b/tests/assets/triangle/tmp.012.png differ diff --git a/tests/assets/triangle/tmp.013.png b/tests/assets/triangle/tmp.013.png new file mode 100644 index 0000000..0b4b573 Binary files /dev/null and b/tests/assets/triangle/tmp.013.png differ diff --git a/tests/assets/triangle/tmp.014.png b/tests/assets/triangle/tmp.014.png new file mode 100644 index 0000000..8789354 Binary files /dev/null and b/tests/assets/triangle/tmp.014.png differ diff --git a/tests/assets/triangle/tmp.015.png b/tests/assets/triangle/tmp.015.png new file mode 100644 index 0000000..ab5e89e Binary files /dev/null and b/tests/assets/triangle/tmp.015.png differ diff --git a/tests/assets/triangle/tmp.016.png b/tests/assets/triangle/tmp.016.png new file mode 100644 index 0000000..b269387 Binary files /dev/null and b/tests/assets/triangle/tmp.016.png differ diff --git a/tests/assets/triangle/tmp.017.png b/tests/assets/triangle/tmp.017.png new file mode 100644 index 0000000..db8a243 Binary files /dev/null and b/tests/assets/triangle/tmp.017.png differ diff --git a/tests/assets/triangle/tmp.018.png b/tests/assets/triangle/tmp.018.png new file mode 100644 index 0000000..b374ed7 Binary files /dev/null and b/tests/assets/triangle/tmp.018.png differ diff --git a/tests/assets/triangle/tmp.019.png b/tests/assets/triangle/tmp.019.png new file mode 100644 index 0000000..2344229 Binary files /dev/null and b/tests/assets/triangle/tmp.019.png differ diff --git a/tests/assets/triangle/tmp.020.png b/tests/assets/triangle/tmp.020.png new file mode 100644 index 0000000..1c9a9ec Binary files /dev/null and b/tests/assets/triangle/tmp.020.png differ diff --git a/tests/assets/triangle/tmp.021.png b/tests/assets/triangle/tmp.021.png new file mode 100644 index 0000000..36e1cc6 Binary files /dev/null and b/tests/assets/triangle/tmp.021.png differ diff --git a/tests/assets/triangle/tmp.022.png b/tests/assets/triangle/tmp.022.png new file mode 100644 index 0000000..eb7140b Binary files /dev/null and b/tests/assets/triangle/tmp.022.png differ diff --git a/tests/assets/triangle/tmp.023.png b/tests/assets/triangle/tmp.023.png new file mode 100644 index 0000000..b0131a7 Binary files /dev/null and b/tests/assets/triangle/tmp.023.png differ diff --git a/tests/assets/triangle/tmp.024.png b/tests/assets/triangle/tmp.024.png new file mode 100644 index 0000000..0de537f Binary files /dev/null and b/tests/assets/triangle/tmp.024.png differ diff --git a/tests/assets/triangle/tmp.025.png b/tests/assets/triangle/tmp.025.png new file mode 100644 index 0000000..3c1ef9d Binary files /dev/null and b/tests/assets/triangle/tmp.025.png differ diff --git a/tests/assets/triangle/tmp.026.png b/tests/assets/triangle/tmp.026.png new file mode 100644 index 0000000..e9205e7 Binary files /dev/null and b/tests/assets/triangle/tmp.026.png differ diff --git a/tests/assets/triangle/tmp.027.png b/tests/assets/triangle/tmp.027.png new file mode 100644 index 0000000..e9b4c3e Binary files /dev/null and b/tests/assets/triangle/tmp.027.png differ diff --git a/tests/assets/triangle/tmp.028.png b/tests/assets/triangle/tmp.028.png new file mode 100644 index 0000000..0a940e7 Binary files /dev/null and b/tests/assets/triangle/tmp.028.png differ diff --git a/tests/assets/triangle/tmp.029.png b/tests/assets/triangle/tmp.029.png new file mode 100644 index 0000000..4af8e93 Binary files /dev/null and b/tests/assets/triangle/tmp.029.png differ diff --git a/tests/assets/triangle/tmp.030.png b/tests/assets/triangle/tmp.030.png new file mode 100644 index 0000000..508f43c Binary files /dev/null and b/tests/assets/triangle/tmp.030.png differ diff --git a/tests/assets/triangle/tmp.031.png b/tests/assets/triangle/tmp.031.png new file mode 100644 index 0000000..600ccec Binary files /dev/null and b/tests/assets/triangle/tmp.031.png differ diff --git a/tests/assets/triangle/tmp.032.png b/tests/assets/triangle/tmp.032.png new file mode 100644 index 0000000..8c795c1 Binary files /dev/null and b/tests/assets/triangle/tmp.032.png differ diff --git a/tests/assets/triangle/tmp.033.png b/tests/assets/triangle/tmp.033.png new file mode 100644 index 0000000..1ad2c2a Binary files /dev/null and b/tests/assets/triangle/tmp.033.png differ diff --git a/tests/assets/triangle/tmp.034.png b/tests/assets/triangle/tmp.034.png new file mode 100644 index 0000000..cba17c9 Binary files /dev/null and b/tests/assets/triangle/tmp.034.png differ diff --git a/tests/assets/triangle/tmp.035.png b/tests/assets/triangle/tmp.035.png new file mode 100644 index 0000000..61106b5 Binary files /dev/null and b/tests/assets/triangle/tmp.035.png differ diff --git a/tests/assets/triangle/tmp.036.png b/tests/assets/triangle/tmp.036.png new file mode 100644 index 0000000..da4a6c3 Binary files /dev/null and b/tests/assets/triangle/tmp.036.png differ diff --git a/tests/assets/triangle/tmp.037.png b/tests/assets/triangle/tmp.037.png new file mode 100644 index 0000000..9ee3a72 Binary files /dev/null and b/tests/assets/triangle/tmp.037.png differ diff --git a/tests/assets/triangle/tmp.038.png b/tests/assets/triangle/tmp.038.png new file mode 100644 index 0000000..1679627 Binary files /dev/null and b/tests/assets/triangle/tmp.038.png differ diff --git a/tests/assets/triangle/tmp.039.png b/tests/assets/triangle/tmp.039.png new file mode 100644 index 0000000..cb8a2ec Binary files /dev/null and b/tests/assets/triangle/tmp.039.png differ diff --git a/tests/assets/triangle/tmp.040.png b/tests/assets/triangle/tmp.040.png new file mode 100644 index 0000000..ad825d9 Binary files /dev/null and b/tests/assets/triangle/tmp.040.png differ diff --git a/tests/assets/triangle/tmp.041.png b/tests/assets/triangle/tmp.041.png new file mode 100644 index 0000000..37768aa Binary files /dev/null and b/tests/assets/triangle/tmp.041.png differ diff --git a/tests/assets/triangle/tmp.042.png b/tests/assets/triangle/tmp.042.png new file mode 100644 index 0000000..f5d3e62 Binary files /dev/null and b/tests/assets/triangle/tmp.042.png differ diff --git a/tests/assets/triangle/tmp.043.png b/tests/assets/triangle/tmp.043.png new file mode 100644 index 0000000..09f9358 Binary files /dev/null and b/tests/assets/triangle/tmp.043.png differ diff --git a/tests/assets/triangle/tmp.044.png b/tests/assets/triangle/tmp.044.png new file mode 100644 index 0000000..3aa0589 Binary files /dev/null and b/tests/assets/triangle/tmp.044.png differ diff --git a/tests/assets/triangle/tmp.045.png b/tests/assets/triangle/tmp.045.png new file mode 100644 index 0000000..b516080 Binary files /dev/null and b/tests/assets/triangle/tmp.045.png differ diff --git a/tests/assets/triangle/tmp.046.png b/tests/assets/triangle/tmp.046.png new file mode 100644 index 0000000..d65c157 Binary files /dev/null and b/tests/assets/triangle/tmp.046.png differ diff --git a/tests/assets/triangle/tmp.047.png b/tests/assets/triangle/tmp.047.png new file mode 100644 index 0000000..ad444b2 Binary files /dev/null and b/tests/assets/triangle/tmp.047.png differ diff --git a/tests/assets/triangle/tmp.048.png b/tests/assets/triangle/tmp.048.png new file mode 100644 index 0000000..b15413a Binary files /dev/null and b/tests/assets/triangle/tmp.048.png differ diff --git a/tests/assets/triangle/tmp.049.png b/tests/assets/triangle/tmp.049.png new file mode 100644 index 0000000..7ad2101 Binary files /dev/null and b/tests/assets/triangle/tmp.049.png differ diff --git a/tests/assets/triangle/tmp.050.png b/tests/assets/triangle/tmp.050.png new file mode 100644 index 0000000..90cd4fc Binary files /dev/null and b/tests/assets/triangle/tmp.050.png differ diff --git a/tests/assets/triangle/tmp.051.png b/tests/assets/triangle/tmp.051.png new file mode 100644 index 0000000..cfd4a78 Binary files /dev/null and b/tests/assets/triangle/tmp.051.png differ diff --git a/tests/assets/triangle/tmp.052.png b/tests/assets/triangle/tmp.052.png new file mode 100644 index 0000000..f9c55e1 Binary files /dev/null and b/tests/assets/triangle/tmp.052.png differ diff --git a/tests/assets/triangle/tmp.053.png b/tests/assets/triangle/tmp.053.png new file mode 100644 index 0000000..32e6949 Binary files /dev/null and b/tests/assets/triangle/tmp.053.png differ diff --git a/tests/assets/triangle/tmp.054.png b/tests/assets/triangle/tmp.054.png new file mode 100644 index 0000000..703ba6b Binary files /dev/null and b/tests/assets/triangle/tmp.054.png differ diff --git a/tests/assets/triangle/tmp.055.png b/tests/assets/triangle/tmp.055.png new file mode 100644 index 0000000..0119dcf Binary files /dev/null and b/tests/assets/triangle/tmp.055.png differ diff --git a/tests/assets/triangle/tmp.056.png b/tests/assets/triangle/tmp.056.png new file mode 100644 index 0000000..a4813f1 Binary files /dev/null and b/tests/assets/triangle/tmp.056.png differ diff --git a/tests/assets/triangle/tmp.057.png b/tests/assets/triangle/tmp.057.png new file mode 100644 index 0000000..0cecb96 Binary files /dev/null and b/tests/assets/triangle/tmp.057.png differ diff --git a/tests/assets/triangle/tmp.058.png b/tests/assets/triangle/tmp.058.png new file mode 100644 index 0000000..cb13737 Binary files /dev/null and b/tests/assets/triangle/tmp.058.png differ diff --git a/tests/assets/triangle/tmp.059.png b/tests/assets/triangle/tmp.059.png new file mode 100644 index 0000000..e557cc1 Binary files /dev/null and b/tests/assets/triangle/tmp.059.png differ