PageRenderTime 63ms CodeModel.GetById 26ms RepoModel.GetById 0ms app.codeStats 0ms

/VideoSplit.py

https://github.com/aminzai/Split-Video
Python | 64 lines | 38 code | 7 blank | 19 comment | 2 complexity | 9a758d52bba64efc493b4cb5fe92cd59 MD5 | raw file
  1. #/bin/python
  2. # -*- coding: UTF-8 -*-
  3. import os
  4. import sys
  5. import datetime
  6. import subprocess
  7. #Youtube video length (Default: 15min)
  8. yvl = 14
  9. #==COMMAND NOTE==
  10. #1:start time
  11. #2:end time
  12. #3:input file name
  13. #4:output file name
  14. #5:count id
  15. COMMAND = 'mencoder \
  16. -ss %s:00 \
  17. -endpos 00:%02d:00 \
  18. -oac copy -ovc copy \
  19. -of mpeg \
  20. -forceidx %s \
  21. -o %s_%02d.mpg'
  22. input_filename = sys.argv[1:]
  23. def getVideoLength(fileName):
  24. """
  25. input: file name
  26. return: video length (int)
  27. """
  28. getLengthCommand = "mplayer -vo null -ao null -frames 0 -identify %s 2>/dev/null \
  29. | grep ID_LENGTH=\
  30. | sed 's/^ID_LENGTH=//'" % (fileName)
  31. #print getLengthCommand
  32. stdout,stdin = subprocess.Popen(args=getLengthCommand,
  33. shell=True,
  34. stdout=subprocess.PIPE
  35. ).communicate()
  36. #print stdout
  37. return float(stdout[:-2])
  38. def getSliceConut(fileName,videoLength):
  39. """
  40. input: file name, video slice length
  41. output: slice count
  42. """
  43. length = getVideoLength(fileName)
  44. return int(length/(videoLength*60))+1
  45. def Runner():
  46. for x in input_filename:
  47. for i in range( getSliceConut(x,yvl)):
  48. cmd = COMMAND % (i*yvl,
  49. yvl,
  50. x,
  51. ''.join(x.split('.')[:-1])
  52. ,i)
  53. print 'Run:',cmd
  54. os.system(cmd)
  55. if __name__ == '__main__':
  56. Runner()