4dage-ffmpeg.sh 8.2 KB

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