Last active
October 8, 2023 11:56
-
-
Save wangjiezhe/576a3820b2519d8684aab39859340cb9 to your computer and use it in GitHub Desktop.
Convert video to 25M for wechat
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
#!/usr/bin/env bash | |
out_size=24 | |
length=$(mediainfo --Inform="Video;%Duration%" "$1") | |
bitrate_all=$(echo "${out_size}*8192/(${length}/1000)" | bc) | |
bitrate_audio_orig=$(mediainfo --Inform="Audio;%BitRate%" "$1") | |
if [ -z ${bitrate_audio_orig} ]; then | |
bitrate_audio_orig=$(mediainfo --Inform="Audio;%BitRate_Nominal%" "$1") | |
fi | |
if [ ${bitrate_audio_orig} -gt 150000 ]; then | |
convert_audio=true | |
bitrate_audio=128 | |
else | |
bitrate_audio=$(echo "${bitrate_audio_orig}/1000" | bc) | |
fi | |
if [ ${bitrate_all} -lt 250 ]; then | |
convert_audio=true | |
bitrate_audio=48 | |
fi | |
bitrate_video=$(echo "${bitrate_all}-${bitrate_audio}" | bc) | |
in_file="$1" | |
out_file=$(echo ${in_file} | sed -e 's/.mp4/_25M.mp4/') | |
ffmpeg -y -i ${in_file} -c:v libx265 -b:v ${bitrate_video}k -x265-params pass=1 -an -f mp4 /dev/null | |
if [ ${convert_audio} = true ]; then | |
ffmpeg -i "$1" -c:v libx265 -b:v ${bitrate_video}k -x265-params pass=2 -c:a aac -b:a ${bitrate_audio}k ${out_file} | |
else | |
ffmpeg -i "$1" -c:v libx265 -b:v ${bitrate_video}k -x265-params pass=2 -c:a copy ${out_file} | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment