Last active
May 18, 2024 12:24
-
-
Save sj14/4220961846faf750f8c4b4245b392302 to your computer and use it in GitHub Desktop.
merge video files from folders recursively with ffmpeg
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 | |
#set -o xtrace # output every line which gets executed | |
set -o nounset # fail if an unset variable is used | |
set -o errexit # fail if a command exits with non-zero | |
set -o pipefail # fail if a command in a pipe fails | |
recurse() { | |
for i in "$1"/*;do | |
if [ -d "$i" ];then | |
# echo "dir: $i" | |
rm -f "$i"/merge.txt | |
find "$i" -maxdepth 1 -type f -name "*-cd*.avi" ! -name ".*" -execdir echo file \'{}\' >> "$i"/merge.txt \; | |
if [ -s "$i"/merge.txt ]; then | |
echo "$i" | |
ffmpeg -y -f concat -safe 0 -fflags +genpts -i "$i"/merge.txt -c copy "$i"/"$(basename "$i").mkv" | |
else | |
rm "$i/merge.txt" | |
fi | |
recurse "$i" | |
# elif [ -f "$i" ]; then | |
# echo "file: $i" | |
fi | |
done | |
} | |
recurse "$1" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment