/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: 2024-11-02 21:19:08 UTC
  • Revision ID: gustav.hartvigsson@gmail.com-20241102211908-ad9nwyj2sf3mpepv
* That's awkard...

Show diffs side-by-side

added added

removed removed

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