1
0
Fork 0
mirror of https://github.com/notwa/rc synced 2024-11-13 20:39:04 -08:00
rc/sh/cutv
Connor Olding d5f3f14d72 merge compatibility lines
RIP meaningful last-modified dates
2024-03-26 15:08:14 -07:00

30 lines
1.3 KiB
Bash
Executable file

#!/usr/bin/env zsh
# YES_ZSH NO_BASH NO_DASH NO_ASH
cutv() { ### @-
### (WIP) create a short clip of a long video file.
argc $# -ge 2 "$0" || return
argc $# -le 4 "$0" || return
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
[ "$((len>0))" -eq 1 ] || return 1
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
}
[ -n "${preload+-}" ] || . ~/sh/preload || exit 2
eval ${preload:-preload} argc
[ -n "${preload+-}" ] || cutv "$@"