Replies: 1 comment 3 replies
-
Contiguous framesYou have a couple options:
fs, frames = ffmpegio.video.read(video_path, ss=timestamps[0], vframes=len(timestamps), pix_fmt=image_format)
fs, frames = ffmpegio.video.read(video_path, ss=timestamps[0], to=timestamps[-1], pix_fmt=image_format)Caveat: I'm not 100% sure if this will always include the last frame at Non-contiguous framesIf the # of keeper frames >> # of skipped framesYou can just slice the fs, frames = ffmpegio.video.read(video_path, ss=timestamps[0], to=timestamps[-1], pix_fmt=image_format)
n = np.round(timestamps*fs).astype(int)
frames = frames[n-n[0], ...]This could very well be the fastest way regardless of how much you're keeping if you're using CUDA as you implied on your other thread. If the # of keeper frames << # of skipped framesYou can use select filter to specify which frames to return. Learn the FFmpeg expression from its documentation to formulate your selection logic, but using one of the examples: vf_expr = ''select='not(mod(n\,100))'" # every 100 frames
fs, frames = ffmpegio.video.read(video_path, ss=timestamps[0], vframes=len(timestamps), pix_fmt=image_format, vf=vf_expr)Use the If your timestamps are randomly chosen (as in no formula can describe your choice) then your expression could get too long. Also, there are several timestamp related options that you may need to set for it to return timestamp accurate frames (e.g., |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
How to do it directly with ffmpegio without a for loop?
Thanks 🙏
Beta Was this translation helpful? Give feedback.
All reactions