Struggling to read a grayscale video in

I’m struggling to figure out how to read in a UInt8 grayscale video.

  1. read(open(videofilename)) isn’t working on this video format. I just get a 1D array of UInt8 that’s about 20k elements longer than the video should be based on w x h x nframes
  2. VideoIO.jl doesn’t support current FFMPEG versions, and I can’t make it use older versions https://github.com/kmsquire/VideoIO.jl/issues/131
  3. FFmpegPipe.jl gets close but seems like forces reading the single channel video as RGB channels, resulting in a frame that’s 3x taller than it should be (using 3 successive frames, from what I can tell). https://github.com/perrutquist/FFmpegPipe.jl/issues/4

Any ideas appreciated. I’d like most to have a basic function where I can tweak ffmpeg to match the source format and control the codec precisely. I’m writing videos like that based on the example given here: Creating a video from a stack of Images

Also, FileIO isn’t able to read the video:

using FileIO
obj = load("test.avi")
Error encountered while loading "test.avi". Fatal error:

DelegateFailed `'ffmpeg' -nostdin -v -1 -vframes %S -i '%i' -vcodec pam -an -f rawvideo -y '%u.pam' 2> '%Z'' @ error/delegate.c/InvokeDelegate/1919

It seems that the 3x taller issue with FFmpegPipe.jl was actually because of an oddity in how Image J saves it’s AVIs, with 3 duplicated grayscale channels, or something to that effect.

I’ve hardcoded a stride into my FFmpegPipe code for now and it seems to work.

But it is VERY slow… Lots of small readbytes() seem to be slowing things down significantly

Yes, as I mentioned in the issue, the readpngdata could be much better implemented using IOBuffers. I hadn’t properly learned how to use these in Julia at the time that I wrote it. (And read speed didn’t matter for what I needed it for.)

However, I suspect a lot of the slowdown comes from the fact that each frame is compressed as a png and then immediately decompressed. If you want to write something faster, it’s proabably be better to go with an uncompressed intermediate format.

Better would be to reduce the output framerate of ffmpeg with the r_out keyword argument. That way you don’t waste time on transferring frames that will not be used.