I think we were using gnuplot
for decades. But still there is no good way to get a good video output from gnuplot
, am I right? What I did is made around 30,000 images (I had to make it with good quality too, to get video clarity), then used ffmpeg
to make the video:
ffmpeg -f image2 -r 10.0 -i capture.%d.png -qscale 1 filename.mp4
But some time I get stuck in between or it takes too long time. We may always need a video output with high quality and low file size, why no one is attempting to do anything, or is there any other method to make video out put from gnuplot
? I am really struggling to make high quality videos with gnuplot
.
You can pipe the output of gnuplot
directly to ffmpeg
without storing the images on the hard drive. For that you need to tell ffmpeg
what format and resolution it has to expect from the pipe, since it can not guess it alone from the extension etc. now. Here is an example:
gnuplot animation.plt | ffmpeg -f png_pipe -s:v 800x600 -i pipe: out.mp4
I used the code from here with some minor modifications.
animation.plt
#!/usr/bin/gnuplot
#
# Creating an animation gif of the Bessel function
# NOTE: this files creates multiple png images, the gif file is then created
# using GIMP
#
# AUTHOR: Hagen Wierstorf
reset
set terminal pngcairo size 800,600 enhanced font 'Verdana,10'
# color definitions
set palette rgb 3,9,9
unset key; unset colorbox; unset border; unset tics
set lmargin at screen 0.03
set bmargin at screen 0
set rmargin at screen 0.97
set tmargin at screen 1
set parametric
# Bessel function, which is moving in time
bessel(x,t) = besj0(x) * cos(2*pi*t)
# calculate the zeros for the bessel function (see Watson, "A Treatise on the
# Theory of Bessel Functions", 1966, page 505)
n = 6 # number of zeros
k = (n*pi-1.0/4*pi)
u_0 = k + 1/(8*k) - 31/(384*k)**3 + 3779/(15360*k)**5
set urange [0:u_0]
set vrange[0:1.5*pi]
set cbrange [-1:1]
set zrange[-1:1]
set isosamples 200,100
set pm3d depthorder
set view 40,200
# initializing values for the loop and start the loop
t = 0
end_time = 1
#system('mkdir -p animation')
load 'bessel.plt'
bessel.plt
# bessel loop
t = t + 0.02
#outfile = sprintf('animation/bessel%03.0f.png',50*t)
#set output outfile
splot u*sin(v),u*cos(v),bessel(u,t) w pm3d ls 1
if(t<end_time) reread;
Gives you a video which looks like this. (This is downscaled and transcoded gif just for demo purposes)
You can also play around with ffmpeg encoder parameters. here only default video encoder config is used.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With