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