4dage-ffmpeg 8.3 KB

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