summaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorEvgeny Zinoviev <me@ch1p.io>2022-06-16 15:59:40 +0300
committerEvgeny Zinoviev <me@ch1p.io>2022-06-16 22:36:40 +0300
commit46af1e90f5867e3f141ceb230a3b71a05c310840 (patch)
treed188e0e880a83b4c789a43ef412f35bdd8fb72fc /tools
parentbd3c5487b526c441b76304b15e13b0ef3b26105f (diff)
video utils updated
Diffstat (limited to 'tools')
-rwxr-xr-xtools/esp32cam_captures_to_video.py23
-rwxr-xr-xtools/rotate-video.sh30
-rwxr-xr-xtools/video-util.sh2
3 files changed, 47 insertions, 8 deletions
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.