4dage-ffmpeg 8.4 KB

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