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

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

PYTHON. Fixed playback rate of double pass in movie encoding. Movies should now play with any player with the correct playback rate

File size: 2.2 KB
Line 
1import numpy as np
2import subprocess
3from os import system
4
5class VideoSink(object) :
6
7    def __init__( self, size, filename="output", rate=10, byteorder="bgra") :
8            self.size = size
9            cmdstring  = ('mencoder',
10                    '/dev/stdin',
11                    '-demuxer', 'rawvideo',
12                    '-rawvideo', 'w=%i:h=%i'%size[::-1]+":fps=%i:format=%s"%(rate,byteorder),
13                    '-o', filename+'_raw.avi',
14                    '-nosound',
15                    '-ovc', 'x264',
16#                    '-ovc', 'lavc',
17                    )
18            self.p = subprocess.Popen(cmdstring, stdin=subprocess.PIPE, shell=False)
19
20    def run(self, image) :
21            #assert image.shape[0:2] == self.size
22            self.p.stdin.write(image.tostring())
23
24    def first_pass(self,filename="output",quality=False,rate=10) :
25
26
27             bitrate="7200"
28             if quality:bitrate="50000"
29             cmdstring  = ('mencoder',
30                     filename+'_raw.avi',
31                     '-of', 'rawvideo',
32                     '-nosound',
33                     '-ofps',str(rate),
34                     '-ovc', 'x264',
35                     '-x264encopts', 'subq=1:frameref=1:bitrate='+bitrate+':bframes=1:pass=1',
36                     '-vf', 'scale=1280:720',
37                     '-o', filename+'_first.264'
38                    )
39             subprocess.call(cmdstring,shell=False)
40
41    def second_pass(self,filename="output",quality=False,rate=10) :
42             bitrate="7200"
43             if quality:bitrate="50000"
44             cmdstring  = ('mencoder',
45                     filename+'_first.264',
46                     '-of', 'rawvideo',
47                     '-nosound',
48                     '-ofps',str(rate),
49                     '-ovc', 'x264',
50                     '-x264encopts', 'subq=6:frameref=5:bitrate='+bitrate+':me=umh:partitions=all:bframes=1:me_range=16:cabac:weightb:deblock:pass=2',
51                     '-vf', 'scale=1280:720',
52                     '-o', filename+'.avi'
53                    )
54             system('rm -f '+filename+'_raw.avi')
55             subprocess.call(cmdstring,shell=False)
56             system('rm -f '+filename+'_first.264')
57
58    def close(self) :
59            self.p.stdin.close()
60            self.p.wait()
61
Note: See TracBrowser for help on using the repository browser.