Javis.jl icon indicating copy to clipboard operation
Javis.jl copied to clipboard

[BUG] Gif not matching spec'd framerate

Open agerlach opened this issue 4 years ago • 6 comments

Describe the bug

For certain combinations for number of frames and framerate, a resulting gif will not have the correct framerate. It is correct sometimes. I cannot seem to find a pattern of why.

To Reproduce

  1. Julia Version (i.e. output of julia -v): v1.5.3
  2. Operating system (Mac, Linux, Windows): MacOS 10.15
  3. Javis version (i.e output of ] status Javis in the REPL) 0.3.3
  4. Minimum working code example that led to bug:
using Javis

function ground(args...)
    background("black")
    sethue("white")
end

function printframe(v,o,f)
    fontsize(100)
    Javis.text("$f",0,0, valign=:center, halign=:center)
end

function makegif(nframes, framerate)
    video = Video(400,400)
    Background(1:nframes, ground)

    frame = Object(1:nframes, printframe)

    Javis.render(video; pathname = "$(nframes)frames_$(framerate)framerate.gif", framerate = framerate)
end

makegif(10, 1) #correct
makegif(1000, 1) #correct 
makegif(1000, 100) #wrong, should only take 10s, seems like 100s

Expected Behavior and Actual Behavior

Last gif created should be 10 s long. 1000 frames / 100 fps. It is 100s long.

agerlach avatar Dec 17 '20 22:12 agerlach

Hey @agerlach - thanks for opening this issue. At first look, this has to do with FFMPEG.jl which is what we use to create renders. I did some googling and it seems like one has to do some interesting trickery with FFMPEG to get the functionality you want: https://unix.stackexchange.com/questions/562869/ffmpeg-video-at-100-fps-with-300-images-gives-13-seconds

I will take a deeper look at this soon. Thanks for providing the code and the example - I was able to replicate exactly the same issue you ran into.

TheCedarPrince avatar Dec 18 '20 03:12 TheCedarPrince

to get the functionality you want

I'm a bit confused by this. Is this not the functionality you would expect?

agerlach avatar Dec 18 '20 13:12 agerlach

@agerlach - oh no, this is definitely a bug as I was expecting the same process you thought to work as well: e.g. 1000 frames at a framerate of 100 should result in a 10s gif. Instead, it is not. I have never run into this as typically, most gifs I create are at a framerate of 30 and below. Curiously, if I use an mp4 instead of a gif, the expected behavior does work:

using Javis

function ground(args...)
    background("black")
    sethue("white")
end

function printframe(v,o,f)
    fontsize(100)
    Javis.text("$f",0,0, valign=:center, halign=:center)
end

function makemp4(nframes, framerate)
    video = Video(400,400)
    Background(1:nframes, ground)

    frame = Object(1:nframes, printframe)

    Javis.render(video; pathname = "$(nframes)frames_$(framerate)framerate.mp4", framerate = framerate)
end

makemp4(1000, 100) # Takes 10s as expected

I'll keep exploring why gifs do not render to the expected time.

TheCedarPrince avatar Dec 18 '20 17:12 TheCedarPrince

Bump @TheCedarPrince any news on this?

Wikunia avatar Jan 09 '21 15:01 Wikunia

Haven't had time to investigate @Wikunia - it is still standing bug for Javis. Nothing wrong with FFMPEG.jl but rather I have to dig deeper into FFMPEG as there is a way around this based on my earlier message's link. Just not sure how to best address it yet.

TheCedarPrince avatar Jan 10 '21 03:01 TheCedarPrince

I am getting the same bug. seems to work up to 50 fps.

jotaivalkoski avatar Apr 10 '21 19:04 jotaivalkoski