overay-ffmpeg 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  1. #!/bin/bash
  2. version="0.1.0"
  3. videoFile=''
  4. picFile=''
  5. outputName=''
  6. outputFolder=''
  7. allowCacheStay=0
  8. tempFolder=/tmp/4dage-ffmpeg
  9. time=$(date "+%Y%m%d-%H%M%S")
  10. tempFilePrefix="4dage-source-${time}"
  11. declare -a outputVideoList=('mp4 flv')
  12. red=$(tput setaf 1)
  13. green=$(tput setaf 2)
  14. reset=$(tput sgr0)
  15. command_exists() {
  16. if ! [[ -x $(command -v "$1") ]]; then
  17. return 1
  18. fi
  19. return 0
  20. }
  21. print_usage() {
  22. echo -e "\033[43;34m $package - 4dage overlay custom version for ffmpeg: \033[0m"
  23. echo "${green}If have problem with this, please contact with gemer AKA: 张宇鹏<zhangyupeng@cgaii.com>"
  24. echo "$package [options] application [arguments]"
  25. echo " "
  26. echo "${red}options:"
  27. echo "-h, --help show brief help"
  28. echo "-s, --source=source file path input the video source path"
  29. echo "-p, --pic=picture file path picture file path"
  30. echo "-n, --name=output file name output file name"
  31. echo "-o, --output=DIR specify a directory to store output in"
  32. echo "-v, --version output verison"
  33. echo "--cahche maintain the cahche file for tmp folder"
  34. echo " "
  35. echo -e "\033[0;33m"
  36. cat <<EOF
  37. _oo0oo_
  38. 088888880
  39. 88" . "88
  40. (| -_- |)
  41. 0\ = /0
  42. ___/'---'\___
  43. .' \\\\| |// '.
  44. / \\\\||| : |||// \\
  45. /_ ||||| -:- |||||- \\
  46. | | \\\\\\ - /// | |
  47. | \_| ''\---/'' |_/ |
  48. \ .-\__ '-' __/-. /
  49. ___'. .' /--.--\ '. .'___
  50. ."" '< '.___\_<|>_/___.' >' "".
  51. | | : '- \'.;'\ _ /';.'/ - ' : | |
  52. \ \ '_. \_ __\ /__ _/ .-' / /
  53. ====='-.____'.___ \_____/___.-'____.-'=====
  54. '=---='
  55. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  56. 佛祖保佑 TTT 万无一失
  57. EOF
  58. echo -e "\033[m"
  59. }
  60. make_temp_dir() {
  61. # # Make a temp folder
  62. if [ ! -d $tempFolder ]; then
  63. mkdir -p $tempFolder && chmod 776 $tempFolder
  64. fi
  65. }
  66. make_temp_dir
  67. while test $# -gt 0; do
  68. case "$1" in
  69. -h | --help)
  70. print_usage
  71. exit 0
  72. ;;
  73. -s)
  74. shift
  75. if test $# -gt 0; then
  76. export videoFile=$1
  77. else
  78. echo "{$red}no video path specified"
  79. exit 1
  80. fi
  81. shift
  82. ;;
  83. --source*)
  84. export videoFile=$(echo $1 | sed -e 's/^[^=]*=//g')
  85. echo $1
  86. shift
  87. ;;
  88. -p)
  89. shift
  90. if test $# -gt 0; then
  91. export picFile=$1
  92. else
  93. echo "{$red}no picFile specified"
  94. exit 1
  95. fi
  96. shift
  97. ;;
  98. --pic*)
  99. export picFile=$(echo $1 | sed -e 's/^[^=]*=//g')
  100. shift
  101. ;;
  102. -o)
  103. shift
  104. if test $# -gt 0; then
  105. export outputFolder=$1
  106. else
  107. echo "{$red}no output dir folder specified"
  108. exit 1
  109. fi
  110. shift
  111. ;;
  112. --output*)
  113. export outputFolder=$(echo $1 | sed -e 's/^[^=]*=//g')
  114. shift
  115. ;;
  116. -n)
  117. shift
  118. if test $# -gt 0; then
  119. export outputName=$1
  120. else
  121. echo "no output video name specified"
  122. exit 1
  123. fi
  124. shift
  125. ;;
  126. --name*)
  127. export outputName=$(echo $1 | sed -e 's/^[^=]*=//g')
  128. shift
  129. ;;
  130. --cache)
  131. shift
  132. echo "allow cahche remain"
  133. export allowCacheStay=1
  134. shift
  135. ;;
  136. -v)
  137. echo "$version"
  138. shift
  139. ;;
  140. *)
  141. print_usage
  142. # echo "111"
  143. break
  144. ;;
  145. esac
  146. done
  147. mkVerison() {
  148. touch "$outputFolder/overlay-ffmpeg.$version.version"
  149. }
  150. takeVideoCap() {
  151. FFREPORT=file="$outputFolder/$outputName.cap.txt":level=48 ffmpeg -hide_banner -loglevel error -y -i "$outputFolder/$outputName.mp4" -r 1 -ss 00:00:01 -vframes 1 -vf "transpose=1,scale=iw/5:ih/5,setsar=1:1" -f image2 "$outputFolder/$outputName.jpg"
  152. }
  153. covertVideoTask() {
  154. videoFileType=${videoFile##*.}
  155. picFileType=${picFile##*.}
  156. FFREPORT=file="$outputFolder/$outputName.$videoFileType.txt":level=48 ffmpeg -hide_banner -i $picFile -c:v libvpx -i $videoFile -filter_complex "overlay=alpha=0.9" -vcodec libx264 "$outputFolder/$outputName.mp4" -y
  157. FFREPORT=file="$outputFolder/$outputName.$videoFileType.txt":level=48 ffmpeg -hide_banner -i $picFile -c:v libvpx -i $videoFile -filter_complex "overlay=alpha=0.9" -vcodec libx264 "$outputFolder/$outputName.flv" -y
  158. # FFREPORT=file="$outputFolder/$outputName.$videoFileType.txt":level=32 ffmpeg -i $tempVideo -s 1056x792 -c:v libx264 -profile:v high -level:v 4.1 -vf "scale=iw/2:ih/2" -pix_fmt yuv420p -movflags +faststart -bf 2 -c:a copy "$outputFolder/$outputName.$videoFileType" -y
  159. # FFREPORT=file="$outputFolder/$outputName.flv.txt":level=32 ffmpeg -i $tempVideo -s 1056x792 -c:v libx264 -ar 44100 -profile:v high -level:v 4.1 -vf "scale=iw/2:ih/2" -pix_fmt yuv420p -movflags +faststart -bf 2 -c:a copy "$outputFolder/$outputName.flv" -y
  160. takeVideoCap
  161. mkVerison
  162. }
  163. concatAllLogFile() {
  164. cat $outputFolder/*.txt >>"$outputFolder/$outputName.full.log"
  165. rm $outputFolder/*.txt
  166. }
  167. if [ ! -z $videoFile ] && [ ! -z $picFile ] && [ ! -z $outputName ] && [ ! -z $outputFolder ]; then
  168. if [ ! -d $outputFolder ]; then
  169. mkdir -p $outputFolder
  170. fi
  171. covertVideoTask
  172. concatAllLogFile
  173. if command_exists "mediainfo"; then
  174. mediainfo --fullscan "$outputFolder/$outputName.$videoFileType" --Output=JSON >"$outputFolder/$outputName.json"
  175. mediainfo --fullscan "$outputFolder/$outputName.flv" --Output=JSON >"$outputFolder/$outputName.flv.json"
  176. fi
  177. echo "\033[0;32m"
  178. cat <<EOF
  179. _oo0oo_
  180. 088888880
  181. 88" . "88
  182. (| -_- |)
  183. 0\ = /0
  184. ___/'---'\___
  185. .' \\\\| |// '.
  186. / \\\\||| : |||// \\
  187. /_ ||||| -:- |||||- \\
  188. | | \\\\\\ - /// | |
  189. | \_| ''\---/'' |_/ |
  190. \ .-\__ '-' __/-. /
  191. ___'. .' /--.--\ '. .'___
  192. ."" '< '.___\_<|>_/___.' >' "".
  193. | | : '- \'.;'\ _ /';.'/ - ' : | |
  194. \ \ '_. \_ __\ /__ _/ .-' / /
  195. ====='-.____'.___ \_____/___.-'____.-'=====
  196. '=---='
  197. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  198. 佛祖保佑 TTT 顺利转换
  199. EOF
  200. echo "\033[m"
  201. echo "covert done!"
  202. else
  203. if [ ! -n "$1" ]; then
  204. print_usage
  205. else
  206. if [ -z $videoFile ]; then
  207. echo "${red}miss video file path: 缺视频文件路径"
  208. fi
  209. if [ -z $picFile ]; then
  210. echo "${red}miss audio file path : 缺背影图像少文件路径"
  211. fi
  212. if [ -z $outputName ]; then
  213. echo "${red}miss file name : 缺音输出文件名称"
  214. fi
  215. if [ -z $outputFolder ]; then
  216. echo "${red}miss output path : 缺音输出路径"
  217. fi
  218. fi
  219. fi