4dage-ffmpeg-img2video copy 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267
  1. #!/bin/bash
  2. version="0.0.5"
  3. picsFolder=''
  4. audioFile=''
  5. outputName=''
  6. outputFolder=''
  7. allowCacheStay=0
  8. allowOrigin=0
  9. frameRate='30'
  10. tempFolder=/tmp/4dage-ffmpeg
  11. time=$(date "+%Y%m%d-%H%M%S")
  12. tempFilePrefix="4dage-source-${time}"
  13. declare -a outputVideoList=('mp4 flv')
  14. red=$(tput setaf 1)
  15. green=$(tput setaf 2)
  16. reset=$(tput sgr0)
  17. command_exists() {
  18. if ! [[ -x $(command -v "$1") ]]; then
  19. return 1
  20. fi
  21. return 0
  22. }
  23. print_usage() {
  24. echo -e "\033[43;34m $package - 4dage-ffmpeg-img2video custom version for ffmpeg: \033[0m"
  25. echo "${green}If have problem with this, please contact with gemer AKA: 张宇鹏<zhangyupeng@cgaii.com>"
  26. echo "$package [options] application [arguments]"
  27. echo " "
  28. echo "${red}options:"
  29. echo "-h, --help show brief help"
  30. echo "-p, --source=pic file folder path input the picture source path"
  31. echo "-a, --audio=audio file path audio file path"
  32. echo "-n, --name=output file name output file name"
  33. echo "-o, --output=DIR specify a directory to store output in"
  34. echo "--allow-origin, allow maintain origin video output"
  35. echo "-rate, aka: 23/23.8/24/25/30/50/60 specify output video framerate"
  36. echo "-v, --version output verison"
  37. echo " "
  38. echo -e "\033[0;33m"
  39. cat <<EOF
  40. _oo0oo_
  41. 088888880
  42. 88" . "88
  43. (| -_- |)
  44. 0\ = /0
  45. ___/'---'\___
  46. .' \\\\| |// '.
  47. / \\\\||| : |||// \\
  48. /_ ||||| -:- |||||- \\
  49. | | \\\\\\ - /// | |
  50. | \_| ''\---/'' |_/ |
  51. \ .-\__ '-' __/-. /
  52. ___'. .' /--.--\ '. .'___
  53. ."" '< '.___\_<|>_/___.' >' "".
  54. | | : '- \'.;'\ _ /';.'/ - ' : | |
  55. \ \ '_. \_ __\ /__ _/ .-' / /
  56. ====='-.____'.___ \_____/___.-'____.-'=====
  57. '=---='
  58. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  59. 佛祖保佑 TTT 万无一失
  60. EOF
  61. echo -e "\033[m"
  62. }
  63. make_temp_dir() {
  64. # # Make a temp folder
  65. if [ ! -d $tempFolder ]; then
  66. mkdir -p $tempFolder && chmod 776 $tempFolder
  67. fi
  68. }
  69. make_temp_dir
  70. while test $# -gt 0; do
  71. case "$1" in
  72. -h | --help)
  73. print_usage
  74. exit 0
  75. ;;
  76. -p)
  77. shift
  78. if test $# -gt 0; then
  79. export picsFolder=$1
  80. else
  81. echo "{$red}no video path specified"
  82. exit 1
  83. fi
  84. shift
  85. ;;
  86. --pic*)
  87. export picsFolder=$(echo $1 | sed -e 's/^[^=]*=//g')
  88. echo $1
  89. shift
  90. ;;
  91. -a)
  92. shift
  93. if test $# -gt 0; then
  94. export audioFile=$1
  95. else
  96. echo "{$red}no rectangle format specified"
  97. exit 1
  98. fi
  99. shift
  100. ;;
  101. -rate)
  102. shift
  103. export frameRate=$1
  104. shift
  105. ;;
  106. --allow-origin)
  107. export allowOrigin=1
  108. shift
  109. ;;
  110. --audio*)
  111. export audioFile=$(echo $1 | sed -e 's/^[^=]*=//g')
  112. shift
  113. ;;
  114. -o)
  115. shift
  116. if test $# -gt 0; then
  117. export outputFolder=$1
  118. else
  119. echo "{$red}no output dir folder specified"
  120. exit 1
  121. fi
  122. shift
  123. ;;
  124. --output*)
  125. export outputFolder=$(echo $1 | sed -e 's/^[^=]*=//g')
  126. shift
  127. ;;
  128. -n)
  129. shift
  130. if test $# -gt 0; then
  131. export outputName=$1
  132. else
  133. echo "no output video name specified"
  134. exit 1
  135. fi
  136. shift
  137. ;;
  138. --name*)
  139. export outputName=$(echo $1 | sed -e 's/^[^=]*=//g')
  140. shift
  141. ;;
  142. --cache)
  143. shift
  144. echo "allow cahche remain"
  145. export allowCacheStay=1
  146. shift
  147. ;;
  148. -v)
  149. echo "$version"
  150. shift
  151. ;;
  152. *)
  153. print_usage
  154. # echo "111"
  155. break
  156. ;;
  157. esac
  158. done
  159. mkVerison() {
  160. touch "$outputFolder/4dage-ffmpeg-img2video-$version.version"
  161. }
  162. takeVideoCap() {
  163. 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"
  164. }
  165. covertVideoTask() {
  166. picsFolderType=${picsFolder##*.}
  167. allImages="$picsFolder/%06d.jpg"
  168. # -i $audioFile -filter_complex "[0:v]scale=1920:-1[vid];[vid]split=2[out1][out2]" \
  169. echo "frameRate: $frameRate"
  170. FFREPORT=file="$outputFolder/$outputName.txt":level=48 ffmpeg -vsync 0 -framerate $frameRate -hide_banner -y -i $allImages \
  171. -preset superfast -threads 2 -pix_fmt yuv420p -c:v libx264 "$outputFolder/$outputName.origin.mp4"
  172. FFREPORT=file="$outputFolder/$outputName.txt":level=48 ffmpeg -hide_banner -y -i "$outputFolder/$outputName.origin.mp4" \
  173. -i $audioFile -filter_complex "[0:v]scale=1920:-1[vid];[vid]split=2[out1][out2]" \
  174. -threads 2 -b 1.8M -minrate 1.8M -maxrate 1.8M -bufsize 2M \
  175. -map '[out1]' -map 1:a? -strict -2 -shortest -profile:v high -vcodec libx264 -c:a copy -ab 128k "$outputFolder/$outputName.mp4" \
  176. -map '[out2]' -map 1:a? -strict -2 -shortest -profile:v high -vcodec libx264 -c:a copy -ab 128k "$outputFolder/$outputName.flv"
  177. if test $allowOrigin -eq 0; then
  178. rm "$outputFolder/$outputName.origin.mp4"
  179. fi
  180. takeVideoCap
  181. mkVerison
  182. }
  183. clearDist() {
  184. rm -f $outputFolder/*.json
  185. rm -f $outputFolder/*.version
  186. }
  187. concatAllLogFile() {
  188. cat $outputFolder/*.txt >>"$outputFolder/$outputName.full.log"
  189. rm $outputFolder/*.txt
  190. }
  191. if [ ! -z $picsFolder ] && [ ! -z $audioFile ] && [ ! -z $outputName ] && [ ! -z $outputFolder ]; then
  192. if [ ! -d $outputFolder ]; then
  193. mkdir -p $outputFolder
  194. else
  195. clearDist
  196. fi
  197. echo "frameRate:$frameRate"
  198. covertVideoTask
  199. concatAllLogFile
  200. if command_exists "mediainfo"; then
  201. mediainfo --fullscan "$outputFolder/$outputName.mp4" --Output=JSON >"$outputFolder/$outputName.json"
  202. mediainfo --fullscan "$outputFolder/$outputName.flv" --Output=JSON >"$outputFolder/$outputName.flv.json"
  203. fi
  204. echo -e "\033[0;32m"
  205. cat <<EOF
  206. _oo0oo_
  207. 088888880
  208. 88" . "88
  209. (| -_- |)
  210. 0\ = /0
  211. ___/'---'\___
  212. .' \\\\| |// '.
  213. / \\\\||| : |||// \\
  214. /_ ||||| -:- |||||- \\
  215. | | \\\\\\ - /// | |
  216. | \_| ''\---/'' |_/ |
  217. \ .-\__ '-' __/-. /
  218. ___'. .' /--.--\ '. .'___
  219. ."" '< '.___\_<|>_/___.' >' "".
  220. | | : '- \'.;'\ _ /';.'/ - ' : | |
  221. \ \ '_. \_ __\ /__ _/ .-' / /
  222. ====='-.____'.___ \_____/___.-'____.-'=====
  223. '=---='
  224. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  225. 佛祖保佑 TTT 顺利转换
  226. EOF
  227. echo -e "\033[m"
  228. echo "covert done!"
  229. else
  230. if [ ! -n "$1" ]; then
  231. print_usage
  232. else
  233. if [ -z $picsFolder ]; then
  234. echo "${red}miss pics file folder path: 缺图像文件路径"
  235. fi
  236. if [ -z $audioFile ]; then
  237. echo "${red}miss rect spec : 缺少rect的技术参数"
  238. fi
  239. if [ -z $outputName ]; then
  240. echo "${red}miss file name : 缺少输出文件名称"
  241. fi
  242. if [ -z $outputFolder ]; then
  243. echo "${red}miss output path : 缺少输出路径"
  244. fi
  245. fi
  246. fi