JuliaIO/VideoIO.jl

Reading cropped frames

Opened this issue · 5 comments

Is it possible to read crops of frames from disk, say frame[1:100,300:500]? We have these large images that we would like to read as efficiently as possible. Only a specific area is relevant for the calculations, and so reading the full frame to discard tons of pixels isn't very nice.

It's a little out of scope of this package, but if they're TIFFs you can via mmaping
https://tamasnagy.com/TiffImages.jl/stable/examples/mmap_lazyio/#Memory-mapping-and-lazy-loading

May be possible for other image formats too

Or by images do you mean frames from a video file?

I mean frames from a video file. Currently I don't know how to read just portions of a frame. I am reading whole frames and discarding most pixels.

I don't think this is supported in VideoIO. It might be possible but would require looking into whether av_image_copy_to_buffer or an equivalent can be set to target a crop region (into an appropriate buffer size)

I also face the same issue; I want to crop my video in time too.
I have stocked the desired images and saved them on the computer. However, making a video of those images is not encoded correctly, and certain portions must be cut. I don't know why.
I am using the following code:
imgnames = filter(x->occursin("jpg", x), readdir()) # Populate list of all images and sort them based on first numerics
intstrings = map(x->split(x,".")[1],imgnames) # Extract index from filenames
p = sortperm(parse.(Int,intstrings)) #sort files numerically
imgstack = []
for imgname in imgnames[p]
push!(imgstack,load(imgname))
end

encoder_options = (crf=15, preset="fast")
VideoIO.save("video.mp4", imgstack, framerate=25, encoder_options=encoder_options)