[READ-ONLY] Mirror of https://github.com/mrgnw/dotfiles. My shell customizations - aliases, functions, and themes.
dotfiles shell zinit zsh
0

Configure Feed

Select the types of activity you want to include in your feed.

dotfiles / video.zsh
3.9 kB 96 lines
1ffp(){ 2 ffprobe -print_format json -show_format -show_streams -show_chapters -show_private_data "$@" | jq '.streams' 3} 4 5hevc(){ 6 local filename=$1:t:r 7 ffmpeg -i $1 -c:v hevc_videotoolbox -b:v 2M $filename.mp4 8 # ffmpeg -i input.mp4 -c:v h264_videotoolbox -b:v 2M -hwaccel videotoolbox output.mp4 9} 10 11atv(){ 12 # Apple 1080p60 4K HEVC Surround. 13 # also make sure it works with quicklook 14 # $2 accepts quality - 1080p60, 1080p30, 720p60, 720p30, 480p30, 360p30, 240p30, 144p30 15 local quality=${2:-"1080p30"} 16 17 fname=$1:t:r 18 input=$1 19 local output_dir=$HANDBRAKE_OUTPUT_DIR 20 # if HANDBRAKE_OUTPUT_DIR is not set, use current directory 21 if [[ -z $HANDBRAKE_OUTPUT_DIR ]]; then 22 output_dir=$(pwd) 23 fi 24 echo output_dir "$output_dir" 25 26 handbrake --input "$input" -o "$output_dir/$fname-$quality.mp4" \ 27 --preset "Apple $quality Surround" \ 28 --all-subtitles --all-audio --optimize \ 29 && trash "$input"; 30 # ensure format will play in macos quicklook using handbrake 31 # ffmpeg -i input.mp4 -c:v h264_videotoolbox -b:v 2M -hwaccel videotoolbox output.mp4 32 # ffmpeg -i "${1%.*}.mp4" -c copy -movflags faststart "${1%.*}.mp4" 33} 34# mp4s() - simply converts all non mp4 files in cwd to mp4 using ffmpeg. 35# If the codec is already h264 or hevc, it just remuxes to mp4 container. 36# if not, it converts to h264 37# also, don't overwrite existing mp4 files; skip if the mp4 already exists 38mp4s(){ 39 emulate -L zsh -o extendedglob 40 for f in (#i)*.(mp4|mov|mkv|avi|webm|m4v|flv|wmv|mpg|mpeg|ts|m2ts|3gp|vob)(.N); do 41 # get file extension (case-insensitive check) 42 local ext=${f##*.} 43 local target_mp4="${f%.*}.mp4" 44 # before applying profile, check if file is already mp4 45 if [[ ${ext:l} != "mp4" ]]; then 46 # skip if target mp4 already exists 47 if [[ -e "$target_mp4" ]]; then 48 echo " - $target_mp4 already exists, skipping $f" 49 else 50 # detect codec via ffprobe to decide remux vs transcode 51 local vcodec 52 vcodec=$(ffprobe -v error -select_streams v:0 -show_entries stream=codec_name -of default=nk=1:nw=1 "$f" 2>/dev/null) 53 if [[ "$vcodec" == "h264" || "$vcodec" == "hevc" || "$vcodec" == "h265" ]]; then 54 echo " - $f is already h264 or hevc, remuxing to mp4" 55 ffmpeg -i "$f" -c copy -movflags faststart "$target_mp4" && trash "$f" 56 else 57 echo " - converting $f to mp4" 58 ffmpeg -i "$f" -c:v libx264 -crf 23 -preset medium -c:a aac -b:a 192k -movflags +faststart "$target_mp4" && trash "$f" 59 fi 60 fi 61 else 62 echo " - $f is already mp4, skipping" 63 fi 64 done 65 } 66 67 68 atvs(){ 69 # apply profile 'Apple 1080p60 HEVC Surround' to all files in current directory 70 local quality=${2:-"1080p30"} 71 emulate -L zsh -o extendedglob 72 for f in (#i)*.(mp4|mov|mkv|avi|webm|m4v|flv|wmv|mpg|mpeg|ts|m2ts|3gp|vob)(.N); do 73 atv "$f" "$quality" 74 done 75 } 76 77# muxs() - batch remux all matching video files to mp4 78# - copies video stream, encodes audio to AAC 79# - skips when target .mp4 already exists 80# - case-insensitive extension match via zsh extended globs 81muxs(){ 82 emulate -L zsh -o extendedglob 83 for f in (#i)*.(mp4|mov|mkv|avi|webm|m4v|flv|wmv|mpg|mpeg|ts|m2ts|3gp|vob)(.N); do 84 local base=${f%.*} 85 local ext=${f##*.} 86 # For mp4 inputs, add -compressed suffix; for others, convert to .mp4 87 if [[ ${ext:l} == "mp4" ]]; then 88 local out="${base}-compressed.mp4" 89 else 90 local out="${base}.mp4" 91 fi 92 echo " - converting $f -> $out" 93 ffmpeg -y -i "$f" -movflags +faststart "$out" \ 94 && echo " ✔ done" 95 done 96}