video utils updated
This commit is contained in:
parent
bd3c5487b5
commit
46af1e90f5
@ -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
|
||||
|
@ -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)
|
||||
|
30
tools/rotate-video.sh
Executable file
30
tools/rotate-video.sh
Executable file
@ -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"
|
Loading…
x
Reference in New Issue
Block a user