Skip to content

Instantly share code, notes, and snippets.

@brookinc
Last active April 18, 2022 17:23
Show Gist options
  • Save brookinc/9dd0e951153ae9e66315170bdf87f5b4 to your computer and use it in GitHub Desktop.
Save brookinc/9dd0e951153ae9e66315170bdf87f5b4 to your computer and use it in GitHub Desktop.
Script to concatenate a directory of mp4 files into one
#!/bin/zsh
# requires ffmpeg: https://ffmpeg.org/download.html
# clear the file list
echo "" > ./output.txt
# recursively find all mp4 files in the current directory and subdirectories
# (will preserve alphabetical order by full path)
for entry in ./**/*.mp4
do
# ...and write them to a source file in the format ffmpeg expects
echo "file '$entry'" >> ./output.txt
done
# this simpler approach yielded a "Could not find tag for codec pcm_alaw" error locally...
#ffmpeg -f concat -safe 0 -i output.txt -c copy output.mp4
# ...so I'm forcing the audio output to AAC:
ffmpeg -f concat -safe 0 -i output.txt -c:v copy -c:a aac output.mp4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment