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

I have the following code:

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?

This thread might be of use:

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…

Thanks for the link!

I use this code now:

# 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.