Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- echo -e "Usage: reverse-soundpost <soundpost>"
- soundpost=$1
- soundpostfilename=${soundpost##*'/'}
- afterdot=${soundpostfilename##*'.'}
- name=${soundpostfilename%%'['*}
- beforebracket=${soundpostfilename%%']'*}
- soundsource=${beforebracket##*'['}
- link=$(echo "$soundsource" | tail -c +7 | sed 's|%2F|/|g; s|%3A|:|g')
- sourceafterdot=${link##*'.'}
- soundfile="/tmp/soundsource.$sourceafterdot"
- echo "Sound source located as $link"
- wget "$link" -O "$soundfile"
- sleep 1
- # Determine audio codec
- audiocodec=$(ffprobe -v error -select_streams a:0 -show_entries stream=codec_name -of default=nokey=1:noprint_wrappers=1 "$soundfile")
- # Determine container and audio codec options
- if [[ "$audiocodec" == "opus" || "$audiocodec" == "vorbis" ]]; then
- container="webm"
- acodec="copy"
- vcodec="libvpx-vp9"
- elif [[ "$audiocodec" == "aac" || "$audiocodec" == "mp3" || "$audiocodec" == "flac" ]]; then
- container="mp4"
- acodec="copy"
- vcodec="libx264"
- else
- container="mp4"
- acodec="aac"
- vcodec="libx264"
- fi
- echo "Audio codec is $audiocodec — using .$container container, video codec $vcodec, audio codec $acodec"
- if [ "$afterdot" == "gif" ]; then
- ffmpeg -stream_loop -1 -i "$soundpost" -i "$soundfile" -shortest -c:v "$vcodec" -c:a "$acodec" "$name.$container"
- elif [[ "$afterdot" == "png" || "$afterdot" == "jpeg" || "$afterdot" == "jpg" ]]; then
- ffmpeg -loop 1 -i "$soundpost" -i "$soundfile" -shortest -c:v "$vcodec" -c:a "$acodec" -r 1 "$name.$container"
- else
- ffmpeg -i "$soundpost" -i "$soundfile" -c:v copy "$name.$afterdot"
- fi
Advertisement
Add Comment
Please, Sign In to add comment