-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils.py
31 lines (27 loc) · 1.04 KB
/
utils.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
"""Util functions to video processing."""
import logging
import pathlib
import subprocess
logger = logging.getLogger("BeePi")
logging.basicConfig(
filename="logs.txt",
filemode="a",
format="%(asctime)s %(name)s: %(message)s",
datefmt="%d.%m.%y %H:%M:%S",
level=logging.INFO,
)
def convert_to_greyscale(video_dir: pathlib.Path, remove_orig: bool = False) -> None:
"""Convert videos in a directory to grayscale. Converted videos will be saved
to same path with 'gry-' prefix and original videos can optionally be removed.
Exceptions raised:
CalledProcessError: raised if ffmpeg doesnt successfully convert a file.
"""
for file in video_dir.glob("*.h264"):
new_path = file.parent / ("gry-" + file.stem + file.suffix)
subprocess.run(
["ffmpeg", "-i", file, "-vf", "format=gray", new_path], check=True
)
logger.info("%s converted, saved as %s.", file.stem, new_path.stem)
if remove_orig:
file.unlink()
logger.info("Deleted %s.", file.stem)