Mac工作流之视频压缩(mov => mp4)
shell脚本如下:
需要安装ffmpeg
命令行工具
PATH=$PATH:/usr/local/bin/
read -r -d '' applescriptCode1 <<EOF
tell application "System Events"
set activeApp to name of first application process whose frontmost is true
activate
set file_wid_display to "$file_wid" as string
set widList to {"原始尺寸", "3/4", "2/3", "1/2", "1/3","other"}
choose from list widList with title "选择输出尺寸" default items "原始尺寸"
if result contains "原始尺寸" then
set widChoose to "$file_wid" as number
else if result contains "other" then
set widChoose to text returned of (display dialog "请输入自定义尺寸" default answer "0")
else
set widChoose to result
end if
end tell
return widChoose
EOF
widChoose=$(osascript -e "$applescriptCode1")
idx=0
for f in "$@";do
# 选择预设分辨率或自定义分辨率
file_wid=$(ffmpeg -i "$f" 2>&1 | grep -E -o '\d{3,}x\d{3,}' | grep -E -o '^\d{3,}')
#echo $file_wid
#echo $widChoose
if [[ "$widChoose" = "$file_wid" ]];then
let widOutput=$widChoose
elif [[ "$widChoose" =~ "/" ]];then
let widOutput=$file_wid*$widChoose
else
let widOutput=$widChoose
fi
#echo $widOutput
full_name=${f%.*}
extension=${f##*.}
newFile=${full_name}_new.mp4
temp1=$(echo $extension | tr [a-z] [A-Z])
if [[ "$temp1"x = "MP4"x ]] || [[ "$temp1"x = "MOV"x ]]; then
ffmpeg -i "$f" -vf scale="$widOutput:-2" -b:v 600k -f mp4 "$newFile"
let idx=$idx+1
fi
done && afplay "/System/Library/Sounds/Submarine.aiff" && osascript -e "display notification \"$(echo 修改了 $idx 个文件)\""
或者
Mov 转 mp4
举例: Mac QuickTime录制了一个视频为mov格式,文件很大,把它通过以下命令转换成mp4感觉尚可 -crf 22
这个值可以调大点会清晰一些 但是文件大小也会相应变大
11.4MB => 697KB
ffmpeg -i hotfix-demo.mov -vcodec libx264 -s 960x540 -preset fast -crf 22 -y -acodec copy new.mp4
未经作者授权,禁止转载
本文来自博客园,作者:CoderWGB,转载请注明原文链接:https://www.cnblogs.com/wgb1234/p/17372614.html
THE END