Created
April 24, 2022 16:12
-
-
Save johnd/fba54d1b43777c9c6ac86f1b94e6b957 to your computer and use it in GitHub Desktop.
Script to automate adding a woooop sound to videos.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash -e | |
# | |
# Copyright 2022 John Daniels <[email protected]> | |
# | |
# Usage of the works is permitted provided that this instrument is retained | |
# with the works, so that any entity that uses the works is notified of this | |
# instrument. | |
# DISCLAIMER: THE WORKS ARE WITHOUT WARRANTY. | |
# This script is intended to add a woooooooop sound to short vidoes. | |
# Why? I automate timelapses from my 3d printer and wanted to have some sound. | |
function usage { | |
echo "Usage:" | |
echo "$0 <path to source MP4 file> <path to output MP4 file>" | |
} | |
# Check params | |
ORIGINAL_FILE="$1" | |
if [ ! -f "$ORIGINAL_FILE" ]; then | |
echo "$ORIGINAL_FILE not found!" | |
usage | |
exit 1 | |
fi | |
OUTPUT_FILE="$2" | |
if [ -z "$2" ] | |
then | |
echo "Missing Output File!" | |
usage | |
exit 1 | |
fi | |
# Check dependencies are available | |
if ! command -v ffmpeg &> /dev/null | |
then | |
echo "ffmpeg is not available, please ensure it's installed!" | |
exit 2 | |
fi | |
if ! command -v sox &> /dev/null | |
then | |
echo "sox is not available, please ensure it's installed!" | |
exit 2 | |
fi | |
DURATION=`ffmpeg -i "$ORIGINAL_FILE" 2>&1 | grep "Duration" | cut -d ' ' -f 4 | sed s/,//` | |
AUDIO_FILE="`mktemp`.wav" | |
sox -V -r 44100 -n -b 16 -c 2 $AUDIO_FILE synth $DURATION sin 100+800 vol -20dB | |
ffmpeg -i "$ORIGINAL_FILE" -i $AUDIO_FILE -ab 192k "$OUTPUT_FILE" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment