4dage-ffmpeg-v1 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260
  1. #!/bin/bash
  2. version="0.1.6"
  3. videoFile=''
  4. audioFile=''
  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 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 "-a, --audio=audio file path audio 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. -a)
  89. shift
  90. if test $# -gt 0; then
  91. export audioFile=$1
  92. else
  93. echo "{$red}no audioFile specified"
  94. exit 1
  95. fi
  96. shift
  97. ;;
  98. --audio*)
  99. export audioFile=$(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/$version.version"
  149. }
  150. takeVideoCap() {
  151. FFREPORT=file="$outputFolder/$outputName.cap.txt":level=32 ffmpeg -hide_banner -loglevel error -y -i $tempVideo -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. audioFileType=${audioFile##*.}
  156. tempbaseAudio="$tempFolder/$tempFilePrefix-base.$audioFileType"
  157. tempAudio="$tempFolder/$tempFilePrefix.$audioFileType"
  158. tempVideo="$tempFolder/$tempFilePrefix.$videoFileType"
  159. # FFREPORT=file="$outputFolder/audio.log":level=32 ffmpeg -i $tempAudio -filter_complex 'lv2=plugin=https\\://github.com/lucianodato/speech-denoiser' $tempAudio -y
  160. FFREPORT=file="$outputFolder/$outputName.audio.txt":level=32 ffmpeg -i $audioFile -af "lv2=p=https\\\\://github.com/lucianodato/speech-denoiser" -ac 1 $tempAudio -y
  161. RC=$?
  162. if [ "${RC}" -ne "0" ]; then
  163. FFREPORT=file="$outputFolder/$outputName.audio.txt":level=32 ffmpeg -i $audioFile -af "highpass=f=200, lowpass=f=3000" $tempAudio -y
  164. fi
  165. # -vf "scale=iw/2:ih/2"
  166. ffmpeg -i $videoFile -i $tempAudio -c:v copy -c:a aac -strict -2 $tempVideo -y
  167. 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
  168. 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
  169. takeVideoCap
  170. mkVerison
  171. # ffmpeg -i $tempVideo -s 1056x792 -c:v libx265 -movflags faststart -bf 2 -c:a copy "$outputFolder/$outputName.265.$videoFileType" -y
  172. # export lastOutPutVideo=$outputFolder/$outputName.$videoFileType
  173. # export lastOutPutVideoFlv="$outputFolder/$outputName.flv"
  174. if test $allowCacheStay -eq 0; then
  175. rm $tempAudio $tempVideo
  176. fi
  177. }
  178. concatAllLogFile() {
  179. cat $outputFolder/*.txt >>"$outputFolder/$outputName.full.log"
  180. rm $outputFolder/*.txt
  181. # rm "$outputFolder/$outputName.$videoFileType.log" "$outputFolder/$outputName.audio.log" "$outputFolder/$outputName.flv.log"
  182. }
  183. if [ ! -z $videoFile ] && [ ! -z $audioFile ] && [ ! -z $outputName ] && [ ! -z $outputFolder ]; then
  184. # ffmpeg -i $audioFile -af "highpass=f=200, lowpass=f=3000" temp.mp3 -y
  185. # ffmpeg -i $audioFile -filter_complex 'lv2=plugin=https\\://github.com/lucianodato/speech-denoiser' $tempAudio -y
  186. # ffmpeg -i $videoFile -i $tempAudio -c:v copy -c:a aac $tempVideo -y
  187. # ffmpeg -i $tempVideo -s 1056x792 -c:v libx264 -profile:v high -level:v 4.0 -movflags faststart -bf 2 -c:a copy $outputFolder/$outputName.$i -y
  188. # for i in "${outputVideoList[@]}"; do
  189. # done
  190. # ffmpeg -i temp.mp4 -s 1056x792 -c:v libx264 -profile:v high -level:v 4.0 -movflags faststart -bf 2 -c:a copy temp1.mp4 -y
  191. # ffmpeg -i temp1.mp4 -pix_fmt rgb24 -color_range 2 $output -y
  192. # rm temp.mp4 temp1.mp4 temp.mp3
  193. if [ ! -d $outputFolder ]; then
  194. mkdir -p $outputFolder
  195. fi
  196. covertVideoTask
  197. concatAllLogFile
  198. if command_exists "mediainfo"; then
  199. mediainfo --fullscan "$outputFolder/$outputName.$videoFileType" --Output=JSON >"$outputFolder/$outputName.json"
  200. mediainfo --fullscan "$outputFolder/$outputName.flv" --Output=JSON >"$outputFolder/$outputName.flv.json"
  201. fi
  202. echo "\033[0;32m"
  203. cat <<EOF
  204. _oo0oo_
  205. 088888880
  206. 88" . "88
  207. (| -_- |)
  208. 0\ = /0
  209. ___/'---'\___
  210. .' \\\\| |// '.
  211. / \\\\||| : |||// \\
  212. /_ ||||| -:- |||||- \\
  213. | | \\\\\\ - /// | |
  214. | \_| ''\---/'' |_/ |
  215. \ .-\__ '-' __/-. /
  216. ___'. .' /--.--\ '. .'___
  217. ."" '< '.___\_<|>_/___.' >' "".
  218. | | : '- \'.;'\ _ /';.'/ - ' : | |
  219. \ \ '_. \_ __\ /__ _/ .-' / /
  220. ====='-.____'.___ \_____/___.-'____.-'=====
  221. '=---='
  222. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  223. 佛祖保佑 TTT 顺利转换
  224. EOF
  225. echo "\033[m"
  226. echo "covert done!"
  227. else
  228. if [ ! -n "$1" ]; then
  229. print_usage
  230. else
  231. if [ -z $videoFile ]; then
  232. echo "${red}miss video file path: 缺视频文件路径"
  233. fi
  234. if [ -z $audioFile ]; then
  235. echo "${red}miss audio file path : 缺音频少文件路径"
  236. fi
  237. if [ -z $outputName ]; then
  238. echo "${red}miss file name : 缺音输出文件名称"
  239. fi
  240. if [ -z $outputFolder ]; then
  241. echo "${red}miss output path : 缺音输出路径"
  242. fi
  243. fi
  244. fi