Hi @asinghvi17 ,
I’m trying to follow your advice for creating a scene and then just update it iteratively to avoid memory usage to increase until crash. I’m working with video, I would like to add a grid on each frames and extract them iteratively. Here you will find the leak I firstly followed to avoid memory leak Makie memory leak? but it seems that it’s not sufficient when using it on large video… With your advice my problem is to be able to extract from the scene the information corresponding to the image and replace it by another one… Thanks in advance for your help !
This piece of code is my MWE:
using VideoIO, FileIO
using GLMakie,AbstractPlotting, Makie
function save_png(img, i, grid)
fn=string(i)*".png"
scene = AbstractPlotting.image(rotr90(img), show_axis = false);
AbstractPlotting.linesegments!(scene, grid, color = "white", linewidth = 2, show_axis = false);
AbstractPlotting.save(fn, scene; resolution = (720,450))
close(GLMakie.global_gl_screen())
nothing
end
function ext_frames(vid_name::String, grid) ## to Add Grid and extract frames
io = VideoIO.testvideo(vid_name) ## for testing purposes
f = VideoIO.openvideo(io); ## Open the video
img = read(f); ## Take the first frame
n = 1
save_png(img,n, grid) ## Add grid and save the frame
while !eof(f) ## While the video is not finished
next_img = read!(f, img); ## Take the next frame
n = n + 1
save_png(next_img,n, grid)
end
close(f)
end
grid = Tuple{Float32,Float32}[(203.18451, 391.91782), (203.18451, 34.85404), (359.62997, 391.91782), (359.62997, 34.85404), (516.07544, 391.91782), (516.07544, 34.85404), (46.739048, 124.11998), (672.52094, 124.11998), (46.739048, 213.38593), (672.52094, 213.38593), (46.739048, 302.6519), (672.52094, 302.6519)]
ext_frames("annie_oakley",grid)
So the idea would be to keep the first part because in my real code I’m doing specific stuff there, but in the while loop I would like to change a bit the save_png function to create the scene with the image + the grid and then iteratively change the image under the grid and save it. Ideally I would like to couple this process with an encoder to recreate the video with the added grid.
Important note: I’m working with 30min videos at 30 fps so it’s a lot of frames to work with → all is about avoiding RAM usage and speed up the process of saving frames.