6
__TMP_IMAGE_NAME=__SPEAKER_IMAGE.PNG
4
# FILE NAME: wav2mp4.sh
7
# Gustav Hartvigsson 2024
8
# Distributed under the Cool Licence 1.1
13
# * Fixed up if statments
17
# * Make script work with gifs, and Make gifs loop.
20
# * Fixed some formating errors.
21
# * Added sanity check.
22
# * Use /tmp/ instead of writing to FS.
27
# FIXME: Use mktemp or mkdtemp instea of usin /tmp/ directly
28
__TMP_IMAGE_NAME=/tmp/__SPEAKER_IMAGE.PNG
10
32
__USE_DIFFERENT_IMAGE=false
14
38
echo "wav2mp4.sh --- Convert audio to a video for upload. "
16
40
echo "-i <audio.wav> The input audio."
18
42
echo "-o <video.mp4> The output for the video."
20
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"
21
46
echo " will be used."
51
function __silent () {
56
function __sanity_check () {
57
# Check that we have the tools needed.
58
___silent which ffmpeg
60
if [[ $? -gt 0 ]]; then
61
echo " Can't find tool \"ffmpeg\" (Required)."
65
if [[ $___SANITY == false ]]; then
66
echo "Please install the missing tools."
72
function __do_cleanup () {
28
73
rm $__TMP_IMAGE_NAME
76
function __do_convertion_gif () {
33
80
-i "$__TMP_IMAGE_NAME"\
35
81
-c:v libx264 -tune stillimage\
36
82
-c:a aac -b:a 256k -pix_fmt yuv420p\
37
83
-vf "pad=ceil(iw/2)*2:ceil(ih/2)*2" -shortest\
87
function __do_convertion () {
89
case $__TMP_IMAGE_NAME in
90
## FIXME: See if there are othre fileformats that need looping and such.
97
-i "$__TMP_IMAGE_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\
108
function __parse_args () {
45
111
echo "Try --help or -h."
159
function __write_image () {
91
160
__IMAGE_BASE64="iVBORw0KGgoAAAANSUhEUgAAAfQAAAH0CAQAAABh3xcBAAAZEHpUWHRSYXcgcHJvZmlsZSB0eXBl
92
161
IGV4aWYAAHja1ZtZdhy3GYXfsYosAfOwHIznZAdZfr6LalEURdmmnDyYdNRks7oK+Ic7AIjZ//n3
93
162
Mf/iKxebTUyl5paz5Su22Hznh2qfr+fV2Xj/vV8nvn5yP75v3v7geQ28hucPeT+vrvN++v6BEl/v
399
if [ ! -e "$__IN_NAME" ]
470
if [[ ! -e "$__IN_NAME" ]]
401
472
echo "missing input audio. Please provide."
405
if [ $__OUT_NAME == "" ]
476
if [[ $__OUT_NAME == "" ]]
407
478
echo "missing output file name. Please provide."
414
if [ $__USE_DIFFERENT_IMAGE = false ]
484
if [[ $__USE_DIFFERENT_IMAGE == false ]]