Advertisement
Onryo

2 pass encoder for ffmpeg

Nov 18th, 2012
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.79 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. clear
  4.  
  5. echo "      2 pass compression program for FFmpeg"
  6. echo "      -------------------------------------"
  7. echo "Enter the size in MB of the finished video"
  8. read totSizeMB
  9. echo "How many kilobits would you like your sound. Enter 128 if not sure"
  10. read sound
  11.  
  12.  
  13. ffmpegResize=/tmp/sizetime
  14. ffprobe -i "$@" 2>$ffmpegResize
  15. title=$(grep Input $ffmpegResize |awk -F "'" '{print $2}')
  16. movieTimeSec=$(awk '/Duration/ {gsub(/,/, "", $2); split($2, a, /:/); print 3600*a[1] + 60*a[2] + a[3]}' $ffmpegResize)
  17. audioSize=$(awk "BEGIN { print $sound*$movieTimeSec/8192 }")
  18. videoSize=$(awk "BEGIN { print $totSizeMB-$audioSize }")
  19. videoBitRate=$(awk "BEGIN { print $videoSize*8192/$movieTimeSec }")
  20.  
  21. videoBR="${videoBitRate}k"
  22. audioBR="${sound}k"
  23.  
  24. clear
  25.  
  26. echo
  27. echo "Do you want to compress your video as follows y/n"
  28. echo "---------------------------------------"
  29. echo "Title           ::" $title
  30. echo "Sound Bit Rate  ::" $sound "Kbps"
  31. echo "Avg Video Rate  ::" $videoBitRate "Kbps"
  32. echo "Size When Done  ::" $totSizeMB "MB"
  33. echo "Video Size      ::" $videoSize "MB"
  34. echo "Audio Size      ::" $audioSize "MB"
  35. echo "Film Duration   ::" $movieTimeSec "sec"
  36. read
  37.  
  38. #ffmpeg -i $title -pass 1 -vcodec libx264 -preset veryslow -b:v $videoBR -f matroska -sn -an -y /dev/null && ffmpeg -i $title -pass 2 -vcodec libx264 -preset veryslow -b:v $videoBR -acodec libfaac -b:a $audioBR -ac 2 -sn -y ${title%.*}.$totSizeMB.mkv
  39.  
  40. # Read on Arch https://wiki.archlinux.org/index.php/FFmpeg
  41. ffmpeg -i $title -an -vcodec libx264 -pass 1 -preset veryslow -threads 0 -b $videoBR -x264opts frameref=15:fast_pskip=0 -f rawvideo -y /dev/null
  42. ffmpeg -i $title -acodec libfaac -b:a $audioBR -ac 2 -vcodec libx264 -pass 2 -preset veryslow -threads 0 -b $videoBR -x264opts frameref=15:fast_pskip=0 ${title%.*}.$totSizeMB.mkv
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement