/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-07-10 14:25:13 UTC
  • Revision ID: git-v1:55fc68b13933a25315ad96a4c69e64d962d2c2d4
Fixed install script's --target flag.

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
 
#
10
6
# Changes
11
7
#
12
8
# 2021-01-31:
16
12
# 2022-03-22:
17
13
#   * Make script work with gifs, and Make gifs loop.
18
14
#
19
 
# 2024-07-10:
20
 
#   * Fixed some formating errors.
21
 
#   * Added sanity check.
22
 
#   * Use /tmp/ instead of writing to FS.
23
15
######
24
16
 
25
 
__SANITY=true
26
 
 
27
 
# FIXME: Use mktemp or mkdtemp instea of usin /tmp/ directly
28
 
__TMP_IMAGE_NAME=/tmp/__SPEAKER_IMAGE.PNG
 
17
__TMP_IMAGE_NAME=__SPEAKER_IMAGE.PNG
29
18
__OUT_NAME=""
30
19
__IN_NAME=""
31
20
 
42
31
  echo "-o <video.mp4>        The output for the video."
43
32
  echo " "
44
33
  echo "--image <image.[png,gif]>"
45
 
  echo "                      Image to use. If none is provided a standard image"
 
34
  echo "                      Image to use. If non is provided a standard image"
46
35
  echo "                      will be used."
47
36
  echo ""
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
 
37
  exit
70
38
}
71
39
 
72
40
function __do_cleanup () {
74
42
}
75
43
 
76
44
function __do_convertion_gif () {
77
 
  ffmpeg\
78
 
         -i "$__IN_NAME"\
79
 
         -ignore_loop 0\
80
 
         -i "$__TMP_IMAGE_NAME"\
81
 
         -c:v libx264 -tune stillimage\
82
 
         -c:a aac -b:a 256k -pix_fmt yuv420p\
83
 
         -vf "pad=ceil(iw/2)*2:ceil(ih/2)*2" -shortest\
84
 
         "$__OUT_NAME"
 
45
    ffmpeg\
 
46
           -i "$__IN_NAME"\
 
47
           -ignore_loop 0\
 
48
           -i "$__TMP_IMAGE_NAME"\
 
49
           -c:v libx264 -tune stillimage\
 
50
           -c:a aac -b:a 256k -pix_fmt yuv420p\
 
51
           -vf "pad=ceil(iw/2)*2:ceil(ih/2)*2" -shortest\
 
52
           "$__OUT_NAME"
85
53
}
86
54
 
87
55
function __do_convertion () {
92
60
      __do_convertion_gif
93
61
    ;;
94
62
    *)
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
 
    ;;
 
63
      ffmpeg -loop 1\
 
64
            -i "$__TMP_IMAGE_NAME"\
 
65
            -i "$__IN_NAME"\
 
66
            -c:v libx264 -tune stillimage\
 
67
            -c:a aac -b:a 256k -pix_fmt yuv420p\
 
68
            -vf "pad=ceil(iw/2)*2:ceil(ih/2)*2" -shortest\
 
69
            "$__OUT_NAME"
 
70
     ;;
104
71
  esac
105
72
}
106
73
 
456
423
 
457
424
 
458
425
function __main () {
459
 
  __sanity_check
460
 
  __parse_args "${@}"
461
 
 
 
426
  
462
427
  if [[ $__USE_DIFFERENT_IMAGE == true ]]
463
428
  then
464
429
    # Let's not make this any more complicated.
479
444
    exit 1
480
445
  fi
481
446
  
 
447
  
482
448
  __do_convertion
483
449
  
484
450
  if [[ $__USE_DIFFERENT_IMAGE == false ]]
487
453
  fi
488
454
}
489
455
 
490
 
__main "${@}"
 
456
__parse_args "${@}"
 
457
__main