Created
November 8, 2023 14:50
-
-
Save zew13/5aeae444210f2546b836884ef4de7f5a to your computer and use it in GitHub Desktop.
This file contains hidden or 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 | |
| DIR=$(realpath $0) && DIR=${DIR%/*} | |
| cd $DIR | |
| set -ex | |
| TMP=/tmp/mp4 | |
| mkdir -p $TMP | |
| # 定义一个函数,剪裁视频最后一帧 | |
| trim_last_frame() { | |
| file="$1" | |
| duration=$(ffmpeg -i "$file" 2>&1 | grep "Duration" | cut -d ' ' -f 4 | sed s/,// | awk -F: '{ print ($1 * 3600) + ($2 * 60) + $3 }') | |
| # 计算新的视频时长(减去最后1秒) | |
| new_duration=$(echo "$duration-1" | bc) | |
| # 使用ffmpeg命令裁剪视频 | |
| ffmpeg -i "$file" -t "$new_duration" -c copy "$TMP/$file" | |
| # 覆盖原文件 | |
| mv -f "$TMP/$file" "$file" | |
| } | |
| # 遍历目录下所有的MP4文件 | |
| for file in *.mp4; do | |
| echo $file | |
| trim_last_frame $file || mv $file ../x2/ | |
| done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment