/useful/trunk-1

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/useful/trunk-1

« back to all changes in this revision

Viewing changes to scripts/enc2firefox.sh

  • Committer: Gustav Hartvigsson
  • Date: 2021-01-13 18:44:02 UTC
  • Revision ID: git-v1:0dbf5fcfbb68944b25dbeeeceb02ac414ac330ad
Inital code.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/env bash
 
2
###################
 
3
# FILE NAME: enc2firefox.sh
 
4
#
 
5
# Encodes (mp4/x264) videos so they can be played in firefox.
 
6
#
 
7
# Updates:
 
8
# 2020-09-05:
 
9
#   * Removed an eval that made no sense.
 
10
#   * Added FJ mode for those spicy memes.
 
11
####################
 
12
ARGS=()
 
13
ARGS="${@}"
 
14
 
 
15
__IN_NAME=
 
16
__OUT_NAME=
 
17
__USE_WEBM=false
 
18
__USE_FJ=false
 
19
 
 
20
__help () {
 
21
  echo "enc2firefox.sh -- Make Videos Playable in Firefox"
 
22
  echo " "
 
23
  echo "-i <input video file>     Input Video File."
 
24
  echo " "
 
25
  echo "-o <output video file>    Output Video File"
 
26
  echo "                          (.mp4 will be added to the end)."
 
27
  echo " "
 
28
  echo "-m                        output webm instead"
 
29
  echo "                          (Will change ending to .webm)."
 
30
  echo " "
 
31
  echo "-f                        Use FJ settings. Low bandwith, small size."
 
32
  echo "                          (Will append .mp4 to the end)."
 
33
  echo " "
 
34
  exit
 
35
}
 
36
 
 
37
__enc_mp4 () {
 
38
  ffmpeg -i "$__IN_NAME"\
 
39
            -c:v libx264\
 
40
            -preset slower\
 
41
            -crf 22\
 
42
            -pix_fmt yuv420p\
 
43
            -c:a aac\
 
44
            -b:a 128k\
 
45
            "$__OUT_NAME".mp4
 
46
}
 
47
 
 
48
__enc_fj () {
 
49
  ffmpeg -i "$__IN_NAME"\
 
50
            -c:v libx264\
 
51
            -preset slower\
 
52
            -pix_fmt yuv420p\
 
53
            -b:v 1024k\
 
54
            -s hd720\
 
55
            -r 30\
 
56
            -c:a aac\
 
57
            -b:a 128k\
 
58
            "$__OUT_NAME".mp4
 
59
}
 
60
 
 
61
__enc_webm () {
 
62
  ffmpeg -i "$__IN_NAME"\
 
63
            -c:v libvpx-vp9\
 
64
            -b:v 0\
 
65
            -crf 20\
 
66
            -c:a libopus\
 
67
            "$__OUT_NAME".webm
 
68
}
 
69
 
 
70
__parse_args() {
 
71
  if [ -z "$1" ]
 
72
  then
 
73
    echo "Try --help or -h."
 
74
    exit 1
 
75
  fi
 
76
  
 
77
  
 
78
  while [[ $# -gt 0 ]]
 
79
  do
 
80
    
 
81
    case "${1}" in
 
82
      -i)
 
83
      __IN_NAME="$2"
 
84
      shift
 
85
      shift
 
86
      ;;
 
87
      -o)
 
88
      __OUT_NAME="$2"
 
89
      shift
 
90
      shift
 
91
      ;;
 
92
      -m)
 
93
      __USE_WEBM=true
 
94
      shift
 
95
      ;;
 
96
      -f)
 
97
      __USE_FJ=true
 
98
      shift
 
99
      ;;
 
100
      -h|--help)
 
101
      __help
 
102
      shift
 
103
      ;;
 
104
      *)
 
105
      __help
 
106
      exit 1
 
107
      shift
 
108
      ;;
 
109
      --)
 
110
      shift
 
111
      break
 
112
      ;;
 
113
    esac
 
114
  done
 
115
}
 
116
 
 
117
__main () {
 
118
  if [ ! -e "$__IN_NAME" ]
 
119
  then
 
120
    echo "missing input audio. Please provide."
 
121
    exit 1
 
122
  fi
 
123
  
 
124
  if [ $__OUT_NAME == "" ]
 
125
  then
 
126
    echo "missing output file name. Please provide."
 
127
    exit 1
 
128
  fi
 
129
  
 
130
  
 
131
  if [ $__USE_WEBM = true ]
 
132
  then
 
133
    if [ $__IN_NAME = $__OUT_NAME.webm ]
 
134
    then
 
135
      echo "Filenames can't be the same."
 
136
      exit
 
137
    fi
 
138
    __enc_webm
 
139
  elif [ $__USE_FJ = true ]
 
140
  then
 
141
    if [ $__IN_NAME = $__OUT_NAME.mp4 ]
 
142
    then
 
143
      echo "Filenames can't be the same."
 
144
      exit
 
145
    fi
 
146
    __enc_fj
 
147
  else
 
148
    if [ $__IN_NAME = $__OUT_NAME.mp4 ]
 
149
    then
 
150
      echo "Filenames can't be the same."
 
151
      exit
 
152
    fi
 
153
    __enc_mp4
 
154
  fi
 
155
}
 
156
 
 
157
__parse_args "${@}"
 
158
__main