diff options
| author | Carl Hetherington <cth@carlh.net> | 2012-02-07 12:12:01 +0000 |
|---|---|---|
| committer | Carl Hetherington <cth@carlh.net> | 2012-02-07 12:12:01 +0000 |
| commit | 9ce56f6a2bdd076843a3b56d1cc27f3496b8528f (patch) | |
| tree | f055ba1a871846d7aa2173db51a023924feaf82b /hacks/python-playback/player.py | |
| parent | b072d4a885bf02f642650a1717c69252861cc5d0 (diff) | |
Move some hacks into the git repo.
Diffstat (limited to 'hacks/python-playback/player.py')
| -rw-r--r-- | hacks/python-playback/player.py | 112 |
1 files changed, 112 insertions, 0 deletions
diff --git a/hacks/python-playback/player.py b/hacks/python-playback/player.py new file mode 100644 index 000000000..5cc8da711 --- /dev/null +++ b/hacks/python-playback/player.py @@ -0,0 +1,112 @@ +import os +import threading +import subprocess +import shlex +import select +import film +import config +import mplayer + +class CommandLine: + def __init__(self): + self.position_x = 0 + self.position_y = 0 + self.output_width = None + self.output_height = None + self.mov = False + self.delay = None + self.dvd = False + self.dvd_title = 1 + self.content = None + self.extra = '' + self.crop_x = None + self.crop_y = None + self.crop_w = None + self.crop_h = None + self.deinterlace = False + self.aid = None + + def get(self, with_binary): + # hqdn3d? + # nr, unsharp? + # -vo x11 appears to be necessary to prevent unwanted hardware scaling + # -noaspect stops mplayer rescaling to the movie's specified aspect ratio + args = '-vo x11 -noaspect -ao pulse -noborder -noautosub -nosub -sws 10 ' + args += '-geometry %d:%d ' % (self.position_x, self.position_y) + + # Video filters (passed to -vf) + + filters = [] + + if self.crop_x is not None or self.crop_y is not None or self.crop_w is not None or self.crop_h is not None: + crop = 'crop=' + if self.crop_w is not None and self.crop_h is not None: + crop += '%d:%d' % (self.crop_w, self.crop_h) + if self.crop_x is not None and self.crop_x is not None: + crop += ':%d:%d' % (self.crop_x, self.crop_y) + filters.append(crop) + + if self.output_width is not None or self.output_height is not None: + filters.append('scale=%d:%d' % (self.output_width, self.output_height)) + + # Post processing + pp = [] + if self.deinterlace: + pp.append('lb') + + # Deringing filter + pp.append('dr') + + if len(pp) > 0: + pp_string = 'pp=' + for i in range(0, len(pp)): + pp_string += pp[i] + if i < len(pp) - 1: + pp += ',' + + filters.append(pp_string) + + if len(filters) > 0: + args += '-vf ' + for i in range(0, len(filters)): + args += filters[i] + if i < len(filters) - 1: + args += ',' + args += ' ' + + if self.mov: + args += '-demuxer mov ' + if self.delay is not None: + args += '-delay %f ' % float(args.delay) + if self.aid is not None: + args += '-aid %s ' % self.aid + + args += self.extra + + if self.dvd: + data_specifier = 'dvd://%d -dvd-device \"%s\"' % (self.dvd_title, self.content) + else: + data_specifier = '\"%s\"' % self.content + + if with_binary: + return 'mplayer %s %s' % (args, data_specifier) + + return '%s %s' % (args, data_specifier) + +def get_player(film, format): + cl = CommandLine() + cl.dvd = film.dvd + cl.dvd_title = film.dvd_title + cl.content = film.content + cl.crop_w = film.width - film.left_crop - film.right_crop + cl.crop_h = film.height - film.top_crop - film.bottom_crop + cl.position_x = format.x + if format.external: + cl.position_x = format.x + config.LEFT_SCREEN_WIDTH + cl.position_y = format.y + cl.output_width = format.width + cl.output_height = format.height + cl.deinterlace = film.deinterlace + cl.aid = film.aid + return mplayer.Player(cl.get(False)) + |
