Guest User

soundpost script

a guest
Apr 18th, 2025
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.58 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. echo -e "Usage: reverse-soundpost <soundpost>"
  4.  
  5. soundpost=$1
  6. soundpostfilename=${soundpost##*'/'}
  7. afterdot=${soundpostfilename##*'.'}
  8. name=${soundpostfilename%%'['*}
  9. beforebracket=${soundpostfilename%%']'*}
  10. soundsource=${beforebracket##*'['}
  11. link=$(echo "$soundsource" | tail -c +7 | sed 's|%2F|/|g; s|%3A|:|g')
  12. sourceafterdot=${link##*'.'}
  13. soundfile="/tmp/soundsource.$sourceafterdot"
  14.  
  15. echo "Sound source located as $link"
  16.  
  17. wget "$link" -O "$soundfile"
  18. sleep 1
  19.  
  20. # Determine audio codec
  21. audiocodec=$(ffprobe -v error -select_streams a:0 -show_entries stream=codec_name -of default=nokey=1:noprint_wrappers=1 "$soundfile")
  22.  
  23. # Determine container and audio codec options
  24. if [[ "$audiocodec" == "opus" || "$audiocodec" == "vorbis" ]]; then
  25.     container="webm"
  26.     acodec="copy"
  27.     vcodec="libvpx-vp9"
  28. elif [[ "$audiocodec" == "aac" || "$audiocodec" == "mp3" || "$audiocodec" == "flac" ]]; then
  29.     container="mp4"
  30.     acodec="copy"
  31.     vcodec="libx264"
  32. else
  33.     container="mp4"
  34.     acodec="aac"
  35.     vcodec="libx264"
  36. fi
  37.  
  38. echo "Audio codec is $audiocodec — using .$container container, video codec $vcodec, audio codec $acodec"
  39.  
  40.  
  41. if [ "$afterdot" == "gif" ]; then
  42.     ffmpeg -stream_loop -1 -i "$soundpost" -i "$soundfile" -shortest -c:v "$vcodec" -c:a "$acodec" "$name.$container"
  43. elif [[ "$afterdot" == "png" || "$afterdot" == "jpeg" || "$afterdot" == "jpg" ]]; then
  44.     ffmpeg -loop 1 -i "$soundpost" -i "$soundfile" -shortest -c:v "$vcodec" -c:a "$acodec" -r 1 "$name.$container"
  45. else
  46.     ffmpeg -i "$soundpost" -i "$soundfile" -c:v copy "$name.$afterdot"
  47. fi
Advertisement
Add Comment
Please, Sign In to add comment