convert.py 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. #!/usr/bin/python3
  2. import os
  3. print("... checking home dir")
  4. HOME = os.getenv('HOME')
  5. try:
  6. os.chdir(HOME+"/LibreLight/video/converter")
  7. except FileNotFoundError:
  8. cmd = "mkdir -p {}/LibreLight/video/converter".format(HOME)
  9. os.system(cmd)
  10. os.chdir(HOME+"/LibreLight/video/converter")
  11. print("ok")
  12. cmd = "mkdir -p {}/LibreLight/video/converter/klein".format(HOME)
  13. os.system(cmd)
  14. cmd = "mkdir -p {}/LibreLight/video/converter/groß".format(HOME)
  15. os.system(cmd)
  16. cmd = "mkdir -p groß/"
  17. os.system(cmd)
  18. def convert_img(s,t):# to 1 sec video
  19. cmd="ffmpeg -y -framerate 1 -i 'groß/{}' -r 1000 'groß/{}.mp4'".format(s,t)
  20. cmd="ffmpeg -y -framerate 1 -i 'groß/{}' -s 640x480 -c:a copy -r 1000 'klein/{}.mp4'".format(s,t)
  21. print(cmd)
  22. os.system(cmd)
  23. print("*"*40)
  24. print("*"*40)
  25. print()
  26. def convert_video(s,t):
  27. cmd="ffmpeg -y -i 'groß/{}' -s 640x480 -c:a copy 'klein/{}.mp4'".format(s,t)
  28. print(cmd)
  29. os.system(cmd)
  30. print("*"*40)
  31. print("*"*40)
  32. print()
  33. files = os.listdir("groß/")
  34. if not files:
  35. print("- no files in groß")
  36. for s in files:
  37. if "." not in s:
  38. continue
  39. t = s.rsplit(".",1)[0] # cut ending .mp4
  40. if os.path.isfile("groß/"+s):
  41. print(s)
  42. ending = s.lower().split(".")[-1]
  43. if ending in ["png","jpg","jpeg","bmp","gif"] :
  44. convert_img(s,t)
  45. #s = t+".mp4"
  46. else:
  47. convert_video(s,t)
  48. print(" ")
  49. print(" ")
  50. print("")
  51. input("ende")