.dotfiles/zsh/ffmpeg

97 lines
3.4 KiB
Plaintext
Raw Normal View History

2022-02-10 20:11:56 +01:00
#--------------------------------
# filename: /zsh/ffmpeg
#--------------------------------
# ffmpeg-recontainer
# source: https://yohanes.gultom.me/2016/05/21/bash-script-to-batch-convert-mkv-to-mp4-linux/
function ff-mp4() {
2023-02-11 01:30:25 +01:00
findpath=$1
: "${findpath:="."}"
find "$findpath" \( -iname '*.mkv' -o -iname '*.flv' -o -iname '*.mov' -o -iname '*.mp4*' \) | while read -r f ; do
dir=$(dirname "$f");
file=$(basename "$f");
name="${file%.*}";
ext="${file##*.}";
2023-02-28 09:38:36 +01:00
ffmpeg -hide_banner -loglevel error -i "$f" -map 0 -c copy -pix_fmt yuv420p -movflags faststart "$dir/temp_$name.mp4";
2023-02-11 01:30:25 +01:00
mv "$f" "$dir/_$file";
mv "$dir/temp_$name.mp4" "$dir/$file";
done
2022-02-10 20:11:56 +01:00
}
# ffmpeg-convert
# source: https://yohanes.gultom.me/2016/05/21/bash-script-to-batch-convert-mkv-to-mp4-linux/
function ff-ac3-to-stereo() {
findpath=$1
2022-11-13 19:19:00 +01:00
: "${findpath:="."}"
find "$findpath" \( -iname '*.mkv' -o -iname '*.flv' -o -iname '*.mov' -o -iname '*.mp4' \) | while read -r f ; do
2023-02-11 01:30:25 +01:00
dir=$(dirname "$f");
file=$(basename "$f");
name="${file%.*}";
ext="${file##*.}";
ffmpeg -hide_banner -loglevel error -i "$f" -map 0 -c:v copy -c:a libfdk_aac -b:a 192k -ac 2 -af volume=2 -movflags faststart "$dir/temp_$name.mp4";
mv "$f" "$dir/_$file";
mv "$dir/temp_$name.mp4" "$dir/$file";
2022-02-10 20:11:56 +01:00
done
}
# ffmpeg audio-to-ac3
function ff-input-to-ac3() {
2023-02-11 01:30:25 +01:00
ffmpeg -i "$1" -movflags faststart -map 0 -c:v copy -c:s copy -c:a ac3 -b:a 448k "temp_$1"
mv "$1" "_$1" && mv "temp_$1" "$1"
2022-02-10 20:11:56 +01:00
}
# ffmpeg fix 16:9 AR
function ff-ar16-9() {
2023-02-28 09:38:36 +01:00
ffmpeg -i "$1" -c copy -map 0 -bsf:v "h264_metadata=sample_aspect_ratio=4/3" -aspect 16:9 -pix_fmt yuv420p -movflags faststart "temp_$1"
2023-02-11 01:30:25 +01:00
mv "$1" "_$1" && mv "temp_$1" "$1"
2022-02-10 20:11:56 +01:00
}
2023-02-10 19:25:48 +01:00
# ffmpeg fix 5:4 AR
function ff-ar5-4() {
2023-02-28 09:38:36 +01:00
ffmpeg -i "$1" -c copy -map 0 -bsf:v "h264_metadata=sample_aspect_ratio=1/1" -aspect 5:4 -pix_fmt yuv420p -movflags faststart "temp_$1"
2023-02-11 01:30:25 +01:00
mv "$1" "_$1" && mv "temp_$1" "$1"
2023-02-10 19:25:48 +01:00
}
# ffmpeg fix 4:3 AR
function ff-ar4-3() {
2023-02-28 09:38:36 +01:00
ffmpeg -i "$1" -c copy -map 0 -bsf:v "h264_metadata=sample_aspect_ratio=1/1" -aspect 4:3 -pix_fmt yuv420p -movflags faststart "temp_$1"
2023-02-11 01:30:25 +01:00
mv "$1" "_$1" && mv "temp_$1" "$1"
2023-02-10 19:25:48 +01:00
}
2023-02-28 09:38:36 +01:00
# ffmpeg fix AR ($1 = file, $2 1/1, $4:3)
2023-02-12 19:54:49 +01:00
function ff-ar-custom() {
if [ $# -lt 3 ]; then
>&2 echo "Not enough arguments (\$1 = 'file', \$2 '1/1', \$3 '4:3')"
return 0
else
2023-02-28 09:38:36 +01:00
ffmpeg -i "$1" -c copy -map 0 -bsf:v "h264_metadata=sample_aspect_ratio=$2" -aspect $3 -pix_fmt yuv420p -movflags faststart "_$1"
2023-02-12 19:54:49 +01:00
fi
}
2022-02-10 20:11:56 +01:00
# ffmpeg fix Non-monotonous DTS
function ff-dts() {
2023-02-28 09:38:36 +01:00
ffmpeg -fflags +igndts -i "$1" -c copy -pix_fmt yuv420p -movflags faststart "temp_$1"
2023-02-11 01:30:25 +01:00
mv "$1" "_$1" && mv "temp_$1" "$1"
2022-02-10 20:11:56 +01:00
}
## ffmpeg wma-to-m4a
function ff-wma-m4a() {
findpath=$1
2022-11-13 19:19:00 +01:00
: "${findpath:="."}"
find "$findpath" -name '*.wma' | while read -r f ; do
2023-02-11 01:30:25 +01:00
dir=$(dirname "$f");
file=$(basename "$f");
name="${file%.*}";
ext="${file##*.}";
ffmpeg -hide_banner -loglevel error -i "$f" -map 0 -vn -b:a 192k -c:a libfdk_aac "$dir/temp_$name.mp4";
mv "$f" "$dir/_$file";
mv "$dir/temp_$name.mp4" "$dir/$file";
2022-02-10 20:11:56 +01:00
done
}