Last active
May 18, 2018 17:05
-
-
Save the-eric-kwok/979aab7d1cb77e4467e0c0acb0ef017a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 这个脚本可以用来把ASS格式的字幕和logo一起压制到视频里。依赖于ffmpeg和zenity | |
# 由于使用命令行输入路径的话参数太多,不方便记忆(我自己都记不住),所以使用zenity图形界面来操作,对新手更友好 | |
# logo建议使用png格式,使用透明背景,并且请裁剪成正方形,否则大概会变形 | |
# 设置logo大小指的是logo水印在视频中的大小,默认为200x200的正方形,如果需要压制长方形logo请自行修改源码 | |
#!/bin/bash | |
TOP_LEFT="10:10" | |
TOP_RIGHT="main_w-overlay_w-10:10" | |
BUTTOM_LEFT="10:main_h-overlay_h-10" | |
BUTTOM_RIGHT="main_w-overlay_w-10:main_h-overlay_h-10" | |
POS=$TOP_LEFT | |
SIZE=200 #默认大小为长宽200的正方形 | |
# 压制主程序,如需要压制长方形logo请自行修改 $SIZE:$SIZE 为 $WIDTH:$HEIGHT | |
burn(){ | |
ffmpeg \ | |
-i "$VIDEO" \ | |
-i "$LOGO" \ | |
-filter_complex \ | |
"[1:v]scale=$SIZE:$SIZE[logo];\ | |
[0:v][logo]overlay=$POS[taged];\ | |
[taged]ass=$ASS[sub]" \ | |
-vcodec libx264 -preset veryslow -profile:v high -level:v 4.1 -x264-params keyint=270:min-keyint=30 -b 4000k -maxrate 5000k -r 30 \ | |
-acodec aac -ac 2 -ab 192k -ar 44100 \ | |
-y \ | |
-map [sub] \ | |
-map 0:a \ | |
"$OUTPUT" | |
} | |
# 文件选择 | |
file_select(){ | |
VIDEO=`zenity --title="选择视频文件" --text="选择视频文件" --file-selection --filename="$HOME/Videos/"` || exit | |
ASS=`zenity --title="选择字幕文件" --text="选择字幕文件" --file-selection --filename="$VIDEO"` || exit | |
LOGO=`zenity --title="选择Logo文件" --text="选择Logo文件" --file-selection --filename="$HOME/Pictures/"` || exit | |
if [[ -z "$VIDEO" ]] || [[ -z "$ASS" ]] || [[ -z "$LOGO" ]]; then file_select; fi | |
} | |
# Logo 位置选择 | |
pos_select(){ | |
i=`zenity --height=250 --list --radiolist \ | |
--title="选择Logo位置" --text="选择Logo位置" \ | |
--column="Select" --column="pos" \ | |
TRUE "左上" \ | |
FALSE "右上" \ | |
FALSE "左下" \ | |
FALSE "右下"` || exit | |
case "$i" in | |
"左上") POS=${TOP_LEFT};; | |
"右上") POS=${TOP_RIGHT};; | |
"左下") POS=${BUTTOM_LEFT};; | |
"右下") POS=${BUTTOM_RIGHT};; | |
esac | |
} | |
# Logo 大小 | |
logo_size(){ | |
SIZE=`zenity --scale --title="请输入logo大小" --text="请选择Logo的边长" --value=200 --min-value=100 --max-value=500 --step=50` || exit | |
} | |
# 安装依赖 | |
install(){ | |
sudo apt-get install -y ffmpeg zenity | |
} | |
# 判断是否安装必要的依赖 | |
if [[ `dpkg -l | grep 'ffmpeg' | wc -l` -gt 0 ]] || [[ `ffmpeg -version | wc -l` -gt 0 ]] ; then | |
FFMPEG=0 | |
fi | |
if [[ `dpkg -l | grep 'zenity' | wc -l` -gt 0 ]] || [[ `zenity --version | wc -l` -gt 0 ]] ; then | |
ZENITY=0 | |
fi | |
if [[ ! "$FFMPEG" -eq 0 ]] || [[ ! "$ZENITY" -eq 0 ]] ; then | |
echo "ffmpeg or zenity not found, installing..." | |
#read | |
install | |
fi | |
file_select | |
pos_select | |
logo_size | |
OUTPUT=`echo $VIDEO | sed -E 's/(.mkv|.mp4|.tv|.avi|.rmvb|.mov|.qt|.wmv)/.final.mp4/ig'` #将视频文件常见的后缀名替换为.final.mp4输出 | |
if [ -e "$OUTPUT" ] ; then | |
zenity --question --text="${OUTPUT}\n已存在,是否覆盖?" | |
[ $? -eq 0 ] && burn || exit | |
else | |
burn | |
exit | |
fi | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment