source: trunk/UTIL/PYTHON/videosink.py @ 440

Last change on this file since 440 was 430, checked in by acolaitis, 14 years ago


PYTHON

Added... movies !


Example :


pp.py -f wrfout_d01_9999-01-01_07:11:40 --var upward --lat 50 --time 5 -m 0 -M 10 -c Spectral_r --div 20 --ymax 200

will generate a 2D altitude-latitude plot of upward tracer concentration, whereas :

pp.py -f wrfout_d01_9999-01-01_07:11:40 --var upward --lat 50 -m 0 -M 10 -c Spectral_r --div 20 --ymax 200

will generate a movie of the previous plot, along the time axis (default axis for movies for now).


Requirements :


The way the movie maker is written is very light-weight and fast, as no intermediary pictures are saved. The data is buffered and streamed right into an encoder.
I could not make this work with ffmpeg... So you MUST have mencoder installed. It is not on the farm... It is on ciclad, and I know that Aymeric installed it on his machine (at least before getting Ulrich).


Known problems :


I spent litteraly all day making this work, but the option is still basic for now, i.e. it is not yea possible to use -w with movies, or 1D plot movies. (several other stuff are not possible yet, like title specification, axis limits (ylim,xlim), etc... I know how to make it work, I just need some time.

Default name for the output movie is "test.avi" for now.

Tested with LES data without projections. Not test on meso or gcm in mapmode 1.


Details :


A videosink.py
----------------- New class that contains some routines for video stuff. This could either be transformed in a function in an other .py, or other functions could be added to this class to make it more usefull.

M 427 mymath.py
----------------- New routines to convert figures to RGBA data (4-dimensions arrays of pixel data) and figures to PIL images.

M * 428 planetoplot.py
----------------- Added support for movies of 2D plots without overlines

M * 428 myplot.py
----------------- Minor stuff about LES and dumpbdy for W. This could be made in a much cleaner way... maybe later.

File size: 750 bytes
Line 
1import numpy as np
2import subprocess
3
4class VideoSink(object) :
5
6    def __init__( self, size, filename="output", rate=10, byteorder="bgra") :
7            self.size = size
8            cmdstring  = ('mencoder',
9                    '/dev/stdin',
10                    '-demuxer', 'rawvideo',
11                    '-rawvideo', 'w=%i:h=%i'%size[::-1]+":fps=%i:format=%s"%(rate,byteorder),
12                    '-o', filename+'.avi',
13                    '-ovc', 'lavc',
14                    )
15            self.p = subprocess.Popen(cmdstring, stdin=subprocess.PIPE, shell=False)
16
17    def run(self, image) :
18            #assert image.shape[0:2] == self.size
19            self.p.stdin.write(image.tostring())
20    def close(self) :
21            self.p.stdin.close()
Note: See TracBrowser for help on using the repository browser.