Guest User

Untitled

a guest
Dec 11th, 2018
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.57 KB | None | 0 0
  1. # 8 mebibytes expressed in bits. 512 bytes leeway for request.
  2. MAX_SIZE=$(( (1024 * 1024 * 8 - 512) * 8 ))
  3.  
  4. file_name="${1%.*}"
  5. audio_bitrate="$(ffprobe -v error -select_streams a:0 -show_entries stream=bit_rate -of default=noprint_wrappers=1:nokey=1 "$1" | awk '{sum+=$1} END {print sum}')"
  6.  
  7. if [ -z "$2" ]
  8. then
  9. seek=""
  10. duration="$(ffprobe -v error -show_entries format=duration -of default=noprint_wrappers=1:nokey=1 "$1")"
  11. else
  12. seek="-sseof -$2"
  13. duration=$(echo $2 | sed -E 's/(.*):(.+):(.+)/\1*3600+\2*60+\3/;s/(.+):(.+)/\1*60+\2/' | bc -l)
  14. fi
  15.  
  16. video_bitrate=$(echo "(($MAX_SIZE + $duration - 1) / $duration - $audio_bitrate) * 0.98" | bc) # Ceiling division, 2% overhead
  17. bufsize=$(echo "$video_bitrate / 2" | bc)
  18.  
  19. ffmpeg \
  20. -hide_banner -loglevel 32 -y \
  21. $seek \
  22. -i "$1" \
  23. -c:v libx264 \
  24. -x264-params "nal-hrd=cbr" \
  25. -b:v $video_bitrate \
  26. -minrate $video_bitrate \
  27. -maxrate $video_bitrate \
  28. -bufsize $bufsize \
  29. -r 30 \
  30. -vf scale=-1:720 \
  31. -pass 1 \
  32. -passlogfile "${file_name}_2pass" \
  33. -an \
  34. -f mp4 /dev/null \
  35. && ffmpeg \
  36. -hide_banner -loglevel 32 \
  37. $seek \
  38. -i "$1" \
  39. -c:v libx264 \
  40. -x264-params "nal-hrd=cbr" \
  41. -b:v $video_bitrate \
  42. -minrate $video_bitrate \
  43. -maxrate $video_bitrate \
  44. -bufsize $bufsize \
  45. -r 30 \
  46. -vf scale=-1:720 \
  47. -pass 2 \
  48. -passlogfile "${file_name}_2pass" \
  49. -c:a copy \
  50. -map 0:v -map 0:a \
  51. "${file_name}_8mb.mp4"
  52.  
  53. find . -name "${file_name}_2pass*.log*" -type f -delete
Add Comment
Please, Sign In to add comment