convert-media.sh 790 B

123456789101112131415161718192021222324252627
  1. #!/usr/bin/env bash
  2. set -euo pipefail # bash strict mode
  3. #converts video or audio file with any extension to extension precised with first parameter
  4. display_help(){
  5. echo "Usage: ${0##*/} -e [extension] -a [audio-bitrate] -v [video-bitrate] [file/s]"
  6. echo "Example: ${0##*/} -e opus Despacito.flac GangnamStype.wav"
  7. echo "Example: ${0##*/} -e webm Video1.mp4 *.mkv"
  8. exit 2
  9. }
  10. [[ "$#" -lt 2 ]] && display_help
  11. while getopts 'a:v:e:h' opt; do
  12. case "$opt" in
  13. a) output_opt+=(-b:a "${OPTARG}") ;;
  14. v) output_opt+=(-b:v "${OPTARG}") ;;
  15. e) ext="$OPTARG" ;;
  16. h|\?|:|*) display_help ;;
  17. esac
  18. done
  19. shift $((OPTIND-1))
  20. for inputf in "$@";do
  21. outputf="${inputf%.*}.${ext}"
  22. ffmpeg -y -i "$inputf" -vsync 2 "${output_opt[@]}" "$outputf"
  23. done