Is writing out to ffmpeg supposed to be this slow? #202
Replies: 4 comments 2 replies
-
Hello, @camblomquist . What is the window resolution for the Sketch you are trying to encode to video? The example for that function uses skvideo but skvideo is not the best video library. I once looked at the source code and how it uses ffmpeg and I believe it piped the frames to ffmpeg via stdin using a raw format of some kind. It isn't efficient at all. Can you try using opencv instead? Using opencv to encode videos isn't that great because the encoding formats available depend on how opencv was compiled, so I didn't want to use it for the example code. It happens I've been making a lot of screen recordings lately with py5 and I've been using save_frames() to write image sequences and then encoding the image sequence using ffmpeg. This can cause problems though because if it tries to save frames faster than what my hard drive can handle, there is a backlog that takes up memory and the process gets killed. This happens if I try to write 4K or 8K frames at 30 fps. To manage that I have to slow down the Sketch so it isn't creating new frames faster than they can be saved. The offline_frame_processing() function was created for a situation I faced where I couldn't use opencv and wasn't able to write an image sequence to disk because of space limitations. I also couldn't use OBS or X11grab + ffmpeg. It wasn't a good situation to be in. Using the offline_frame_processing function plus skvideo was slow but it got the job done. |
Beta Was this translation helpful? Give feedback.
-
First, sorry for my rudeness earlier. The window resolution is 1920x1080. |
Beta Was this translation helpful? Give feedback.
-
A discovery! def write(frames):
pass I would think that this shouldn't slow things down, but it does! It appears that using |
Beta Was this translation helpful? Give feedback.
-
It's fine, we all have our moments. I should tell you I'm currently swamped preparing for a gallery show in two weeks so I am not able to respond as quickly as I would like.
Yes, for large windows, that is to be expected. I have re-read the reference documentation for offline_frame_processing() and should re-write the last sentence in the first paragraph. This function is less useful than I thought it would be when I was writing the code. Can I have more information about what the end goal is here? You have an HD sketch running on Windows that you want to encode to a video. Why not use On Linux I can run a Sketch in fullscreen mode and then use ffmpeg and x11grab to pull from the display and encode the video. If the encoder works on the GPU like hevc_nvenc does, it can go from x11grab right to the encoder, without leaving the GPU. As long as the Sketch can still run in real time, this will get good results. When that approach doesn't work I will use |
Beta Was this translation helpful? Give feedback.
-
The documentation for
offline_frame_processing
provides an example where a sketch is written out to video using ffmpeg. Trying this in my own sketch which normally runs a smooth 30ish or 60ish frames per second, the sketch slows down to a painful 0.3 fps.Beta Was this translation helpful? Give feedback.
All reactions