/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/wav2mp4.sh

  • Committer: Gustav Hartvigsson
  • Date: 2021-01-14 11:47:07 UTC
  • Revision ID: git-v1:8ab298a55bc6629f1bf4fc1660469a59f4ebf0cf
General fixup.

* Removed unused ARGS declarations.

* Made all variabels start with two underlines

* Expilitly declared functions as such.

* Expilitly declared strings (file names and such) as strings
  at the start of the files.

Show diffs side-by-side

added added

removed removed

Lines of Context:
9
9
#   * Fixed up if statments
10
10
#   * Removed eval.
11
11
#
12
 
# 2022-03-22:
13
 
#   * Make script work with gifs, and Make gifs loop.
14
 
#
15
 
# 2024-07-10:
16
 
#   * Fixed some formating errors.
17
 
#   * Added sanity check.
18
 
#   * Use /tmp/ instead of writing to FS.
19
12
######
20
13
 
21
 
__SANITY=true
22
 
 
23
 
# FIXME: Use mktemp or mkdtemp instea of usin /tmp/ directly
24
 
__TMP_IMAGE_NAME=/tmp/__SPEAKER_IMAGE.PNG
 
14
__TMP_IMAGE_NAME=__SPEAKER_IMAGE.PNG
25
15
__OUT_NAME=""
26
16
__IN_NAME=""
27
17
 
28
18
__USE_DIFFERENT_IMAGE=false
29
19
__OTHER_IMAGE_NAME=""
30
20
 
31
 
__LOOP=false
32
 
 
33
21
function __usage () {
34
22
  echo "wav2mp4.sh --- Convert audio to a video for upload. "
35
23
  echo " "
37
25
  echo " "
38
26
  echo "-o <video.mp4>        The output for the video."
39
27
  echo " "
40
 
  echo "--image <image.[png,gif]>"
41
 
  echo "                      Image to use. If none is provided a standard image"
 
28
  echo "--image <image.png>   Image to use. If non is provided a standard image"
42
29
  echo "                      will be used."
 
30
  echo " "
43
31
  echo ""
44
 
  exit 0
45
 
}
46
 
 
47
 
function __silent () {
48
 
  $@ >> /dev/null 2>&1
49
 
  return $?
50
 
}
51
 
 
52
 
function __sanity_check () {
53
 
  # Check that we have the tools needed.
54
 
  ___silent which ffmpeg 
55
 
 
56
 
  if [[ $? -gt 0 ]]; then
57
 
    echo "    Can't find tool \"ffmpeg\" (Required)."
58
 
    __SANITY=false
59
 
  fi
60
 
  
61
 
  if [[ $___SANITY == false ]]; then
62
 
    echo "Please install the missing tools."
63
 
    echo ""
64
 
    exit 1
65
 
  fi
 
32
  exit
66
33
}
67
34
 
68
35
function __do_cleanup () {
69
36
  rm $__TMP_IMAGE_NAME
70
37
}
71
38
 
72
 
function __do_convertion_gif () {
73
 
  ffmpeg\
 
39
function __do_convertion () {
 
40
  ffmpeg -loop 1\
 
41
         -i "$__TMP_IMAGE_NAME"\
74
42
         -i "$__IN_NAME"\
75
 
         -ignore_loop 0\
76
 
         -i "$__TMP_IMAGE_NAME"\
77
43
         -c:v libx264 -tune stillimage\
78
44
         -c:a aac -b:a 256k -pix_fmt yuv420p\
79
45
         -vf "pad=ceil(iw/2)*2:ceil(ih/2)*2" -shortest\
80
46
         "$__OUT_NAME"
81
47
}
82
48
 
83
 
function __do_convertion () {
84
 
  
85
 
  case $__TMP_IMAGE_NAME in
86
 
    ## FIXME: See if there are othre fileformats that need looping and such.
87
 
    *.gif)
88
 
      __do_convertion_gif
89
 
    ;;
90
 
    *)
91
 
    
92
 
    ffmpeg -loop 1\
93
 
           -i "$__TMP_IMAGE_NAME"\
94
 
           -i "$__IN_NAME"\
95
 
           -c:v libx264 -tune stillimage\
96
 
           -c:a aac -b:a 256k -pix_fmt yuv420p\
97
 
           -vf "pad=ceil(iw/2)*2:ceil(ih/2)*2" -shortest\
98
 
           "$__OUT_NAME"
99
 
    ;;
100
 
  esac
101
 
}
102
 
 
103
49
 
104
50
function __parse_args () {
105
51
  if [[ -z "$1" ]]
114
60
    
115
61
    case "${1}" in
116
62
      -i)
117
 
        __IN_NAME="$2"
 
63
      __IN_NAME="$2"
118
64
      shift
119
65
      shift
120
66
      ;;
121
67
      -o)
122
 
        __OUT_NAME="$2"
 
68
      __OUT_NAME="$2"
123
69
      shift
124
70
      shift
125
71
      ;;
126
72
      --image)
127
 
        __USE_DIFFERENT_IMAGE=true
128
 
        __OTHER_IMAGE_NAME="$2"
129
 
      shift
130
 
      shift
131
 
      ;;
132
 
      --loop)
133
 
        __LOOP=true
 
73
      __USE_DIFFERENT_IMAGE=true
 
74
      __OTHER_IMAGE_NAME="$2"
 
75
      shift
134
76
      shift
135
77
      ;;
136
78
      -h|--help)
137
 
        __usage
 
79
      __usage
138
80
      exit
139
81
      shift
140
82
      ;;
141
83
      *)
142
 
        __usage
 
84
      __usage
143
85
      exit 1
144
86
      shift
145
87
      ;;
452
394
 
453
395
 
454
396
function __main () {
455
 
  __sanity_check
456
 
  __parse_args "${@}"
457
 
 
 
397
  
458
398
  if [[ $__USE_DIFFERENT_IMAGE == true ]]
459
399
  then
460
400
    # Let's not make this any more complicated.
475
415
    exit 1
476
416
  fi
477
417
  
 
418
  
478
419
  __do_convertion
479
420
  
480
421
  if [[ $__USE_DIFFERENT_IMAGE == false ]]
483
424
  fi
484
425
}
485
426
 
486
 
__main "${@}"
 
427
__parse_args "${@}"
 
428
__main