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

Drop all non-keyframes to speed up long footage #2111

Open
4 tasks done
TuxRobotics opened this issue Aug 12, 2024 · 8 comments
Open
4 tasks done

Drop all non-keyframes to speed up long footage #2111

TuxRobotics opened this issue Aug 12, 2024 · 8 comments

Comments

@TuxRobotics
Copy link

The fewer issues I have to read, the more new features I will have time to implement, so I ask that you please try these things first

Description

In the "Export Mode" dropdown, it would be awesome if there were a "Fast Forward Cuts" option. Instead of cutting, it would speed up the frame rate by an integer multiple and merge.

It would be fantastic for quickly cropping down long security camera footage!

To keep export performance, it could:

  1. Be restricted to integer frame rate multiples
  2. Only export keyframes in the "cut" section
  3. "FF" segments would Essentially just be a few more params passed to FFMPEG

Thanks, awesome work!

@mifi
Copy link
Owner

mifi commented Aug 13, 2024

I think you can already do that by clicking on the change speed icon next to the fps in the lower left

@TuxRobotics
Copy link
Author

That is close but it still outputs all the frames and just tells the player to speed up.
This means big files and most hardware can't handle high frame rates.
Also, it can't be applied to cut sections.

@mifi
Copy link
Owner

mifi commented Aug 13, 2024

It’s not possible to losslessly change the speed without re-encoding or playing existing frames faster afaik, or am i missing something?

@TuxRobotics
Copy link
Author

TuxRobotics commented Aug 14, 2024

FFMPEG can actually do this by grabbing only the keyframes and copying them, at least for H264.

I tried this quickly on a video and it worked (no transcoding involved).

ffmpeg -discard nokey -i t1.mp4 -c copy t1.264
ffmpeg -r 30 -i t1.264 -c copy t1keys.mp4

Source:
https://video.stackexchange.com/questions/21970/speed-up-a-video-30x-using-only-key-frames-with-ffmpeg

@mifi
Copy link
Owner

mifi commented Aug 15, 2024

Ohh okay cool! Gyan from the ffmpeg team always seems to have the answers 🙌

But then you are at the mercy of the keyframe interval, right? it wouldn't allow "speed up the frame rate by an integer multiple". The resulting file would play only the keyframes and nothing else. That would effectively give a keyframe interval of 1. I think some players have problems playing back videos that only have keyframes (as it requires more bandwidth and cpu to decode keyframes compared to other frames).

I agree it would be a cool trick, maybe we can have a tool in the "Tools" menu that allows stripping out non-keyframes from a video using this command.

also: even though technically the keyframes don't lose any quality, in a whole it's quite a lossy operation because all non-keyframes are lost 😅 but I guess the main benefit is that the operation would be very fast.

@mifi mifi changed the title Fast Forward Cuts Drop all non-keyframes to speed up long footage Aug 15, 2024
@TuxRobotics
Copy link
Author

Yes, I agree it is lossy, but it is fast and less lossy than "cut" right? 😅

For playback, I had made the assumption that it would take less CPU power to play keyframe-only sections, but you are right that the memory/file bandwidth probably jumps a lot.

Instead of the tools menu, if a user could click on the "trash" icon in the timeline and have it change to a ">>" or similar for the segment it would be slick. Might be difficult to differentiate the icon click from a seek click?

I am poking around the FFMPEG source to see if there is a way to throw out some of the keyframes as well to be able to adjust the speedup

@TuxRobotics
Copy link
Author

Yeah, doesn't look like there is a way to do any faster than keyframes only. Still pretty useful level of speed up though.
I will look at submitting a pull request to FFMPEG for skipping a variable number of keyframes as well. A surprising number of codecs work with this.

@mifi
Copy link
Owner

mifi commented Aug 23, 2024

For playback, I had made the assumption that it would take less CPU power to play keyframe-only sections, but you are right that the memory/file bandwidth probably jumps a lot.

I just assumed that rendering a high quality detailed keyframe takes more cpu than calculating the next frame based on an existing frame and a motion vector, but i might be wrong.

Instead of the tools menu, if a user could click on the "trash" icon in the timeline and have it change to a ">>" or similar for the segment it would be slick. Might be difficult to differentiate the icon click from a seek click?

That would not be trivial to implement so I probably won't implement it that way for such a niche use case unless it becomes a tremendously popular request.

I will look at submitting a pull request to FFMPEG for skipping a variable number of keyframes as well. A surprising number of codecs work with this.
cool

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

No branches or pull requests

2 participants