overlay-ffmpeg 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254
  1. #!/bin/bash
  2. version="0.1.5.1"
  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=(W-w)/2:(H-h)/2,pad=ceil(iw/2)*2:ceil(ih/2)*2" -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=(W-w)/2:(H-h)/2,pad=ceil(iw/2)*2:ceil(ih/2)*2" -vcodec libx264 "$outputFolder/$outputName.flv" -y
  158. FFREPORT=file="$outputFolder/$outputName.$videoFileType.txt":level=48 \
  159. ffmpeg -hide_banner -y -i $picFile -c:v libvpx -i $videoFile -filter_complex "[1:v][0:v]scale2ref[image][video];[video][image]overlay=0:0[v];[v]scale='2*trunc(iw/2)':'2*trunc(ih/2)'[v];[v]split=2[out1][out2]" \
  160. -preset superfast -threads 2 -b 0.5M -minrate 0.5M -maxrate 0.5M -bufsize 1M \
  161. -map '[out1]' -map 1:a? -vcodec libx264 -ab 128k "$outputFolder/$outputName.mp4" -map '[out2]' -map 1:a? -vcodec libx264 -ab 128k "$outputFolder/$outputName.flv"
  162. # FFREPORT=file="$outputFolder/$outputName.$videoFileType.txt":level=48 \
  163. # ffmpeg -hide_banner -i $picFile -c:v libvpx -i $videoFile -filter_complex "[1:v][0:v]scale2ref[image][video];[video][image]overlay[v];[v]scale='2*trunc(iw/2)':'2*trunc(ih/2)'" \
  164. # -movflags +faststart -b 0.5M -minrate 0.5M -maxrate 0.5M -bufsize 1M \
  165. # -vcodec libx264 "$outputFolder/$outputName.flv" -y
  166. # FFREPORT=file="$outputFolder/$outputName.$videoFileType.txt":level=48 \
  167. # ffmpeg -hide_banner -i $picFile -c:v libvpx -i $videoFile \
  168. # -filter_complex "[1:v][0:v]scale2ref[image][video];[video][image]overlay[v];[v]scale='2*trunc(iw/2)':'2*trunc(ih/2)'" \
  169. # -movflags +faststart -b 0.5M -minrate 0.5M -maxrate 0.5M -bufsize 1M -vcodec libx264 "$outputFolder/$outputName.flv" -y
  170. # ffmpeg -y -i background-2.jpeg -c:v libvpx -i Human_alpha_2.webm \
  171. # -filter_complex "[1:v][0:v]scale2ref[image][video];[video][image]overlay[v];[v]scale='2*trunc(iw/2)':'2*trunc(ih/2)'" \
  172. # -movflags +faststart -b 0.5M -minrate 0.5M -maxrate 0.5M -bufsize 1M -vcodec libx264 output.mp4
  173. takeVideoCap
  174. mkVerison
  175. }
  176. concatAllLogFile() {
  177. cat $outputFolder/*.txt >>"$outputFolder/$outputName.full.log"
  178. rm $outputFolder/*.txt
  179. }
  180. if [ ! -z $videoFile ] && [ ! -z $picFile ] && [ ! -z $outputName ] && [ ! -z $outputFolder ]; then
  181. if [ ! -d $outputFolder ]; then
  182. mkdir -p $outputFolder
  183. fi
  184. covertVideoTask
  185. concatAllLogFile
  186. if command_exists "mediainfo"; then
  187. mediainfo --fullscan "$outputFolder/$outputName.mp4" --Output=JSON >"$outputFolder/$outputName.json"
  188. mediainfo --fullscan "$outputFolder/$outputName.flv" --Output=JSON >"$outputFolder/$outputName.flv.json"
  189. fi
  190. echo -e "\033[0;32m"
  191. cat <<EOF
  192. _oo0oo_
  193. 088888880
  194. 88" . "88
  195. (| -_- |)
  196. 0\ = /0
  197. ___/'---'\___
  198. .' \\\\| |// '.
  199. / \\\\||| : |||// \\
  200. /_ ||||| -:- |||||- \\
  201. | | \\\\\\ - /// | |
  202. | \_| ''\---/'' |_/ |
  203. \ .-\__ '-' __/-. /
  204. ___'. .' /--.--\ '. .'___
  205. ."" '< '.___\_<|>_/___.' >' "".
  206. | | : '- \'.;'\ _ /';.'/ - ' : | |
  207. \ \ '_. \_ __\ /__ _/ .-' / /
  208. ====='-.____'.___ \_____/___.-'____.-'=====
  209. '=---='
  210. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  211. 佛祖保佑 TTT 顺利转换
  212. EOF
  213. echo -e "\033[m"
  214. echo "covert done!"
  215. else
  216. if [ ! -n "$1" ]; then
  217. print_usage
  218. else
  219. if [ -z $videoFile ]; then
  220. echo "${red}miss video file path: 缺视频文件路径"
  221. fi
  222. if [ -z $picFile ]; then
  223. echo "${red}miss audio file path : 缺少背影图像文件路径"
  224. fi
  225. if [ -z $outputName ]; then
  226. echo "${red}miss file name : 缺少输出文件名称"
  227. fi
  228. if [ -z $outputFolder ]; then
  229. echo "${red}miss output path : 缺少输出路径"
  230. fi
  231. fi
  232. fi