Advertisement
Guest User

php implementation

a guest
Jul 18th, 2012
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.17 KB | None | 0 0
  1. <?php
  2. print system(" # !/bin/bash
  3. #
  4. #
  5. # ffmpeg libxvid
  6. # --------------------------------------------------------------------------------------------------------
  7. # ffmpeg -i Input-Filename.avi -f mp4 -y \
  8. # -vcodec libxvid -b:v 600k -acodec libfaac -b:a 96k -ac 2 -ar 44100 \
  9. # -r 25 -s 640x272 -aspect 640:360 -vf pad=640:360:0:44 \
  10. # -threads 2 -async 1 -pass 1 /dev/null
  11. # ffmpeg -i Input-Filename.avi -f mp4 \
  12. # -y -vcodec libxvid -b:v 600k -acodec libfaac -b:a 96k -ac 2 -ar 44100 \
  13. # -r 25 -s 640x272 -aspect 640:360 -vf pad=640:360:0:44 \
  14. # -threads 2 -async 1 -pass 2 ./Input-Filename-ffmpeg.mp4
  15. #
  16. # ffmpeg libx264
  17. # ----------------------------------------------------------------------------------------------------------
  18. # ffmpeg -i Input-Filename.avi -f mp4 -y \
  19. # -vcodec libx264 -b:v 600k -acodec libfaac -b:a 96k -ac 2 -ar 44100 \
  20. # -r 25 -s 320x196 -aspect 320:240 -vf pad=320:240:0:22 \
  21. # -threads 2 -async 1 -pass 1 /dev/null
  22. # ffmpeg -i Input-Filename.avi -f mp4 -y \
  23. # -vcodec libx264 -b:v 600k -acodec libfaac -b:a 96k -ac 2 -ar 44100 \
  24. # -r 25 -s 320x196 -aspect 320:240 -vf pad=320:240:0:22 \
  25. # -threads 2 -async 1 -pass 2 ./Input-Filename-ffmpeg.mp4 Usage
  26. # --------------------------------------------------------------------------------------------------------
  27. # Command-line options:
  28. # -a : Video aspect ratio. Could be either 1.77 or 2.35 (default)
  29. # -b : Video bitrate. Should be in the form of 600k (default)
  30. # -c : Video codec. Should be either libx264 or libxvid (default)
  31. # -d : Output directory. Current directory (.) is the default
  32. # -y : Whether to ask confirmation before overwriting any file.
  33. # Should be either "yes" (default) or "no"
  34. # Command-line options
  35. while getopts 'a:b:c:d:o:p:y' opt "$@"; do
  36. case "$opt" in
  37. a) video_aspect="$OPTARG" ;;
  38. b) vbitrate="$OPTARG" ;;
  39. c) video_codec="$OPTARG" ;;
  40. d) output_dir="$OPTARG" ;;
  41. o) addl_options="$OPTARG" ;;
  42. p) passes="$OPTARG" ;;
  43. y) ask_confirmation="no" ;;
  44. esac
  45. done
  46. shift $((OPTIND - 1))
  47. # Defaults
  48. video_aspect="${video_aspect:-2.35}"
  49. video_codec="${video_codec:-libxvid}" # or libx264
  50. vbitrate="${vbitrate:-600k}"
  51. passes="${passes:-2}"
  52. output_dir="${output_dir:-.}"
  53. vpre=""
  54. if [[ "$video_codec" == "libx264" ]]; then
  55. vpre="-vpre ipod320"
  56. aspect="320:240"
  57. if [[ "$video_aspect" == "2.35" ]]; then
  58. resolution="320x196"
  59. pad="pad=320:240:0:22"
  60. elif [[ "$video_aspect" == "1.77" ]]; then
  61. resolution="320x240"
  62. pad="pad=320:240:0:0"
  63. fi;
  64. elif [[ "$video_codec" == "libxvid" ]]; then
  65. aspect="640:360"
  66. if [[ "$video_aspect" == "2.35" ]]; then
  67. resolution="640x272"
  68. pad="pad=640:360:0:44"
  69. elif [[ "$video_aspect" == "1.77" ]]; then
  70. resolution="640x360"
  71. pad="pad=640:360:0:0"
  72. fi;
  73. fi;
  74. echo "Encoding '${#@}' video(s)";
  75. for in_file in "$@"; do
  76. # If the filename has no extension
  77. if [[ -z "$(echo "$in_file" | grep -Ei "\.[a-z]+$")" ]]; then
  78. fname="$(basename "${in_file}")-ffmpeg.mp4"
  79. else
  80. fname="$(basename "$in_file" | sed -sr 's/^(.*)(\.[^.]+)$/\1-ffmpeg.mp4/')"
  81. fi
  82. out_file="${output_dir%/}/${fname}"
  83. # Avoid overwriting files
  84. if [[ "$ask_confirmation" != "no" ]] && [[ -f "$out_file" ]]; then
  85. echo -n "'$out_file' already exists. Do you want to overwrite it? [y/n] "; read response
  86. [[ -z "$(echo "$response" | grep -i "^y")" ]] && continue
  87. fi
  88. # 1st pass
  89. ffmpeg -i "$in_file" \
  90. -f mp4 -y $addl_options \
  91. -vcodec "$video_codec" -b:v "$vbitrate" $vpre \
  92. -acodec libfaac -b:a 96k -ac 2 -ar 44100 \
  93. -r 25 -s "$resolution" -aspect "$aspect" -vf "$pad" \
  94. -threads 2 -async 1 -pass 1 \
  95. "/dev/null"; # $out_file;
  96. # 2nd pass
  97. ffmpeg -i "$in_file" \
  98. -f mp4 -y $addl_options \
  99. -vcodec "$video_codec" -b:v "$vbitrate" $vpre \
  100. -acodec libfaac -b:a 96k -ac 2 -ar 44100 \
  101. -r 25 -s "$resolution" -aspect "$aspect" -vf "$pad" \
  102. -threads 2 -async 1 -pass 2 \
  103. "$out_file";
  104. done
  105. 2>&1");
  106. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement