Difference between revisions of "New:Making videos"

From Yade

 
 
Line 1: Line 1:
 
[[Category:New to linux?]]{{New to linux menu}}
 
[[Category:New to linux?]]{{New to linux menu}}
  +
=Using VTKRecorder and Paraview=
=Creating sequence of images (snapshots)=
 
==Using SQLiteRecorder (with offscreen rendering)==
 
=== The simple way ===
 
scripts/simple-scene-player.py saves simulation to a .sqlite file, then using the utils.qtMakeVideo, it creates the video automatically:
 
<source lang="python">
 
from yade import qt
 
qt.createVideo('/tmp/player.sqlite','/tmp/player.ogg',
 
'/tmp/qglviewerState.xml',stride=10,fps=12)
 
</source>
 
If you run it in Xvfb (see below), you will get the video offscreen.
 
   
  +
Use VTKRecorder engine (see docs), it will save snapshots to *.vtu files. Those can be opened with paraview (http://www.paraview.org), then rendered and saved as video directly.
=== The complicated and customizable way ===
 
scripts/simple-scene-player.py is the [[SimpleSceneTutorial]] with the engine
 
<source lang="python">
 
  StandAloneEngine('SQLiteRecorder',{'recorders':['se3','rgb'],'dbFile':'/tmp/player.sqlite','iterPeriod':100})
 
</source>
 
added. Once the simulation is run, you will have one single .sqlite file containing the simulation. You can load this file in the simulation player.
 
 
For automatic rendering of the saved simulation, you need
 
 
* saved simulation states in the .sqlite file
 
* saved GL view state: when running simulation, setup the view you want and press Alt-S. This will save view state (dimensions, camera position etc) into /tmp/qglviewerState.xml. You can rename this file if you want to keep it.
 
* A small script (let's save it to /tmp/play.py) that will tell yade how to proceed:
 
<source lang="python">
 
from yade import qt
 
qt.runPlayer('/tmp/player.sqlite','/tmp/g','/tmp/qglviewerState.xml',stride=3)
 
quit()
 
</source>
 
where the arguments are
 
* saved simulation,
 
* basename for snapshot images (/tmp/g-0001.png, /tmp/g-0002.png etc.)
 
* saved viewer state (may be omitted or "" to use default)
 
* stride tells the player to take only every 3rd state (may be omitted as well).
 
Now running
 
 
yade-trunk /tmp/play.py
 
 
should do the trick (move your mouse if it seems to be stuck...).
 
 
For offscreen, install the xvfb package and run
 
 
Xvfb :1 -ac -screen 0 1024x768x16
 
 
(:1 is display number, 1024x768 is the display dimension and 16 is color depth; -ac disables access control to the display) Xvfb creates a virtual display (that cannot be seen) but the programs runs as normally. You may have problems due to GL acceleration - try it out. Then tell yade to run on that display:
 
 
DISPLAY=:1 yade-trunk /tmp/play.py
 
 
==Using Simulation Player ==
 
Add PositionOrientationRecorder to your engines (you can do it like this with PythonUI, without any compilation:
 
 
sim='/path/to/your/simulation.xml'
 
o.load(sim)
 
por=StandAloneEngine("PositionOrientationRecorder") # instantiate the engine
 
por['outputFile']='/tmp/xyz' ## will create files /tmp/xyz_0000010 and so on
 
por['interval']=10
 
o.engines=o.engines+[por] # add our recorder to engines
 
o.save(sim) # save what we loaded, with the last engine added this time
 
 
Then, during simulation, files /tmp/xyz_000010, /tmp/xyz_000020, ... will be created, until you stop the simulation. These files contain se3 (position and orientation, i.e. 7 numbers) per line. First line is body #0, second is body #1 etc. '''There is no need to add first line with line count as it used to be'''.
 
 
Once you have those files, open Simulation Player, give it name of your simulation (<code>/path/to/your/simulation.xml</code> in the previous example). Given you have PositionOrientationRecorder in your simulation, the player is (now) smart enough to find out where you were saving your snapshots - you don't have to fill in ''Base Name'' and ''Directory'' by hand (unless you want to override those), it will be filled once you load the simulation (it finds for all files with appropriate name and sorts them). The load simulation. Check ''Save Snapshots'' and the animation will be saved (by default into <code>/tmp/frame-0000.png</code>, <code>/tmp/frame-0001.png</code> etc). Make sure the 3d window is always in front; otherwise, snapshots will be garbled.
 
 
Proceed as described above with mencoder to get video.
 
   
 
=Taking video from the screen=
 
=Taking video from the screen=

Latest revision as of 08:45, 29 April 2010

New to linux?

Using VTKRecorder and Paraview

Use VTKRecorder engine (see docs), it will save snapshots to *.vtu files. Those can be opened with paraview (http://www.paraview.org), then rendered and saved as video directly.

Taking video from the screen

With xvidcap and mencoder it was possible to record all the videos presented on this website.

For debian/ubuntu 'xvidcap' and 'mencoder' can be found here:

deb http://www.debian-multimedia.org etch main

You need to add above line to your /etc/apt/sources.list, but first check if 'xvidcap' is already available for your linux distribution. You can also try to download xvidcap from its home page. Program 'mencoder' is a part of mplayer package, from debian-multimedia. And 'convert' is from imagemagick package, every linux distribution has it.

Running xvidcap is easy, so when you have all the pictures, you can convert them to .png and then encode them to make a video:

for m in *.xwd; do convert $m `basename $m .xwd`.png; rm $m; done
mencoder "mf://*.png" -o video.mpg -mf fps=25 -ovc lavc -lavcopts vcodec=msmpeg4v2

The codec msmpeg4v2 is by my experience most popular on windows, and I had least amount of problems with it when I wanted a video to run on some windows machine.