0

I need to read a video file (.mkv format, h264, 1280x720) frame by frame for video processing.

I am stuck with .NET Framework 4.8 due to dependencies.

Having tried Accord.net VideoFileReader I am unable to read them due to:

[matroska,webm @ 0000024eb36e5c00] Could not find codec parameters for stream 0 (Video: h264, none(progressive), 1280x720): unspecified pixel format
Consider increasing the value for the 'analyzeduration' and 'probesize' options
Assertion desc failed at src/libswscale/swscale_internal.h:674

Unfortunately Accord.NET does not give me much control over the ffmpeg request and the project seems to have died (and .NET Framework has died (and C# has died)).

What are some alternatives which would allow me to read a .mkv file in h264 format frame by frame?

NOTE - FFmpeg.NET does not seem to support getting frame bitmaps; neither does MediaToolkit :(

NOTE - this page has the same problem (last comment 2020) but no resolution :( https://github.com/accord-net/framework/issues/713

Brendan Hill
  • 3,406
  • 4
  • 32
  • 61
  • You could use ffmpeg to extract all the frames yourself and process them afterwards. – Poiter Sep 27 '22 at 08:06
  • You can use Aforge.Net VideoFileReder module. IIRC, it was a separate module with no dependencies on other modules. – jtxkopt Sep 27 '22 at 08:13
  • As long as you can get a pointer or other frame data reference it should be trivial to convert to a bitmap. If you are looking for a complete library you might want to ask at https://softwarerecs.stackexchange.com/ . However, in my experience, it is kind of a pain in the ass to deal with video on .Net, there are just not a lot of good libraries available. – JonasH Sep 27 '22 at 08:32
  • You may try FFmpeg as sup-process using pipe. Here is an [example](https://stackoverflow.com/a/36774881/4926757) for writing video. – Rotem Sep 27 '22 at 08:42
  • You can do this using the LEADTOOLS Multimedia SDK. (Disclosure: I work for the vendor). The SDK has a video callback processing filter that gives you each frame of a video file to either analyze or even modify whether you're playing back, processing video or capturing from a camera. There's a C# Video Callback demo which I built with .NET 4.8 and tested with some MKV files and it worked. If you'd like to try it, there's a [free evaluation here](https://leadtools.com/downloads). – Amin Dodin Sep 28 '22 at 13:54
  • You need move to c/c++/c# unsafe. With c# unsafe, you can try [FFmpeg.AutoGen](https://www.nuget.org/packages/FFmpeg.AutoGen). My old example [here](https://gist.github.com/tqk2811/94d31eb559f9a7fab861bce9507be592#file-livestream-cs-L83), and you need convert `AVFrame` to your type. – Trương Quốc Khánh Sep 30 '22 at 10:23

0 Answers0