Advertisement
spikeysnack

surround_to_stereo

Mar 3rd, 2018
163
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.04 KB | None | 0 0
  1. #!/bin/bash
  2. # surround_to_stereo
  3.  
  4. FF=$(which ffmpeg)
  5. [[ ! $FF ]]  && >&2 echo "Can't Find ffmpeg" && exit
  6.  
  7. if [ $# -lt 2 ]; then
  8.   >&2 echo "surround_to_stereo <filename>"
  9.   exit
  10. fi
  11.  
  12. # audio rate -- DVD AC3 5.1 is 448k native
  13. A_RATE="320k"
  14. AENC="libfdk_aac"
  15. # AENC="aac"  # default if not there
  16.  
  17.  
  18. # A_RATE="448k"
  19.  
  20. # use single quotes because parameter requires double inside
  21. AF='-ac 2 -af "pan=stereo|FL=FC+0.30*FL+0.30*BL|FR=FC+0.30*FR+0.30*BR"'
  22.  
  23. # if your hardware does Dolby ProLogic II this will sound better. Mine doesn't.
  24. # AF='aresample=matrix_encoding=dplii -ac 2 -ar 48000 -ab 256k'
  25.  
  26. # fixes backwards-endian audio bytes or does nothing if it is OK
  27. BSF="aac_adtstoasc"
  28.  
  29. fname="${1%.*}"
  30. ext="${1##*.}"
  31. outfile="${fname}.2ch.${ext}"
  32.  
  33.        
  34.  
  35. # 6 to 2 channel  reencode with Dolby II matrix
  36.  
  37. ${FF}  -i "${1}"               \
  38.     -fflags +genpts            \
  39.     -c:v copy                  \
  40.     -c:a ${AENC}"              \
  41.    -b:a "${A_RATE}" "${AF}"   \
  42.    -bsf:a "$BSF"              \
  43.    "${outfile}"
  44.  
  45.  
  46. #END
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement