1
0
Fork 0
mirror of https://github.com/notwa/rc synced 2024-11-14 08:19:03 -08:00
rc/sh/cutv

29 lines
1.2 KiB
Text
Raw Normal View History

2021-07-29 00:37:35 -07:00
#!/usr/bin/env zsh
# compat: -ash -bash -dash +zsh
2021-07-29 00:37:35 -07:00
cutv() {
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-09-11 10:38:30 -07:00
[ "$((len>0))" -eq 1 ] || 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
}
2021-09-11 10:38:30 -07:00
[ -n "${preload+-}" ] || . ~/sh/preload || exit 2
eval ${preload:-preload} argc
[ -n "${preload+-}" ] || cutv "$@"