diff options
-rw-r--r-- | requirements.txt | 1 | ||||
-rwxr-xr-x | tools/esp32cam_captures_to_video.py | 23 | ||||
-rwxr-xr-x | tools/rotate-video.sh | 30 | ||||
-rwxr-xr-x | tools/video-util.sh | 2 |
4 files changed, 48 insertions, 8 deletions
diff --git a/requirements.txt b/requirements.txt index 53c3cd0..e42e4a9 100644 --- a/requirements.txt +++ b/requirements.txt @@ -14,6 +14,7 @@ PyYAML~=6.0 apscheduler~=3.9.1 psutil~=5.9.1 aioshutil~=1.1 +scikit-image~=0.19.3 # following can be installed from debian repositories # matplotlib~=3.5.0 diff --git a/tools/esp32cam_captures_to_video.py b/tools/esp32cam_captures_to_video.py index 98a4e4f..72aaa5c 100755 --- a/tools/esp32cam_captures_to_video.py +++ b/tools/esp32cam_captures_to_video.py @@ -33,14 +33,14 @@ def get_files(source_directory: str) -> FileList: return files -def group_files(files: FileList) -> list[FileList]: +def group_files(files: FileList, timedelta_val: int) -> list[FileList]: groups = [] group_idx = None for file in files: if group_idx is None or \ not groups[group_idx] or \ - file['time'] - groups[group_idx][-1]['time'] <= timedelta(seconds=10): + file['time'] - groups[group_idx][-1]['time'] <= timedelta(seconds=timedelta_val): if group_idx is None: groups.append([]) group_idx = 0 @@ -55,7 +55,8 @@ def group_files(files: FileList) -> list[FileList]: def merge(groups: list[FileList], output_directory: str, delete_source_files=False, - cedrus=False) -> None: + cedrus=False, + rotate=0) -> None: for g in groups: success = False @@ -91,10 +92,15 @@ def merge(groups: list[FileList], env = {} args = ['-c:v', 'libx264', '-preset', 'veryslow', - # '-crf', '23', + '-crf', '34', # '-vb', '448k', '-pix_fmt', 'yuv420p', - '-filter:v', 'fps=2'] + '-movflags', '+faststart' + # '-filter:v', 'fps=2' + ] + + if rotate != 0: + args.extend(['-map_metadata', '0', '-metadata:s:v', f'rotate="{rotate}"', '-codec', 'copy']) cmd = [ffmpeg, '-y', '-f', 'concat', @@ -130,8 +136,10 @@ if __name__ == '__main__': help='Directory with files') parser.add_argument('--output-directory', '-o', type=str, required=True, help='Output directory') + parser.add_argument('--timedelta', type=int, default=10) parser.add_argument('-D', '--delete-source-files', action='store_true') parser.add_argument('--cedrus', action='store_true') + parser.add_argument('--rotate', type=int, choices=(90, 180, 270), default=0) # parser.add_argument('--vbr', action='store_true', # help='Re-encode using VBR (-q:a 4)') arg = parser.parse_args() @@ -144,10 +152,11 @@ if __name__ == '__main__': print(f"No jpeg files found in {arg.input_directory}.") sys.exit() - groups = group_files(files) + groups = group_files(files, timedelta_val=arg.timedelta) # print_groups(groups) merge(groups, os.path.realpath(arg.output_directory), delete_source_files=arg.delete_source_files, - cedrus=arg.cedrus) + cedrus=arg.cedrus, + rotate=arg.rotate) diff --git a/tools/rotate-video.sh b/tools/rotate-video.sh new file mode 100755 index 0000000..6d27b44 --- /dev/null +++ b/tools/rotate-video.sh @@ -0,0 +1,30 @@ +#!/bin/bash + +set -e + +DIR="$( cd "$( dirname "$(realpath "${BASH_SOURCE[0]}")" )" &>/dev/null && pwd )" +PROGNAME="$0" + +. "$DIR/lib.bash" + + +usage() { + cat <<EOF +usage: $PROGNAME FILENAME +EOF + exit 1 +} + +[[ $# -lt 1 ]] && usage + +oldname="$1" +if file_in_use "$oldname"; then + die "file $oldname is in use by another process" +fi + +newname="${oldname/.mp4/_rotated.mp4}" + +ffmpeg -y -i "$(realpath "$1")" -map_metadata 0 -metadata:s:v rotate="90" -codec copy \ + "$(realpath "$newname")" +rm "$oldname" +mv "$newname" "$oldname"
\ No newline at end of file diff --git a/tools/video-util.sh b/tools/video-util.sh index e7507ac..0ee5560 100755 --- a/tools/video-util.sh +++ b/tools/video-util.sh @@ -22,7 +22,7 @@ Options: -i|--input FILE input file/directory -o|--output FILE output file/directory --name NAME camera name, affects config directory. - default is $config_dir, specifying --name will make it + default is $config_dir, specifying --name will make it ${config_dir}-\$name -v, -vv, vx be verbose. -v enables debug logs. |