compress.py 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. #!/usr/bin/env python3
  2. import os
  3. import sys
  4. import ff
  5. TGTBR_EV = 'MCLEAN_FF_BITRATE'
  6. PRESET_EV = 'MCLEAN_FF_PRESET'
  7. DRYRUN_EV = 'MCLEAN_DRYRUN'
  8. def main(argv):
  9. src = os.path.expanduser(argv[1])
  10. dest = os.path.expanduser(argv[2])
  11. target_br = 1000
  12. preset = 'veryfast'
  13. dr = False
  14. if TGTBR_EV in os.environ:
  15. target_br = int(os.environ[TGTBR_EV])
  16. if PRESET_EV in os.environ:
  17. preset = os.environ[PRESET_EV]
  18. if DRYRUN_EV in os.environ:
  19. dr = bool(os.environ[DRYRUN_EV])
  20. probe = ff.probe_file(src)
  21. props = ff.extract_stream_props(probe)
  22. exp_size = (props['duration_sec'] * target_br) // 8 // 1024 # TODO adj for audio
  23. print('SRC CODEC:', props['codec'])
  24. print('INPUT HEIGHT:', props['res_h'])
  25. print('TARGET BITRATE:', target_br)
  26. print('EXP OUTPUT:', exp_size, 'MiB')
  27. yn = input('Continue? y/n: ')
  28. if yn != 'y':
  29. return 1
  30. ff.reencode(src, dest, target_br, preset=preset, dryrun=dr)
  31. print('WRITTEN OK')
  32. return 0
  33. if __name__ == '__main__':
  34. sys.exit(main(sys.argv))