/useful/trunk-1

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/useful/trunk-1
11 by Gustav Hartvigsson
General fixup.
1
#!/usr/bin/env bash
2
###################
3
# FILE NAME: video2lbry.sh
4
#
5
# Encodes videos so they are ready to be uploaded to LBRY.
6
#
7
# Changes
8
# 2021-01-13
9
#   * fixed up if statments
10
#   * removed eval
11
#
12
####################
13
14
__IN_NAME=""
15
__OUT_NAME=""
16
17
__help () {
18
  echo "video2lbry.sh -- Make vide ready for upload to LBRY."
19
  echo " "
20
  echo "-i <input video file>     Input Video File."
21
  echo " "
22
  echo "-o <output video file>    Output Video File"
23
  echo "                          (_lbry.mp4 will be added to the end)."
24
  echo " "
25
}
26
27
__enc_mp4 () {
28
  ffmpeg -y -i "$__IN_NAME"\
29
          -threads 7\
30
          -c:v libx264\
31
          -crf 21\
32
          -preset slower\
33
          -pix_fmt yuv420p\
34
          -maxrate 5000K\
35
          -bufsize 5000K\
36
          -vf 'scale=if(gte(iw\,ih)\,min(2560\,iw)\,-2):if(lt(iw\,ih)\,min(2560\,ih)\,-2)'\
37
          -movflags +faststart\
38
          -c:a aac\
39
          -b:a 256k\
40
          "${__OUT_NAME}_lbry.mp4"
41
}
42
43
__parse_args() {
44
  if [[ -z "$1" ]]
45
  then
46
    echo "Try --help or -h."
47
    exit 1
48
  fi
49
  
50
  
51
  while [[ $# -gt 0 ]]
52
  do
53
    
54
    case "${1}" in
55
      -i)
56
      __IN_NAME="$2"
57
      shift
58
      shift
59
      ;;
60
      -o)
61
      __OUT_NAME="$2"
62
      shift
63
      shift
64
      ;;
65
      -m)
66
      __USE_WEBM=true
67
      shift
68
      ;;
69
      -h|--help)
70
      __help
71
      shift
72
      ;;
73
      *)
74
      __help
75
      exit
76
      shift
77
      ;;
78
      --)
79
      shift
80
      break
81
      ;;
82
    esac
83
  done
84
}
85
86
__main () {
87
  if [[ ! -e "$__IN_NAME" ]]
88
  then
89
    echo "missing input audio. Please provide."
90
    exit 1
91
  fi
92
  
93
  if [[ $__OUT_NAME == "" ]]
94
  then
95
    echo "missing output file name. Please provide."
96
    exit 1
97
  fi
98
  
99
  
100
  if [[ $__IN_NAME == ${__OUT_NAME}_lbry.mp4 ]]
101
  then
102
    echo "Filenames can't be the same."
103
    exit
104
  fi
105
  __enc_mp4
106
}
107
108
__parse_args "${@}"
109
__main