embed-cover.sh 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. #!/usr/bin/env bash
  2. set -euo pipefail # bash strict mode
  3. # if [ "$#" -ge 2 ];then
  4. # for x in "${@:2}";do
  5. # cp "$x" "new_${x}"
  6. # # ffmpeg -i "$x" -i "$1" -map 0 -map 1 -c copy -disposition:v:1 attached_pic "new_${x}"
  7. # ffmpeg -i "$x" -i "$1" -map 0 -map 1 -c copy -disposition:v:1 attached_pic "new_${x}"
  8. # done
  9. # else
  10. # echo Usage: "${0##*/}" '[cover/image] [audio file/s]'
  11. # fi
  12. # defaults
  13. cover=$(find ./ -type f -size -2M | grep -i "cover\|artwork\|front" | head -n 1 )
  14. while getopts ':c:h' opt; do
  15. case "$opt" in
  16. c) cover="$OPTARG" ;;
  17. h|\?|:|*) display_help ;;
  18. esac
  19. done
  20. shift $((OPTIND-1))
  21. [[ "$#" -lt 1 || ! -f $cover ]] && display_help
  22. for infile in "$@"; do
  23. ext="${infile##*.}"
  24. outfile="${infile%.*}_cover-embedded.${ext}"
  25. [[ $ext == 'webm' ]] && \
  26. ffmpeg -i "$infile" -loop 1 -i "$cover" -r 1 "$outfile" && \
  27. continue
  28. ffmpeg -i "$infile" -i "$cover" -map 0:a -map 1 -codec copy \
  29. -metadata:s:v title="Album cover" -metadata:s:v \
  30. comment="Cover (front)" -disposition:v attached_pic \
  31. "$outfile"
  32. done
  33. # # some guy from 4chan said...
  34. # ffmpeg -i INPUT -c:v libvpx -crf 4 -b:v 1500K -vf scale=320:-1 -an output.webm