ffmpeg.wasm icon indicating copy to clipboard operation
ffmpeg.wasm copied to clipboard

How to get images for each frame of a video, without file writing operations

Open mcdongWang opened this issue 3 years ago • 1 comments

On web, it takes very long time for get much frame of a video(100 frame from a mp4 file, size:3.3MB, length: 10s, 1280*720, takes 20-30 seconds),

I read the exact procedure,

  • Frame extraction task about 300ms
  • write file maybe taks 25 seconds

some info

  • MacBook Pro (15-inch, 2017)
  • 2.8 GHz 4 Core Intel Core i7
  • 16 GB 2133 MHz LPDDR3
  • Radeon Pro 555 2 GB
  • Intel HD Graphics 630 1536 MB
  • Chrome 96.0.4664.110(Stable) (x86_64)

code:

await ffmpeg.run('-i', name, '-vf', `select='between(t\,0\,99)`, '-vsync', '0','frames%d.jpg')

Can i quickly read each frame by Memory , like:

// await ffmpeg.run('-i', name, '-vf', `select='between(t\,0\,99)`, '-vsync', '0','frames%d.jpg')
const frameArray
await ffmpeg.run('-i', name, '-vf', `select='between(t\,0\,99)`, '-vsync', '0', frameArray)
frameArray.length // 100
frameArray[10] // a image obj or a image blob

solutions now:

  • i try to use pipe but i don't know how to use is
  • now, i use ffmpeg -i ./test.mp4 -vf 'fps=1/0.1:round=zero:start_time=0,scale=1280x720,tile=10x10' M%d.jpg
    • Faster than before, but still takes a long time

mcdongWang avatar Jan 11 '22 07:01 mcdongWang

Excuse me,an example of getting a video cover or specifying a frame to Image,Thanks! @mcdongWang

dayday6668 avatar Jul 15 '22 10:07 dayday6668

If you're looking for performance, ffmpeg.wasm might not be the right solution. Can you solve your problems by using native ffmpeg on a server?

benz2012 avatar May 23 '23 02:05 benz2012