Ben Ford
Ben Ford

Reputation: 1394

Faster frame extraction than ffmpeg

I have a video analytics program that processes assorted frames from a video. (Several hours long) The video is likely going to be an MP4 but may be other formats going forwards.

At the moment, I have a C# wrapper around an ffmpeg call to extract an individual frame at the requested time. (I'm using the ffmpeg.exe binary. Not the libraries directly) At the moment, this all works. But it's slow. Very slow.

I've found ways to improve the speed by storing the extracted frames in a ramdisk while they're being processed. Changing the stored image format etc...

I just wanted to check if anyone could think of any way to pull individual frames out. At split-second accuracy. I know this is probably possible with DShow etc... I went straight to FFMPEG as I've used it before. But if DShow is likely to be faster I'll gladly change!

Upvotes: 3

Views: 3435

Answers (2)

Roman Ryltsov
Roman Ryltsov

Reputation: 69724

In Windows you have native APIs to process, and in particular read from, media files:

  • DirectShow
  • Media Foundation

Both provide support for MP4 (H.264 video), DirectShow as a framework extended by third party MP4 Demultiplexer and H.264 decoder (of needed, also Windows 7 provides build it), and Media Foundation - natively or extended by third party extensions depending on OS version.

Both can be interfaced from .NET via open source wrappers DirectShow.NET and Media Foundation .NET respectively. This works out way faster then FFmpeg CLI for individual frames. Also note that you would be able to obtain frames incrementally without need to locate specific time and do excessive duplicated work, not even to mention process startup/initialization overhead. Alternatively you could use FFmpeg/Libav binaries through wrapper into C# and get similar performance.

Upvotes: 1

rekire
rekire

Reputation: 47975

You can change the position of the offset parameters. The order matters for the speed if the video contains valid meta data you can seek through the video faster.

If you put the offset before the input file the offset will be calculated with the bit rate with is not every time exactly (in case of a variable bit rate), but it is much faster. The correct way is to walk through the video (offset parameter is after the input file) but this takes time.

Upvotes: 0

Related Questions