BrokenSource / DepthFlow

🌊 Image to → 2.5D Parallax Effect Video. High quality, user first. Free and Open Source Leiapix alternative
https://brokensrc.dev
GNU Affero General Public License v3.0
149 stars 11 forks source link

(REQUEST) Ability to dump frames instead of a video #26

Closed agoralski closed 1 day ago

agoralski commented 4 days ago

Would it be possible to dump frames to individual files instead of a video container?

Tremeschin commented 4 days ago

You can technically inherit your own class like here or on the DepthScene class's .update method, and use:

def update(self):
    frame = self.read_screen()
    image = PIL.Image.frombytes("RGB", self.resolution, frame)
    image = image.transpose(PIL.Image.FLIP_TOP_BOTTOM)

Similar mechanism for taking screenshots on shaderflow !

If you want a numpy array which will be faster than using PIL Image, something like the following could work:

numpy.frombuffer(frame, dtype=numpy.uint8).reshape((*self.resolution, -1))

I can try to do some trickery later for you if you want the raw frames being sent to ffmpeg to use the "render" command on the scene's main command, I'm curious what would be the use case for this though 🤔

Alternatively wait for some if self.time >= 10: self.quit(True) on the update method to stop writing frames this way

agoralski commented 4 days ago

Awesome, thanks for your help! I don't need the frames to be sent to ffmpeg in my case.

Using depthflow to generate different views on the object for training a model for object recognition. It helps me build a larger image dataset from slightly different views :)

Tremeschin commented 4 days ago

Oh, interesting, yea, that way I've talked about should do it for your case, set random or custom/known parameters on a .update, grab the screen contents, move on infinitely until you reach a certain self.frame or self.time !

Be sure to use DepthAnythingV2 on the self.estimator property! it's much better :)

Tremeschin commented 4 days ago

Just adding to your use case, maybe a headless window can go handy for you with WINDOW_BACKEND=headless or initializing your inherited class with YourScene(backend="headless"), so there's not a chance to mess up window resizes / be limited by the monitor size