Compare commits
2 commits
194b6b672d
...
66c2231a15
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
66c2231a15 | ||
|
|
e7f2320b82 |
2 changed files with 76 additions and 6 deletions
|
|
@ -44,18 +44,16 @@ calc_smart_volumes() {
|
|||
total_size=$(du -s -BM "${input_file}" | grep -oP '^\d+') || return 0
|
||||
|
||||
# If total file size is smaller than volume size, don't pack it into volumes
|
||||
[[ $total_size -lt $size ]] && return 1
|
||||
(( total_size < size )) && return 1
|
||||
|
||||
num_volumes=$(echo "($total_size + $size - 1) / $size" | bc)
|
||||
size=$(echo "($total_size + $num_volumes - 1) / $num_volumes" | bc)
|
||||
num_volumes=$(( (total_size + size - 1) / size ))
|
||||
size=$(( (total_size + num_volumes - 1) / num_volumes ))
|
||||
|
||||
echo "Calculated smart volume size '$size'" >&2
|
||||
}
|
||||
|
||||
set_volumes() {
|
||||
if [[ -n "$size" ]]; then
|
||||
calc_smart_volumes && volumes="-v${size}m"
|
||||
fi
|
||||
[[ -n "$size" ]] && calc_smart_volumes && volumes="-v${size}m"
|
||||
|
||||
echo "Volumes set to '$volumes'" >&2
|
||||
}
|
||||
|
|
|
|||
72
modules/video_previews.sh
Executable file
72
modules/video_previews.sh
Executable file
|
|
@ -0,0 +1,72 @@
|
|||
#!/bin/bash
|
||||
|
||||
preview_dir="$(dirname "$0")/../previews"
|
||||
|
||||
search_dir="${1}"
|
||||
|
||||
check_dependencies() {
|
||||
if ! mkdir -p "$preview_dir"; then
|
||||
echo "ERROR: Unable to create preview directory"
|
||||
exit 1
|
||||
elif ! command -v ffmpeg 2>&1 >/dev/null; then
|
||||
echo "ERROR: FFmpeg must be installed"
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
check_input() {
|
||||
if [[ ! -e "${search_dir}" ]]; then
|
||||
echo "ERROR: Input file '${search_dir}' does not exist"
|
||||
exit 2
|
||||
fi
|
||||
}
|
||||
|
||||
# Search for videos recursively using the MIME type
|
||||
find_videos() {
|
||||
video_list=$(find "${search_dir}" -type f -exec file -i {} \; | grep -oP '.*(?=: video/)')
|
||||
|
||||
echo "${video_list}" >&2
|
||||
}
|
||||
|
||||
create_previews() {
|
||||
while IFS= read -r video; do
|
||||
echo "Making preview for ${video}"
|
||||
make_preview
|
||||
done <<< "${video_list}"
|
||||
}
|
||||
|
||||
get_size() {
|
||||
IFS=','
|
||||
read -r width height <<< $(ffprobe -v error -select_streams v -show_entries stream=width,height -of csv=p=0 "${video}")
|
||||
|
||||
if [[ $width -gt $height ]]; then
|
||||
rows=4 cols=5
|
||||
scale_format="200:-1"
|
||||
else
|
||||
rows=5 cols=4
|
||||
scale_format="-1:200"
|
||||
fi
|
||||
}
|
||||
|
||||
get_num_frames() {
|
||||
local num_snapshots=$(( rows * cols ))
|
||||
|
||||
num_frames=$(ffprobe -v error -select_streams v:0 -count_frames -show_entries stream=nb_read_frames -of csv=p=0 "${video}")
|
||||
echo "Num frames: $num_frames" >&2
|
||||
|
||||
frames_per_snapshot=$(( num_frames / num_snapshots ))
|
||||
}
|
||||
|
||||
make_preview() {
|
||||
get_size
|
||||
get_num_frames
|
||||
|
||||
filename="$(basename "${video}")"
|
||||
|
||||
ffmpeg -nostdin -loglevel panic -i "${video}" -frames 1 -q:v 90 -vf "select=not(mod(n\,$frames_per_snapshot)),scale=$scale_format,tile=${rows}x${cols}" "$preview_dir/${filename}.webp"
|
||||
}
|
||||
|
||||
check_dependencies
|
||||
check_input
|
||||
find_videos
|
||||
create_previews
|
||||
Loading…
Add table
Add a link
Reference in a new issue