Guest User

convert_DTS_ac3

a guest
Nov 2nd, 2015
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 7.24 KB | None | 0 0
  1. #!/bin/sh                                                                                                              
  2.                                                                                                                                                                                                                                        
  3.                                                                                                                        
  4. ffprobe="/volume1/homes/user/ffmpeg/bin/ffprobe"                                                                        
  5. ffmpeg="/volume1/homes/user/ffmpeg/bin/ffmpeg"                                                                          
  6.                                                                                                                        
  7. ##  cleanup by deleting unwanted files                                                                                  
  8. find "$1" -name "*.txt" -type f -print0 | xargs -0 rm -rf                                                              
  9. find "$1" -name "*.db" -type f -print0 | xargs -0 rm -rf                                                                
  10. find "$1" -name "*.nfo" -type f -print0 | xargs -0 rm -rf                                                              
  11. find "$1" -name "*sample*.mkv" -type f -print0 | xargs -0 rm -rf                                                        
  12. find "$1" -name "*Sample*.mkv" -type f -print0 | xargs -0 rm -rf                                                        
  13. find "$1" -name "*SAMPLE*.mkv" -type f -print0 | xargs -0 rm -rf                                                        
  14.                                                                                                                        
  15. ##  go over all MKVs                                                                                                    
  16. find "$1" -name "*.mkv" -type f | while read f                                                                          
  17. do                                                                                                                      
  18. #echo processing $f                                                                                                    
  19. ##  Detect what audio codec is being used:                                                                              
  20. audio=$($ffprobe "$f" 2>&1 | sed -n '/Audio:/s/.*: \([a-zA-Z0-9]*\).*/\1/p' | sed 1q)                                  
  21. aopts="-c:a ac3 -b:a 640k"                                                                                              
  22. ##  Set default video settings:                                                                                        
  23. vopts="-c:v copy"                                                                                                      
  24. ##  Set default subtitle settings:                                                                                      
  25. sopts="-c:s copy"                                                                                                      
  26.                                                                                                                        
  27. echo "$f -----> audio is $audio" | grep dts                                                                            
  28.                                                                                          
  29.     case "$audio" in                                                                                                    
  30.         aac|alac|mp3|mp2|ac3 )                                                                                          
  31. ##  If the audio is one of the MP4-supported codecs                                                                    
  32.                         echo "-----> no processing needed."                                                            
  33.             ;;                                                                                                          
  34.         "" )                                                                                                            
  35. ##  If there is no detected audio stream, don't bother                                                                  
  36.                         echo "-----> can't determine audio, skipping"                                                  
  37.             ;;                                                                                                          
  38.         * )                                                                                                            
  39. ##  anything else, convert                                                                                              
  40.                          mv "$f" "$f"-1                                                                                
  41.              echo -e "\n -----> executing $ffmpeg -y -i $f-1 -map 0 $sopts $vopts $aopts $f"                            
  42.              $ffmpeg -hwaccel auto -nostdin -y -i "$f"-1 -map 0 $sopts $vopts $aopts "$f"                              
  43.                          fail=$?                                                                                        
  44.                          case "$fail" in                                                                                
  45.                            "0" )                                                                                        
  46. ##  put new file in place                                                                                              
  47.                            echo "-----> SUCCES"                                                                        
  48.                            rm -rf "$f"-1                                                                                
  49.                            chmod 666 "$f"                                                                              
  50.                            synoindex -D "$f"                                                                            
  51.                synoindex -A "$f"                                                                                        
  52.                            ;;                                                                                          
  53.                            * )                                                                                          
  54.                            echo "-----> FAIL"                                                                          
  55. ##  revert back                                                                                                        
  56.                            rm -rf "$f"                                                                                  
  57.                            mv "$f"-1 "$f"                                                                              
  58.                            ;;                                                                                          
  59.                          esac                                                                                          
  60.           ;;                                                                                                            
  61.     emac
  62.  
  63. done
Advertisement
Add Comment
Please, Sign In to add comment