4dage-ffmpeg 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  1. #!/bin/sh
  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. # -vf "scale=iw/2:ih/2"
  145. ffmpeg -i $videoFile -i $tempAudio -c:v copy -c:a aac -strict -2 $tempVideo -y
  146. 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
  147. 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
  148. # ffmpeg -i $tempVideo -s 1056x792 -c:v libx265 -movflags faststart -bf 2 -c:a copy "$outputFolder/$outputName.265.$videoFileType" -y
  149. # export lastOutPutVideo=$outputFolder/$outputName.$videoFileType
  150. # export lastOutPutVideoFlv="$outputFolder/$outputName.flv"
  151. rm $tempAudio $tempVideo
  152. }
  153. concatAllLogFile() {
  154. cat $outputFolder/*.txt >>"$outputFolder/$outputName.full.log"
  155. rm $outputFolder/*.txt
  156. # rm "$outputFolder/$outputName.$videoFileType.log" "$outputFolder/$outputName.audio.log" "$outputFolder/$outputName.flv.log"
  157. }
  158. if [ ! -z $videoFile ] && [ ! -z $audioFile ] && [ ! -z $outputName ] && [ ! -z $outputFolder ]; then
  159. # ffmpeg -i $audioFile -af "highpass=f=200, lowpass=f=3000" temp.mp3 -y
  160. # ffmpeg -i $audioFile -filter_complex 'lv2=plugin=https\\://github.com/lucianodato/speech-denoiser' $tempAudio -y
  161. # ffmpeg -i $videoFile -i $tempAudio -c:v copy -c:a aac $tempVideo -y
  162. # 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
  163. # for i in "${outputVideoList[@]}"; do
  164. # done
  165. # 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
  166. # ffmpeg -i temp1.mp4 -pix_fmt rgb24 -color_range 2 $output -y
  167. # rm temp.mp4 temp1.mp4 temp.mp3
  168. if [ ! -d $outputFolder ]; then
  169. mkdir -p $outputFolder
  170. fi
  171. covertVideoTask
  172. concatAllLogFile
  173. if command_exists "mediainfo"; then
  174. mediainfo --fullscan "$outputFolder/$outputName.$videoFileType" --Output=JSON >"$outputFolder/$outputName.json"
  175. mediainfo --fullscan "$outputFolder/$outputName.flv" --Output=JSON >"$outputFolder/$outputName.flv.json"
  176. fi
  177. echo -ne "\033[0;32m"
  178. cat <<EOF
  179. _oo0oo_
  180. 088888880
  181. 88" . "88
  182. (| -_- |)
  183. 0\ = /0
  184. ___/'---'\___
  185. .' \\\\| |// '.
  186. / \\\\||| : |||// \\
  187. /_ ||||| -:- |||||- \\
  188. | | \\\\\\ - /// | |
  189. | \_| ''\---/'' |_/ |
  190. \ .-\__ '-' __/-. /
  191. ___'. .' /--.--\ '. .'___
  192. ."" '< '.___\_<|>_/___.' >' "".
  193. | | : '- \'.;'\ _ /';.'/ - ' : | |
  194. \ \ '_. \_ __\ /__ _/ .-' / /
  195. ====='-.____'.___ \_____/___.-'____.-'=====
  196. '=---='
  197. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  198. 佛祖保佑 TTT 顺利转换
  199. EOF
  200. echo -ne "\033[m"
  201. echo "covert done!"
  202. else
  203. if [ ! -n "$1" ]; then
  204. print_usage
  205. else
  206. if [ -z $videoFile ]; then
  207. echo "${red}miss video file path: 缺视频文件路径"
  208. fi
  209. if [ -z $audioFile ]; then
  210. echo "${red}miss audio file path : 缺音频少文件路径"
  211. fi
  212. if [ -z $outputName ]; then
  213. echo "${red}miss file name : 缺音输出文件名称"
  214. fi
  215. if [ -z $outputFolder ]; then
  216. echo "${red}miss output path : 缺音输出路径"
  217. fi
  218. fi
  219. fi