nicknsy / jellyscrub

Smooth mouse-over video scrubbing previews for Jellyfin.
MIT License
668 stars 27 forks source link

Extracting keyframe to increase speed #84

Open Damix48 opened 1 year ago

Damix48 commented 1 year ago

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

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 commented 1 year ago
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 commented 1 year ago

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 commented 1 year ago

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:

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