how to create nice videos

19 views
Skip to first unread message

Ondrej Certik

unread,
Jul 9, 2009, 10:56:22 AM7/9/09
to hpfem
Hi,

let me share my latest experience with creating videos (I know some
people like Sameer are interested in that).

So here is the video done in visit:

http://www.youtube.com/watch?v=D0vqFHg2Fnk

watch the movie in HD quality (click on the "HD" button in the youtube
player). Notice the camera fly-by, I think this would be especially
cool in the flow simulations, where you want to watch some vertex or
turbulence or something for a while and then zoom out etc.

This was converted from a set of png files by:

ffmpeg -i frame%04d.png -r 15 -vcodec copy mhd.avi

Here is a script that uses VisIt to produce the png files:

-------------------
print "starting"
OpenDatabase("/netscratch/ondrej/vtk/frame*.vtk database")
AddPlot("Pseudocolor", "C")
p = PseudocolorAttributes()
p.min, p.minFlag = 0.174630617373, 1
p.max, p.maxFlag = 2.23176607373, 1
SetPlotOptions(p)
print "drawing"
DrawPlots()
v1 = View2DAttributes()
v1.windowCoords = (-2, 2, -2, 2)
v2 = View2DAttributes()
v2.windowCoords = (-1.05, -0.85, -0.10, 0.10)
cpts = [v1, v1, v2]
print cpts
x = [0., 0.5, 1.]

def animate():
print "animating"
s = SaveWindowAttributes()
s.format = s.PNG
s.fileName = "frame"
s.width, s.height = 1024,768
s.screenCapture = 0
SetSaveWindowAttributes(s)
nsteps = TimeSliderGetNStates()
for i in range(nsteps):
t = float(i) / float(nsteps - 1)
c = EvalCubicSpline(t, x, cpts)
SetTimeSliderState(i)
print c
SetView2D(c)
SaveWindow()
print "done"

animate()
-------------------

run it with:

visit -cli -s video_script.py

as you can see from the first line, it expects a set of VTK files in
the directory /netscratch/ondrej/vtk/frame*.vtk.

To produce those vtk files, I wrote this simple library:

http://certik.github.com/visit_writer/

and here is the script that takes the data from the simulation (in .h5
format) and uses the visit_writer library (above) to create the vtk
files:

http://github.com/certik/mhd/blob/9d5fcaa20067701222fba9443affa834ed8dd86f/plot.py

You can clone the whole git repository using:

git clone git://github.com/certik/mhd.git

it's just couple scripts. To create the .h5 file with the data, I
wrote this script:

http://github.com/certik/mhd/blob/9d5fcaa20067701222fba9443affa834ed8dd86f/readbin3.py

it produces python pickle files, that I then converted them to an h5
format using this older revision of plot.py:

http://github.com/certik/mhd/blob/d1184d35ca2b1f9e486f449a11285e45df3223f0/plot.py


So with hermes, I suggest to take the solution as a lin file (in C++),
or just the linearizer output in Python, then produce vtk files out of
it. And then use mayvi or visit for any kinds of nice animations. It's
very flexible, the vtk format contains all the data and you then tell
the visualizer how you want them to be visualized.

I'll probably write the exporters to vtk for my own fluid dynamics
stuff and post patches to hermes.

Ondrej

Pavel Solin

unread,
Jul 12, 2009, 11:23:41 AM7/12/09
to hp...@googlegroups.com
Hi Ondrej,
  I have been converting linearizer files into enumerated bitmaps
and then using mencoder to create AVI movies. Does your 
approach have any advantages, or should we support both 
of them? This discussion is timely since I am going to 
create a separate example dedicated to creating videos 
soon.

Thanks,

Pavel
--
Pavel Solin
University of Nevada, Reno
http://hpfem.math.unr.edu/people/pavel/
Hermes project: http://hpfem.org/
FEMhub project: http://femhub.org/

Ondrej Certik

unread,
Jul 12, 2009, 12:28:43 PM7/12/09
to hp...@googlegroups.com
On Sun, Jul 12, 2009 at 9:23 AM, Pavel Solin<so...@unr.edu> wrote:
> Hi Ondrej,
>   I have been converting linearizer files into enumerated bitmaps
> and then using mencoder to create AVI movies. Does your
> approach have any advantages, or should we support both
> of them? This discussion is timely since I am going to
> create a separate example dedicated to creating videos
> soon.

One thing is the video quality, e.g. I noticed when you converted the
bitmaps, you encoded the avi file using a low quality compression, so
it looks ugly sometimes. I don't know if my approach (ffmpeg -i
frame%04d.png -r 15 -vcodec copy mhd.avi) is the best, but it does
produces high quality videos.

As to the other things -- essentially we use hermes' opengl
visualisation, which is good enough for many purposes. But sometimes
as I said, I would like to fly by, e.g. zoom into some part, zoom out,
etc. For that, I would export to vtk and use some external program,
like visit, or mayavi.

It's on my todo to do it for my MHD simulations.

Ondrej

Jakub Cerveny

unread,
Jul 12, 2009, 12:33:05 PM7/12/09
to hp...@googlegroups.com
> One thing is the video quality, e.g. I noticed when you converted the
> bitmaps, you encoded the avi file using a low quality compression, so
> it looks ugly sometimes. I don't know if my approach (ffmpeg -i
> frame%04d.png -r 15 -vcodec copy mhd.avi) is the best, but it does
> produces high quality videos.

You are both using essentially the same thing to encode the video
(MPEG4). The quality can be controlled by the bitrate which can be set
on the command line. The better quality, the larger the resulting
video file.

Jakub

Ondrej Certik

unread,
Jul 12, 2009, 12:53:48 PM7/12/09
to hp...@googlegroups.com

Yes, but unfortunately I totally failed to convince mencoder to
produce higher quality videos by forcing the bitrate. By using the
"-vcodec copy" trick above, it works for me.

Ondrej

Jakub Cerveny

unread,
Jul 12, 2009, 12:56:13 PM7/12/09
to hp...@googlegroups.com
> Yes, but unfortunately I totally failed to convince mencoder to
> produce higher quality videos by forcing the bitrate. By using the
> "-vcodec copy" trick above, it works for me.

I am using something like this (see man mplayer at the end)

-ovc lavc -lavcopts vcodec=mpeg4:vbitrate=3200

and it works.

Jakub

Reply all
Reply to author
Forward
0 new messages