JuliaPlots / Plots.jl

Powerful convenience for Julia visualizations and data analysis
https://docs.juliaplots.org
Other
1.84k stars 355 forks source link

mp4 resolution #2158

Open jw3126 opened 5 years ago

jw3126 commented 5 years ago

Is there a way to control the resolution of mp4 output? Here is what I tried:

julia> using Plots

julia> gr(windowsize=(100,100))
Plots.GRBackend()

julia> path = tempname() * ".mp4"
"/tmp/jl_haa4lh.mp4"

julia> anim = @animate for i in 1:100
           plot(randn(10))
       end
Animation("/tmp/jl_FqJLPd", ["000001.png", "000002.png", "000003.png", "000004.png", "000005.png", "000006.png", "000007.png", "000008.png", "000009.png", "000010.png"  …  "000091.png", "000092.png", "000093.png", "000094.png", "000095.png", "000096.png", "000097.png", "000098.png", "000099.png", "000100.png"])

julia> mp4(anim, path)
ERROR: failed process: Process(`/home/jan/.julia/packages/FFMPEG/9JQpZ/deps/usr/bin/ffmpeg -v 0 -framerate 20 -loop 0 -i /tmp/jl_FqJLPd/%06d.png -pix_fmt yuv420p -y /tmp/jl_haa4lh.mp4`, ProcessExited(1)) [1]

OTOH it works with gif:

julia> gif(anim, path * ".gif")
┌ Info: Saved animation to 
└   fn = "/tmp/jl_haa4lh.mp4.gif"
Plots.AnimatedGif("/tmp/jl_haa4lh.mp4.gif")
grahamas commented 5 years ago

I think this may be the same problem I'm running into. I investigated the error and got:

[libx264 @ 0x1a1f980] width not divisible by 2 (799x800)", "Error initializing output stream 0:0 -- Error while opening encoder for output stream #0:0 - maybe incorrect parameters such as bit_rate, rate, width or height", "Conversion failed!"]

However, I'm manually setting the plot size to be 800x800.

ssfrr commented 4 years ago

I just ran into this as well. This is hard to see what's going on because the call to ffmpeg throws a ProcessError but doesn't say what the problem is (it seems that ffmpeg is being run with -v 0 which disables error messages).

In my case I got it to work by setting dpi=101 which for my resolution (500x500) happened to give an even height and width. The return value seems to be of type AnimatedGif but it created the mp4 video.

hdrake commented 1 year ago

This bug is a result of the more fundamental bug discussed in https://github.com/JuliaPlots/Plots.jl/issues/2303