ffmpeg-record.py 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. #!/usr/bin/env python
  2. # This is a wrapper script for ffmpeg to do various usefule things.
  3. # Read the help in order to understand in order to close it go to the
  4. # terminal window and press q on your keyboard. If you don't do this
  5. # there is some chance ffmpeg could mess with your recording.
  6. #
  7. # WARNING no gaurentee all these commands work on windows and linux
  8. # because I did not test. And most of these commands I got right off
  9. # of stack exchange and they add crazy options.
  10. import os
  11. import subprocess
  12. import re
  13. import sys
  14. import platform
  15. import argparse
  16. parser = argparse.ArgumentParser(description='Fffmpeg wrapper script.')
  17. parser.add_argument('-s', '--screen', action="store_true", default=False, help='Record screen')
  18. parser.add_argument('-sa', '--screen_audio', action="store_true", default=False, help='Record screen and audio')
  19. parser.add_argument('-a', '--audio', action="store_true", default=False, help='Record just audio')
  20. args = parser.parse_args()
  21. if args.screen:
  22. output = input("Where do you want the recording to go: ")
  23. print(platform.system())
  24. if platform.system() == "Windows":
  25. os.system(f"ffmpeg -f gdigrab -framerate 30 -i desktop {output}")
  26. else:
  27. os.system(f"ffmpeg -f x11grab -i :0.0 -f alsa -i hw:0 {output}")
  28. elif args.audio:
  29. devices = subprocess.getoutput("ffmpeg -list_devices true -f dshow -i dummy")
  30. data = re.findall('"(.+?)"',devices)
  31. for i,device in enumerate(data):
  32. print(i, device)
  33. pick = data[int(input("Which audio device do you want? "))]
  34. if pick.startswith("@"):
  35. pick = data[data.index(pick)-1]
  36. output = input("Where do you want the recording to go: ")
  37. command = f'ffmpeg -f dshow -i audio="{pick}" {output}'
  38. try:
  39. os.system(command)
  40. except:
  41. quit()
  42. elif args.screen_audio:
  43. devices = subprocess.getoutput("ffmpeg -list_devices true -f dshow -i dummy")
  44. data = re.findall('"(.+?)"',devices)
  45. for i,device in enumerate(data):
  46. print(i, device)
  47. pick = data[int(input("Which audio device do you want? "))]
  48. if pick.startswith("@"):
  49. pick = data[data.index(pick)-1]
  50. output = input("Where do you want the recording to go: ")
  51. # On windows this command is supposed to work for getting screen
  52. # resolution "wmic desktopmonitor get screenheight, screenwidth"
  53. # but for me it doesn't work. In the future when linux support is
  54. # added xrandr could be used to get screen resolution and select
  55. # which monitor to use etc. But for now ffmpeg is basicly geussing
  56. # stuff.
  57. command = f'ffmpeg -f gdigrab -framerate ntsc -i desktop -f dshow -i audio="{pick}" -vcodec libx264 -pix_fmt yuv420p -preset ultrafast {output}'
  58. os.system(command)
  59. # Add an overlay thing on the lower right corner of the video
  60. # ffmpeg -i whole.mp4 -i meme.png -filter_complex "[0:v][1:v] overlay=W-w:H-h" -pix_fmt yuv420p -c:a copy wholeimage.mp4