FFmpeg batch merge videos within a folder

For those who use bash (Linux/Mac), here is the script to generate the list of all files in a folder and then merge it all into one video file:

#!/bin/bash
for filename in pieces/*.mp4; do
  echo "file $filename" >> concat-list.txt
done

ffmpeg -f concat -i concat-list.txt merged.mp4

echo "Concatenated videos list:"
cat concat-list.txt
rm concat-list.txt

It takes all mp4 files from pieces/ folder and concatenates the videos into merged.mp4 file.

Files list is generated in alphabetical order, so if you want the videos to be in a particular order, name them like 01-murder-scene.mp4, 02-office-scene.mp4 etc.