# How to set the frame-rate of a gif file?

**URL:** <https://discourse.julialang.org/t/how-to-set-the-frame-rate-of-a-gif-file/120392>\
**Category:** General Usage\
**Tags:** question\
**Created:** [September 28, 2024, 4:02pm UTC](https://discourse.julialang.org/t/how-to-set-the-frame-rate-of-a-gif-file/120392 "2024-09-28T16:02:57Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![ufechner7](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ufechner7/32/51363_2.png) [@ufechner7](https://discourse.julialang.org/u/ufechner7)\
**Post date:** [September 28, 2024, 4:02pm UTC](https://discourse.julialang.org/t/how-to-set-the-frame-rate-of-a-gif-file/120392/1 "2024-09-28T16:02:57Z")

</div>

I have the following code:

```julia
using FileIO, ImageIO, Colors, FixedPointNumbers, Images

folder = "video"

A = Array{Array{RGB{Normed{UInt8,8}},2},1}()
files = readdir(folder)
pngfiles = filter(file->(occursin.("png",file)), files )

for j in 0:(length(pngfiles)-1)
    global A
    local img
    img_path = folder*"/"*"img-"*lpad(j,4,"0")*".png"
    img=FileIO.load(img_path)
    if j==0
        A = img
    else
        A = cat(A, img, dims=3)
    end
    if j%10 == 0
        println("Processing image $img_path of $(length(pngfiles)-1)")
    end
end

FileIO.save(folder * "/Tether.gif", A)
println("\nGif file $(folder * "/Tether.gif") created!") 

```

It creates a GIF file from the `.png` files in the folder video.

But if I replay it, it is replayed with 10 fps, even though it should be replayed with 20 fps.

How can I set the frame rate?

---

<div class="post-metadata">

**Author:** ![rsenne](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rsenne/32/212973_2.png) [@rsenne](https://discourse.julialang.org/u/rsenne)\
**Post date:** [September 28, 2024, 5:34pm UTC](https://discourse.julialang.org/t/how-to-set-the-frame-rate-of-a-gif-file/120392/2 "2024-09-28T17:34:17Z")

</div>

This thread might be of use:

> [@Create gif from saved images](https://discourse.julialang.org/t/create-gif-from-saved-images/85146):
>
> I have 3000 images.They are the result of calculations on Julia. This images is a graphic of probablity density function (PDF), time series and lyapunov spectrum. How can i create gif from images PDF, time series and lyapunov spectrum ? Images of PDF have name type of “\* PDF” where \* is number. Similarly for time series and Lyapunov spectrum that is “\* timeseries”; “\* spectrum”.

It would require you use FFMPEG.jl and not FileIO but seems like it would work. I tried to look at the documentation for FileIO.jl to find something like a “fps” kwarg but couldn’t find one though I would imagine something like that would exist…

---

<div class="post-metadata">

**Author:** ![ufechner7](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ufechner7/32/51363_2.png) [@ufechner7](https://discourse.julialang.org/u/ufechner7)\
**Post date:** [September 29, 2024, 10:41am UTC](https://discourse.julialang.org/t/how-to-set-the-frame-rate-of-a-gif-file/120392/3 "2024-09-29T10:41:31Z")

</div>

Thanks for the link!

I use this code now:

```julia
# create a gif and an mp4 file from the images in the folder "video"
using Colors, FixedPointNumbers, Images, FFMPEG

folder = "video"
framerate = 20
gifname = joinpath(folder, "Tether.gif")
mp4name = joinpath(folder, "Tether.mp4")

rm(gifname, force=true)
rm(mp4name, force=true)

FFMPEG.ffmpeg_exe(`-framerate $(framerate) -f image2 -i $(folder)/img-%4d.png -c:v libx264 -pix_fmt yuv420p -y $(mp4name)`)
FFMPEG.ffmpeg_exe(`-i $(mp4name) -filter_complex "[0]split[a][b]; [a]palettegen[palette]; [b][palette]paletteuse" -y $(gifname)`)

println("\nGif file $(gifname) created!")
println("Mp4 file $(mp4name) created!")

```

which creates both a gif file and an mp4 file.
