2021-07-29 00:37:35 -07:00
|
|
|
#!/usr/bin/env zsh
|
|
|
|
# YES_ZSH
|
2021-07-29 05:44:12 -07:00
|
|
|
# NO_BASH
|
|
|
|
# NO_DASH
|
2021-07-29 00:37:35 -07:00
|
|
|
|
2021-07-30 19:41:16 -07:00
|
|
|
cutv() { ### @-
|
2021-08-01 08:28:21 -07:00
|
|
|
### (WIP) create a short clip of a long video file.
|
|
|
|
|
|
|
|
argc -ge 2 "$0" "$@" || return
|
|
|
|
argc -le 4 "$0" "$@" || return
|
2021-07-29 00:37:35 -07:00
|
|
|
local nel="${1?missing length parameter}"
|
|
|
|
local f="${2?missing file parameter}"
|
|
|
|
local g="cut."${${f##*/}%.*}".mp4"
|
|
|
|
ffmpeg -hide_banner -i "$f" 2>&1 \
|
|
|
|
| grep Duration \
|
|
|
|
| grep -Eo '[0-9][0-9]:[0-9][0-9]:[0-9][0-9].[0-9][0-9]' | awk -F: '{print (($1*60+$2)*60+$3)+$4/100}' | read len
|
2021-08-01 08:28:21 -07:00
|
|
|
[ "$len" -gt 0 ] || return 1
|
2021-07-29 00:37:35 -07:00
|
|
|
echo "$g"
|
|
|
|
ffmpeg \
|
|
|
|
-hide_banner -loglevel warning -stats -stats_period 5 \
|
|
|
|
-i "$f" -ss "$(((nel<len)*(len-nel)))" \
|
|
|
|
-sn -dn -metadata = -map_chapters -1 -movflags +faststart \
|
|
|
|
-ar 44100 -acodec libfdk_aac -b:a 256k -cutoff 20000 -af alimiter=level_in=2.5:level_out=0.9 \
|
|
|
|
-maxrate 7680k -bufsize 9600k -vcodec libx264 -preset medium -crf 21 -vf scale=1280:720 \
|
|
|
|
-threads 2 -y "$g" || return 1
|
|
|
|
# -maxrate 7680k -bufsize 9600k -vcodec libx264 -preset medium -crf 21 -vf scale=1280:720
|
|
|
|
# -maxrate 9600k -bufsize 12000k -vcodec libx264 -preset medium -crf 22 -vf scale=1280:720
|
|
|
|
}
|
|
|
|
|
|
|
|
[ "${SOURCING:-0}" -gt 0 ] || cutv "$@"
|