upload_video_2.py 1.1 KB

12345678910111213141516171819202122232425
  1. def get_video_info(filename):
  2. res = {}
  3. try:
  4. terminalResult = subprocess.Popen(["ffprobe", filename],
  5. stdout=subprocess.PIPE,
  6. stderr=subprocess.STDOUT)
  7. for x in terminalResult.stdout.readlines():
  8. # Duration: 00:00:59.51, start: 0.000000, bitrate: 435 kb/s
  9. m = re.search(r'duration: (\d\d:\d\d:\d\d\.\d\d),', str(x), flags=re.IGNORECASE)
  10. if m is not None:
  11. res['duration'] = m.group(1)
  12. # Video: h264 (Constrained Baseline) (avc1 / 0x31637661), yuv420p, 480x268
  13. m = re.search(r'video:\s.*\s(\d+)x(\d+)\s', str(x), flags=re.IGNORECASE)
  14. if m is not None:
  15. res['width'] = m.group(1)
  16. res['height'] = m.group(2)
  17. finally:
  18. if 'width' not in res:
  19. print(("ERROR: 'ffprobe' not found, please install "
  20. "'ffprobe' with one of following methods:"))
  21. print(" sudo apt-get install ffmpeg")
  22. print("or sudo apt-get install -y libav-tools")
  23. return res