Advertisement
Guest User

Synology Re-encode AAC script v1.1

a guest
Apr 4th, 2014
999
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 3.47 KB | None | 0 0
  1. #!/bin/sh
  2.  
  3. # Credits to:
  4. # User jeppo77 + http://blog.mobile-harddisk.nl/tutorials/workaround-voor-dts-video-op-ds214play/
  5. #
  6. # Example Usage: /volume1/scripts/Audioconverter/convert.sh /volume1/video/
  7. #
  8.  
  9. #Directories must be defined without trailing slash
  10. rootpath="/volume1/scripts/Audioconverter"
  11.  
  12. #leave as is.
  13. ffprobe="$rootpath/ffprobe"
  14. ffmpeg="$rootpath/ffmpeg"
  15. log="$rootpath/convert.log"
  16.  
  17. echo "This script will reencode audio from video files in: $1"
  18. echo "Logfile is: $log"
  19.  
  20. #Check if any arguments were passed
  21. if [ -z "$1" ]
  22. then
  23.         echo
  24.         echo "Usage: convert.sh [DIR]"
  25.         exit 0
  26. else
  27.         # create new/ empty log
  28.         echo "----- START ------" > "$log"
  29.         echo
  30.         find $1 -name "*.mkv" -type f | while read f
  31.         do
  32.                 echo "processing $f" >> "$log"
  33.                 # get number of audio streams
  34.                 #num_streams=$($ffprobe "$f" -show_streams 2>&1 | grep "codec_type=audio" -c)
  35.                 #echo "streams = $num_streams" >> "$log"
  36.                
  37.                 # Detect what audio codec is being used:
  38.                 audio=$($ffprobe "$f" 2>&1 | grep Audio | sed -n '/Audio:/s/.*: \([a-zA-Z0-9]*\).*/\1/p' | sed 1q)
  39.                 echo "audio = $audio" >> "$log"
  40.                
  41.                 ##  Set default mapping settings:
  42.                 mopts="-map 0"
  43.                 ##  Set default subtitle settings:
  44.                 sopts="-c:s copy"
  45.                 ##  Set default video settings:
  46.                 vopts="-c:v copy"
  47.                 ## Set default audio settings:
  48.                 aopts="-c:a:1 aac -b:a 640k "
  49.                 ##  Set extra settings:
  50.                 eopts=" -strict -2"
  51.                
  52.                 case "$audio" in
  53.                    aac|alac|mp3|mp2) echo "-----> no processing needed." >> "$log" ;;
  54.                    "") echo "-----> can't determine audio, skipping" >> "$log" ;;
  55.                    *)
  56.                    
  57.                                 mv "$f" "$f"-1
  58.                                 #convert to aac surround
  59.                                 $ffmpeg -nostdin -y -i "$f"-1 $mopts $sopts $vopts $aopts $eopts "$f"
  60.                                
  61.                                 fail=$?
  62.                                 case "$fail" in
  63.                                         "0" )
  64.                                                 ##  put new file in place
  65.                                                 echo "-----> SUCCES" >> "$log"
  66.                                                 #remove old file
  67.                                                 rm -rf "$f"-1
  68.                                                 #set rights
  69.                                                 chmod 666 "$f"
  70.                                                 #first remove than add to synology index
  71.                                                 synoindex -D "$f" >> "$log"
  72.                                                 synoindex -A "$f" >> "$log"
  73.                                    ;;
  74.                                    * )
  75.                                                 echo "-----> FAIL" >> "$log"
  76.                                                 ##  revert back
  77.                                                 rm -rf "$f"
  78.                                                 mv "$f"-1 "$f"
  79.                                    ;;
  80.                                  esac
  81.                    
  82.                    ;;
  83.                 esac
  84.  
  85.         done
  86. fi
  87.  
  88. exit 0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement