PageRenderTime 39ms CodeModel.GetById 19ms RepoModel.GetById 1ms app.codeStats 0ms

/evmaker/player.py

https://github.com/lerosua/gmcore
Python | 61 lines | 51 code | 7 blank | 3 comment | 7 complexity | c118d98513ee9b202719ff732d365df2 MD5 | raw file
Possible License(s): GPL-2.0
  1. #!/usr/bin/env python
  2. # -*- coding: UTF-8 -*-
  3. import os
  4. import re
  5. import sys
  6. tmp_dir="/tmp/"
  7. preview_jpg_filename = "/tmp/00000001.jpg"
  8. class player():
  9. def get_length(self,filename):
  10. cmd='mplayer -identify -frames 0 2>/dev/null '+filename
  11. out = os.popen(cmd)
  12. for line in out:
  13. line = line.strip()
  14. if re.search("ID_LENGTH",line):
  15. return line[10:]
  16. return 0
  17. def get_info(self,filename):
  18. cmd='mplayer -identify -frames 0 2>/dev/null '+filename
  19. out = os.popen(cmd)
  20. length = 0
  21. width = 0
  22. height = 0
  23. for line in out:
  24. line = line.strip()
  25. if re.search("ID_LENGTH",line):
  26. length = line[10:]
  27. if re.search ("ID_VIDEO_WIDTH", line):
  28. width = line[15:]
  29. if re.search ("ID_VIDEO_HEIGHT", line):
  30. height = line[16:]
  31. return length,width,height
  32. def get_screenshot(self,filename):
  33. os.chdir(tmp_dir)
  34. cmd = "mplayer -ss 90 -noframedrop -nosound -vo jpeg -frames 1 2>/dev/null "+filename
  35. #out = os.popen(cmd)
  36. self.wait_run(cmd)
  37. return preview_jpg_filename
  38. def preview(self,filename,a_time,b_time):
  39. if b_time == "":
  40. self.run("mplayer","-osdlevel","3",filename)
  41. else:
  42. self.run("mplayer","-osdlevel","3","-ss",a_time,"-endpos",b_time,filename)
  43. def run(self,program, *args):
  44. pid = os.fork()
  45. if not pid:
  46. os.execvp(program,(program,)+args)
  47. def wait_run(self,cmd):
  48. pid = os.fork()
  49. if not pid:
  50. os.system(cmd)
  51. sys.exit(0)
  52. return os.wait()[0]