/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:33:51 UTC
  • Revision ID: gustav.hartvigsson@gmail.com-20241102213351-80kgj6tqguc7da18
Forgot to trigger the offline update...

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:
12
16
# 2022-03-22:
13
17
#   * Make script work with gifs, and Make gifs loop.
14
18
#
 
19
# 2024-07-10:
 
20
#   * Fixed some formating errors.
 
21
#   * Added sanity check.
 
22
#   * Use /tmp/ instead of writing to FS.
15
23
######
16
24
 
17
 
__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
18
29
__OUT_NAME=""
19
30
__IN_NAME=""
20
31
 
31
42
  echo "-o <video.mp4>        The output for the video."
32
43
  echo " "
33
44
  echo "--image <image.[png,gif]>"
34
 
  echo "                      Image to use. If non is provided a standard image"
 
45
  echo "                      Image to use. If none is provided a standard image"
35
46
  echo "                      will be used."
36
47
  echo ""
37
 
  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
38
70
}
39
71
 
40
72
function __do_cleanup () {
42
74
}
43
75
 
44
76
function __do_convertion_gif () {
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"
 
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"
53
85
}
54
86
 
55
87
function __do_convertion () {
60
92
      __do_convertion_gif
61
93
    ;;
62
94
    *)
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
 
     ;;
 
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
    ;;
71
104
  esac
72
105
}
73
106
 
423
456
 
424
457
 
425
458
function __main () {
426
 
  
 
459
  __sanity_check
 
460
  __parse_args "${@}"
 
461
 
427
462
  if [[ $__USE_DIFFERENT_IMAGE == true ]]
428
463
  then
429
464
    # Let's not make this any more complicated.
444
479
    exit 1
445
480
  fi
446
481
  
447
 
  
448
482
  __do_convertion
449
483
  
450
484
  if [[ $__USE_DIFFERENT_IMAGE == false ]]
453
487
  fi
454
488
}
455
489
 
456
 
__parse_args "${@}"
457
 
__main
 
490
__main "${@}"