# Record video

**URL:** <https://discourse.julialang.org/t/record-video/81289>\
**Category:** New to Julia\
**Tags:** question, video, glmakie\
**Created:** [May 18, 2022, 11:20pm UTC](https://discourse.julialang.org/t/record-video/81289 "2022-05-18T23:20:03Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![vahhab70](https://avatars.discourse-cdn.com/v4/letter/v/dfb087/32.png) [@vahhab70](https://discourse.julialang.org/u/vahhab70)\
**Post date:** [May 18, 2022, 11:20pm UTC](https://discourse.julialang.org/t/record-video/81289/1 "2022-05-18T23:20:03Z")

</div>

Hello,

I am new in Julia and I would appreciate your help. I want to record a video. It seems frames are accumulated during recording the frames:

using GLMakie  
using MAT  
file = matopen(“//home//arostami//Desktop//3D//sample\_vrtx\_1.mat”)  
vrtx=read(file, “vrtx”)  
scene=contour(vrtx[1,:,:,:],levels=[-7,7],colormap=:balance,alpha=0.2,colorrange=[-7,7])  
record(scene, “//home//arostami//Desktop//3D//kir.mp4”) do io  
for i in 1:100  
dat=vrtx[i,:,:,:]  
scene=contour!(dat,levels=[-7,7],colormap=:balance,alpha=0.2,colorrange=[-7,7])  
recordframe!(io)  
end  
end

I don’t know where the issue comes from. Thank you for your help in advance!

---

<div class="post-metadata">

**Author:** ![suavesito](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/suavesito/32/34386_2.png) [@suavesito](https://discourse.julialang.org/u/suavesito)\
**Post date:** [May 19, 2022, 1:44am UTC](https://discourse.julialang.org/t/record-video/81289/2 "2022-05-19T01:44:28Z")

</div>

Hi!

Foremost, I will recommend you to read [this PSA on quoting code](https://discourse.julialang.org/t/psa-how-to-quote-code-with-backticks/7530).

Second, what version of Julia and GLMakie are you running? That code looks outdated. You can look at the [documentation for animations](https://makie.juliaplots.org/v0.15.2/documentation/animation/index.html). You probably want something base on `Observable`.

Here is an example of how to use them:

```julia
julia> using GLMakie

julia> range = -2π:0.1:2π
-6.283185307179586:0.1:6.216814692820414

julia> mul = Observable(1.0)
Observable{Float64} with 0 listeners. Value:
1.0

julia> xy = lift(mul) do m
           [cos(m*x)*cos(m*y) for x=range, y=range]
       end
Observable{Matrix{Float64}} with 0 listeners. Value:
[1.0 0.9950041652780258 … 0.9861923022788637 0.9977982791785807; 0.9950041652780258 0.9900332889206209 … 0.9812654485325952 0.9928134438899342; … ; 0.9861923022788637 0.9812654485325952 … 0.9725752570740857 0.9840209821530128; 0.9977982791785807 0.9928134438899342 … 0.9840209821530128 0.9956014059317367]

julia> fig, ax, plot = contour(xy)

julia> framerate = 30
30

julia> multplier_iterator = LinRange(1.0, 10.0, 60)
60-element LinRange{Float64, Int64}:
 1.0,1.15254,1.30508,1.45763,1.61017,1.76271,1.91525,2.0678,2.22034,2.37288,…,8.62712,8.77966,8.9322,9.08475,9.23729,9.38983,9.54237,9.69492,9.84746,10.0

julia> record(fig, "cosx_cosy.mp4", multplier_iterator; framerate=framerate) do m
           mul[] = m # update multiplier and so the figure
       end
"cosx_cosy.mp4"

```

---

<div class="post-metadata">

**Author:** ![suavesito](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/suavesito/32/34386_2.png) [@suavesito](https://discourse.julialang.org/u/suavesito)\
**Post date:** [May 19, 2022, 1:59am UTC](https://discourse.julialang.org/t/record-video/81289/3 "2022-05-19T01:59:50Z")

</div>

Re-reading your question, maybe this changes fix your code?

```julia
using GLMakie
using MAT

file = matopen("/home/arostami/Deskto/3D/sample_vrtx_1.mat")
vrtx = read(file, "vrtx")
idx = Observable(1) # the index of the layer

#every time you do `idx[] = j`, for a `j`, then `data` will change to the corresponding layer
data = lift(idx) do i
    vrtx[i, :, :, :]
end

fig, ax, plot = contour( # just plot
    data,
    levels = [-7, 7],
    colormap = :balance,
    alpha = 0.2,
    colorrange = [-7, 7],
)

indexes = 1:1000
record(fig, "/home/arostami/Desktop/3D/kir.mp4", indexes) do i
    idx[] = i # you just need to update the layer number, and the plot will be updated
end

```

---

<div class="post-metadata">

**Author:** ![vahhab70](https://avatars.discourse-cdn.com/v4/letter/v/dfb087/32.png) [@vahhab70](https://discourse.julialang.org/u/vahhab70)\
**Post date:** [May 20, 2022, 6:08pm UTC](https://discourse.julialang.org/t/record-video/81289/4 "2022-05-20T18:08:51Z")

</div>

Thank you so much @suavesito . It is working now!
