-
-
Save bczhc/a9b9235217bb69a97588d379c66f86de to your computer and use it in GitHub Desktop.
利用h264_nvenc编码器再编码视频,有时可起到压缩的作用
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
#!/bin/bash | |
# 此脚本暂没一般适用化,只做个记录 | |
set -e | |
base_dir="$(dirname "$0")" | |
cd "$base_dir" || exit | |
list_file="$base_dir/list" | |
temp_file="$(mktemp --suffix=.mp4)" | |
function get_video_bitrate() { | |
ffprobe -v error -select_streams v -show_entries stream=bit_rate \ | |
-of default=noprint_wrappers=1:nokey=1 \ | |
"$1" | |
} | |
# if file "./ok" exists, delete it | |
if [ -f "./ok" ]; then | |
rm ok | |
fi | |
# same to "./err" | |
if [ -f "./err" ]; then | |
rm err | |
fi | |
# same to "./ignored" | |
if [ -f "./ignored" ]; then | |
rm ignored | |
fi | |
while read -r file; do | |
if ffmpeg -y -nostdin -i "$file" -c:a copy -c:v h264_nvenc -b:v 0 "$temp_file"; then | |
output_bitrate="$(get_video_bitrate "$temp_file")" | |
input_bitrate="$(get_video_bitrate "$file")" | |
if [[ output_bitrate -lt input_bitrate ]]; then | |
mv -f "$temp_file" "$file" | |
echo "$file" >>ok | |
else | |
echo "$file" >>ignored | |
fi | |
else | |
echo "$file" >>err | |
fi | |
done <"$list_file" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
可以改编码器,比如改成hevc_nvenc,h265更省空间!