123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260 |
- #!/bin/bash
- version="0.1.5"
- videoFile=''
- audioFile=''
- outputName=''
- outputFolder=''
- allowCacheStay=0
- tempFolder=/tmp/4dage-ffmpeg
- time=$(date "+%Y%m%d-%H%M%S")
- tempFilePrefix="4dage-source-${time}"
- declare -a outputVideoList=('mp4 flv')
- red=$(tput setaf 1)
- green=$(tput setaf 2)
- reset=$(tput sgr0)
- command_exists() {
- if ! [[ -x $(command -v "$1") ]]; then
- return 1
- fi
- return 0
- }
- print_usage() {
- echo -e "\033[43;34m $package - 4dage custom version for ffmpeg lite: \033[0m"
- echo "${green}If have problem with this, please contact with gemer AKA: 张宇鹏<zhangyupeng@cgaii.com>"
- echo "$package [options] application [arguments]"
- echo " "
- echo "${red}options:"
- echo "-h, --help show brief help"
- echo "-s, --source=source file path input the video source path"
- echo "-a, --audio=audio file path audio file path"
- echo "-n, --name=output file name output file name"
- echo "-o, --output=DIR specify a directory to store output in"
- echo "-v, --version output verison"
- echo "--cahche maintain the cahche file for tmp folder"
- echo " "
- echo -e "\033[0;33m"
- cat <<EOF
- _oo0oo_
- 088888880
- 88" . "88
- (| -_- |)
- 0\ = /0
- ___/'---'\___
- .' \\\\| |// '.
- / \\\\||| : |||// \\
- /_ ||||| -:- |||||- \\
- | | \\\\\\ - /// | |
- | \_| ''\---/'' |_/ |
- \ .-\__ '-' __/-. /
- ___'. .' /--.--\ '. .'___
- ."" '< '.___\_<|>_/___.' >' "".
- | | : '- \'.;'\ _ /';.'/ - ' : | |
- \ \ '_. \_ __\ /__ _/ .-' / /
- ====='-.____'.___ \_____/___.-'____.-'=====
- '=---='
-
-
- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
- 佛祖保佑 TTT 万无一失
- EOF
- echo -e "\033[m"
- }
- make_temp_dir() {
- # # Make a temp folder
- if [ ! -d $tempFolder ]; then
- mkdir -p $tempFolder && chmod 776 $tempFolder
- fi
- }
- make_temp_dir
- while test $# -gt 0; do
- case "$1" in
- -h | --help)
- print_usage
- exit 0
- ;;
- -s)
- shift
- if test $# -gt 0; then
- export videoFile=$1
- else
- echo "{$red}no video path specified"
- exit 1
- fi
- shift
- ;;
- --source*)
- export videoFile=$(echo $1 | sed -e 's/^[^=]*=//g')
- echo $1
- shift
- ;;
- -a)
- shift
- if test $# -gt 0; then
- export audioFile=$1
- else
- echo "{$red}no audioFile specified"
- exit 1
- fi
- shift
- ;;
- --audio*)
- export audioFile=$(echo $1 | sed -e 's/^[^=]*=//g')
- shift
- ;;
- -o)
- shift
- if test $# -gt 0; then
- export outputFolder=$1
- else
- echo "{$red}no output dir folder specified"
- exit 1
- fi
- shift
- ;;
- --output*)
- export outputFolder=$(echo $1 | sed -e 's/^[^=]*=//g')
- shift
- ;;
- -n)
- shift
- if test $# -gt 0; then
- export outputName=$1
- else
- echo "no output video name specified"
- exit 1
- fi
- shift
- ;;
- --name*)
- export outputName=$(echo $1 | sed -e 's/^[^=]*=//g')
- shift
- ;;
- --cache)
- shift
- echo "allow cahche remain"
- export allowCacheStay=1
- shift
- ;;
- -v)
- echo "$version"
- shift
- ;;
- *)
- print_usage
- # echo "111"
- break
- ;;
- esac
- done
- mkVerison() {
- echo "4dage-ffmpeg:$version" >>"$outputFolder/version"
- }
- takeVideoCap() {
- 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"
- }
- covertVideoTask() {
- videoFileType=${videoFile##*.}
- audioFileType=${audioFile##*.}
- tempbaseAudio="$tempFolder/$tempFilePrefix-base.$audioFileType"
- tempAudio="$tempFolder/$tempFilePrefix.$audioFileType"
- tempVideo="$tempFolder/$tempFilePrefix.$videoFileType"
- # FFREPORT=file="$outputFolder/audio.log":level=32 ffmpeg -i $tempAudio -filter_complex 'lv2=plugin=https\\://github.com/lucianodato/speech-denoiser' $tempAudio -y
- FFREPORT=file="$outputFolder/$outputName.audio.txt":level=32 ffmpeg -i $audioFile -af "lv2=p=https\\\\://github.com/lucianodato/speech-denoiser" -ac 1 $tempAudio -y
- RC=$?
- if [ "${RC}" -ne "0" ]; then
- FFREPORT=file="$outputFolder/$outputName.audio.txt":level=32 ffmpeg -i $audioFile -af "highpass=f=200, lowpass=f=3000" $tempAudio -y
- fi
- # -vf "scale=iw/2:ih/2"
- ffmpeg -i $videoFile -i $tempAudio -c:v copy -c:a aac -strict -2 $tempVideo -y
- 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
- 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
- takeVideoCap
- mkVerison
- # ffmpeg -i $tempVideo -s 1056x792 -c:v libx265 -movflags faststart -bf 2 -c:a copy "$outputFolder/$outputName.265.$videoFileType" -y
- # export lastOutPutVideo=$outputFolder/$outputName.$videoFileType
- # export lastOutPutVideoFlv="$outputFolder/$outputName.flv"
- if test $allowCacheStay -eq 0; then
- rm $tempAudio $tempVideo
- fi
- }
- concatAllLogFile() {
- cat $outputFolder/*.txt >>"$outputFolder/$outputName.full.log"
- rm $outputFolder/*.txt
- # rm "$outputFolder/$outputName.$videoFileType.log" "$outputFolder/$outputName.audio.log" "$outputFolder/$outputName.flv.log"
- }
- if [ ! -z $videoFile ] && [ ! -z $audioFile ] && [ ! -z $outputName ] && [ ! -z $outputFolder ]; then
- # ffmpeg -i $audioFile -af "highpass=f=200, lowpass=f=3000" temp.mp3 -y
- # ffmpeg -i $audioFile -filter_complex 'lv2=plugin=https\\://github.com/lucianodato/speech-denoiser' $tempAudio -y
- # ffmpeg -i $videoFile -i $tempAudio -c:v copy -c:a aac $tempVideo -y
- # 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
- # for i in "${outputVideoList[@]}"; do
- # done
- # 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
- # ffmpeg -i temp1.mp4 -pix_fmt rgb24 -color_range 2 $output -y
- # rm temp.mp4 temp1.mp4 temp.mp3
- if [ ! -d $outputFolder ]; then
- mkdir -p $outputFolder
- fi
- covertVideoTask
- concatAllLogFile
- if command_exists "mediainfo"; then
- mediainfo --fullscan "$outputFolder/$outputName.$videoFileType" --Output=JSON >"$outputFolder/$outputName.json"
- mediainfo --fullscan "$outputFolder/$outputName.flv" --Output=JSON >"$outputFolder/$outputName.flv.json"
- fi
- echo "\033[0;32m"
- cat <<EOF
- _oo0oo_
- 088888880
- 88" . "88
- (| -_- |)
- 0\ = /0
- ___/'---'\___
- .' \\\\| |// '.
- / \\\\||| : |||// \\
- /_ ||||| -:- |||||- \\
- | | \\\\\\ - /// | |
- | \_| ''\---/'' |_/ |
- \ .-\__ '-' __/-. /
- ___'. .' /--.--\ '. .'___
- ."" '< '.___\_<|>_/___.' >' "".
- | | : '- \'.;'\ _ /';.'/ - ' : | |
- \ \ '_. \_ __\ /__ _/ .-' / /
- ====='-.____'.___ \_____/___.-'____.-'=====
- '=---='
-
-
- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
- 佛祖保佑 TTT 顺利转换
- EOF
- echo "\033[m"
- echo "covert done!"
- else
- if [ ! -n "$1" ]; then
- print_usage
- else
- if [ -z $videoFile ]; then
- echo "${red}miss video file path: 缺视频文件路径"
- fi
- if [ -z $audioFile ]; then
- echo "${red}miss audio file path : 缺音频少文件路径"
- fi
- if [ -z $outputName ]; then
- echo "${red}miss file name : 缺音输出文件名称"
- fi
- if [ -z $outputFolder ]; then
- echo "${red}miss output path : 缺音输出路径"
- fi
- fi
- fi
|