embed-audio.sh 538 B

123456789101112131415161718
  1. #!/usr/bin/env bash
  2. set -euo pipefail # bash strict mode
  3. # audio=$(find ./ -type f | grep "ogg$\|mp3$\|opus$\|flac$\|wav$\|m4a$" | head -n 1)
  4. audio=$(find-type.sh -a | head -n 1)
  5. while getopts ':a:h' opt; do
  6. case "$opt" in
  7. a) audio="$OPTARG" ;;
  8. h|\?|:|*) display_help ;;
  9. esac
  10. done
  11. shift $((OPTIND-1))
  12. [[ "$#" -lt 1 || ! -f $audio ]] && display_help
  13. for input_file in "$@"; do
  14. output_file="audio-embedded_${input_file}"
  15. ffmpeg -i "$input_file" -i "$audio" -c copy -map 0:v:0 -map 1:a:0 "$output_file"
  16. done