config

Personal configuration.
git clone git://code.dwrz.net/config
Log | Files | Refs

video (1900B)


      1 #!/usr/bin/env bash
      2 
      3 compress() {
      4   local filetype crf
      5   filetype="$(printf "*.%s" "$1")"
      6   # "The range of the CRF scale is 0–51, where 0 is lossless, 23 is the default,
      7   # and 51 is worst quality possible. A lower value generally leads to higher
      8   # quality, and a subjectively sane range is 17–28. Consider 17 or 18 to be
      9   # visually lossless or nearly so; it should look the same or nearly the same
     10   # as the input but it isn't technically lossless."
     11   crf="$2"
     12   if [[ -z "$crf" ]]; then
     13     crf=32 # Use a default CRF of 32.
     14   fi
     15 
     16   mkdir compressed
     17 
     18   for v in ${filetype}; do
     19     ffmpeg -i "file:${v}" -vcodec libx264 -crf "${crf}" "./compressed/${v}";
     20   done
     21 
     22   notify-send "video: compress: done"
     23 }
     24 
     25 compress_x265() {
     26   local filetype crf
     27   filetype="$(printf "*.%s" "$1")"
     28   # "The range of the CRF scale is 0–51, where 0 is lossless, 23 is the default,
     29   # and 51 is worst quality possible. A lower value generally leads to higher
     30   # quality, and a subjectively sane range is 17–28. Consider 17 or 18 to be
     31   # visually lossless or nearly so; it should look the same or nearly the same
     32   # as the input but it isn't technically lossless."
     33   crf="$2"
     34   if [[ -z "$crf" ]]; then
     35     crf=23 # Use a default CRF of 23.
     36   fi
     37 
     38   mkdir compressed
     39 
     40   for v in ${filetype}; do
     41     ffmpeg -i "file:${v}" \
     42 	   -c:v libx265 \
     43 	   -vtag hvc1 \
     44 	   -crf "${crf}" \
     45 	   -c:a copy \
     46 	   "./compressed/${v}";
     47   done
     48 
     49   notify-send "video: compress-x265: done"
     50 }
     51 
     52 trim() {
     53   input="$1"
     54   output="${input%.*}-trim.${input#*.}"
     55   start="$2" # 00:00:00
     56   end="$3" # 00:00:00
     57 
     58   ffmpeg -i "${input}" -ss "${start}" -to "${end}" "${output}"
     59 
     60   notify-send "video: trim: done"
     61 }
     62 
     63 main() {
     64   local cmd="$1"; shift
     65 
     66   case "${cmd}" in
     67     "compress") compress "$@" ;;
     68     "compress-x265") compress_x265 "$@" ;;
     69     "trim") trim "$@" ;;
     70     *) err "unrecognized command: ${cmd}" ;;
     71   esac
     72 }
     73 
     74 main "$@"