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

Would it be possible to decode a file to frames and display them on the fly without holding the entire video in memory? #548

Open
Liam-00 opened this issue Nov 14, 2024 · 1 comment

Comments

@Liam-00
Copy link

Liam-00 commented Nov 14, 2024

My goal is to effectively play a video from a file in a custom view by cycling through frames at the video framerate. My first attempt at this uses ffmpeg to decode the entire video file into a stream of PNGs (should probably use rawvideo), then splits that stream into an array of images that can be displayed.
The FFMpegCore use looks like this:

await FFMpegArguments
      .FromFileInput(videoPath)
      .OutputToPipe(new StreamPipeSink(video_outputstream), options => options
       .WithVideoCodec("png")
       .ForceFormat("image2pipe")
       .ForcePixelFormat("rgba"))
      .ProcessAsynchronously();

This is manageable for very small videos, but requires that the entire decoded video sequence be held in memory at once making memory usage a problem. So is there any way of decoding one frame to a buffer, showing that frame, then decoding the next frame into the buffer, showing that frame and so on in a loop? I've experimented briefly with using a filestream and pipe input, but that seems to get decoded all at once by FFMpegCore, so I'm not sure if there's a way to effectively "stream" a file like a videoplayer would.

@hqkirkland
Copy link

Does the -re flag accomplish at least some of what you want?

This flag should indicate to FFMPEG that the input should be read/processed at 1x of the framerate of the video, or as near to it as possible.

FFMpegArguments.FromFileInput(videoPath, inputOptions => inputOptions.WithCustomArgument(string.Format("-re")))

That said, I don't think this prevents the full file from being required to stay in memory.

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

No branches or pull requests

2 participants