From aa929ec24f8e4763ae7e84b7d7f5bb7e92fcde5e Mon Sep 17 00:00:00 2001 From: Tom Breloff Date: Wed, 30 Nov 2016 09:50:28 -0500 Subject: [PATCH] buildanimation: mov and mp4 --- src/Plots.jl | 2 ++ src/animation.jl | 15 ++++++++++----- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/src/Plots.jl b/src/Plots.jl index 0761858c..65434b81 100644 --- a/src/Plots.jl +++ b/src/Plots.jl @@ -80,6 +80,8 @@ export Animation, frame, gif, + mov, + mp4, animate, @animate, @gif, diff --git a/src/animation.jl b/src/animation.jl index aaadffb2..1d2822f6 100644 --- a/src/animation.jl +++ b/src/animation.jl @@ -17,6 +17,8 @@ function frame{P<:AbstractPlot}(anim::Animation, plt::P=current()) end giffn() = (isijulia() ? "tmp.gif" : tempname()*".gif") +movfn() = (isijulia() ? "tmp.mov" : tempname()*".mov") +mp4fn() = (isijulia() ? "tmp.mp4" : tempname()*".mp4") type FrameIterator itr @@ -51,11 +53,14 @@ immutable AnimatedGif filename::String end -function gif(anim::Animation, fn = giffn(); fps::Integer = 20, loop::Integer = 0) +gif(anim::Animation, fn = giffn(); kw...) = buildanimation(anim.dir, fn; kw...) +mov(anim::Animation, fn = movfn(); kw...) = buildanimation(anim.dir, fn; kw...) +mp4(anim::Animation, fn = mp4fn(); kw...) = buildanimation(anim.dir, fn; kw...) + +function buildanimation(animdir::AbstractString, fn::AbstractString; + fps::Integer = 20, loop::Integer = 0) fn = abspath(fn) - try - # high quality speed = round(Int, 100 / fps) file = joinpath(Pkg.dir("ImageMagick"), "deps","deps.jl") @@ -63,7 +68,7 @@ function gif(anim::Animation, fn = giffn(); fps::Integer = 20, loop::Integer = 0 include(file) end # prefix = get(ENV, "MAGICK_CONFIGURE_PATH", "") - run(`convert -delay $speed -loop $loop $(joinpath(anim.dir, "*.png")) -alpha off $fn`) + run(`convert -delay $speed -loop $loop $(joinpath(animdir, "*.png")) -alpha off $fn`) catch err warn("""Tried to create gif using convert (ImageMagick), but got error: $err @@ -71,7 +76,7 @@ function gif(anim::Animation, fn = giffn(); fps::Integer = 20, loop::Integer = 0 Will try ffmpeg, but it's lower quality...)""") # low quality - run(`ffmpeg -v 0 -framerate $fps -loop $loop -i $(anim.dir)/%06d.png -y $fn`) + run(`ffmpeg -v 0 -framerate $fps -loop $loop -i $(animdir)/%06d.png -y $fn`) # run(`ffmpeg -v warning -i "fps=$fps,scale=320:-1:flags=lanczos"`) end