Guest User

Untitled

a guest
Feb 17th, 2019
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.25 KB | None | 0 0
  1. import os
  2. import time
  3.  
  4. def v2c(filename, number_of_clips):
  5.  
  6. duration = os.popen("ffmpeg -i {0} 2>&1 | grep Duration".format(filename)).read()
  7. duration = duration.split(' ')[3].split(',')[0]
  8.  
  9. hours, mins, secs = duration.split(':')
  10. total_secs = int(hours)*3600 + int(mins)*60 + int(secs.split('.')[0])
  11.  
  12. duration_secs = (total_secs)//number_of_clips
  13.  
  14. duration_formatted = time.strftime('%H:%M:%S', time.gmtime(duration_secs))
  15. for i in range(number_of_clips):
  16. ss_formatted = time.strftime('%H:%M:%S', time.gmtime(duration_secs * (i)))
  17. # print("ffmpeg -ss {0} -i {1} -to {2} -qscale 0 -c copy clips/clip{3}.mp4".format(ss_formatted, filename, duration_formatted, i))
  18. os.system("ffmpeg -ss {0} -i {1} -to {2} -qscale 0 -c copy clips/clip{3}.mp4".format(ss_formatted, filename, duration_formatted, i))
  19.  
  20.  
  21. def c2f(timestamp, clip_name, number_of_frames):
  22. os.system("ffmpeg -ss {0} -i {1} -qscale 0 -frames:v {2} frames/frame%04d.jpg -hide_banner".format(timestamp, clip_name, number_of_frames))
  23.  
  24. # filename = './video.mp4'
  25. # number_of_clips = 10
  26. # v2c(filename, number_of_clips)
  27.  
  28. # clip_name = './clips/clip3.mp4'
  29. # timestamp = '00:00:03'
  30. # number_of_frames = 24
  31. # c2f(timestamp, clip_name, number_of_frames)
Add Comment
Please, Sign In to add comment