Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extracting keyframe to increase speed #84

Open
Damix48 opened this issue Feb 20, 2023 · 3 comments
Open

Extracting keyframe to increase speed #84

Damix48 opened this issue Feb 20, 2023 · 3 comments

Comments

@Damix48
Copy link

Damix48 commented Feb 20, 2023

I would be nice extracting the keyframes instead of any frames. This trick improves by 5x-7x the generation of the previews.

example:

ffmpeg -skip_frame nokey -i file -vf scale=320:-1  -qscale:v 10 out%d.jpeg
  • -skip_frame nokey to process only the keyframes
  • -vf scale=320:-1 to scale the frames to be 320px width
  • -qscale:v 10 quality?, not really necessary because the images are so small

I run a test with a 3h movie:

keyframes any frames
speed ~90s (114x) ~750s (14.7x)
frames ~2500 (~13MB) ~2100 (~10MB)
fps 1 frame every ~4s 1 frame ever 5s

The keyframe methods is 7.7x faster!

The main drawback is that isn't not possible to specify exactly how many frames create or how many seconds from frame to frame.


references:

@iwalton3
Copy link

ffmpeg -skip_frame nokey -i file -frame_pts true -vf scale=320:-1 -qscale:v 10 -vsync 0 -r 1000 kf-%10d.jpg

can produce files which have their timestamp in milliseconds. I suppose that could be used to find frames which are the closest to the prescribed interval. The question becomes how to deal with the gaps, as trickplay formats usually require there to not be holes in the series of images.

@nicknsy
Copy link
Owner

nicknsy commented Feb 21, 2023

I have tested keyframes before when using the BIF format and my problem was that I didn't get nearly as many frames output which led to much less useful trickplay images. Generally, my goal is that if you're hovering over some point on the timeline the image previewed is going to be what you see when you skip there, but with keyframes that's usually not the case (at least from the very limited testing I did).

@Damix48
Copy link
Author

Damix48 commented Feb 21, 2023

Is ffmpeg requirement? Because I often use mplayer (http://www.mplayerhq.hu) and it's very fast. I extract 1 frame each 10s in about 50s (same movie of the tests before). ~15x faster of standard and ~2x faster of keyframe only.

The only problem is that I'm not sure how precise mplayer is.:

mplayer $file -ss 1 -nosound -zoom -xy 320 -vo jpeg:outdir=./output -frames $frames -sstep $steps

where:

  • $steps is 10 (10s)
  • $frames is duration of movie / $steps

This command generates ~200 same ending frames. I only tried it on Windows and maybe I do the wrong calculation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants