slice.py 582 B

1234567891011121314151617181920212223
  1. from pathlib import Path
  2. from .utils import to_hhmmss, system
  3. async def slice_audio(src_path: Path, dst_path: Path, timecode: str):
  4. if not src_path.exists():
  5. raise FileNotFoundError
  6. if dst_path.exists():
  7. return dst_path
  8. start, end = map(int, timecode.split("/"))
  9. if start == -1:
  10. return src_path
  11. if start == 0 and end == -1:
  12. return src_path
  13. start = to_hhmmss(start)
  14. end = to_hhmmss(end)
  15. command = f'ffmpeg -ss {start} -to {end} -i "{src_path}" -qscale 0 "{dst_path}"'
  16. await system(command)
  17. return dst_path