/ Terminal

Concatentating or Combining Multiple Videos into a single file

I wanted to stream an eCourse to Plex to watch while spinning! Unfortunately, the eCourse was split up (as usually the case) into multiple video files.

This is kinda painful to work with Plex. The most efficient way that I was thought was to combine all the video files into a single file and then stream that to Plex!

Here is the code that I was able to use to achieve that! Seems to work fine!

# Fix names with spaces
# Fix unsafe file name issue
# Fix Whilelist protocol issue
# https://blog.yo1.dog/fix-for-ffmpeg-protocol-not-on-whitelist-error-for-urls/

ls *.mp4 | sed -e "s/ /\\\ /g" | perl -ne 'print "file $_"' | ffmpeg -f concat -safe 0 -protocol_whitelist "file,pipe,http,https,tcp,tls" -i - -c copy Movie_Joined.mp4

Next, I had a masterclass with multiple mp4 files in subfolders. Concatenating them involved recursively finding the files and concatenating them after that using:

find . -type f -name '*.mp4' | sed -e "s/ /\\\ /g" | perl -ne 'print "file $_"' | ffmpeg -f concat -safe 0 -protocol_whitelist "file,pipe,http,https,tcp,tls" -i - -c copy Movie_Joined.mp4

Masterclass - Margaret Atwood Teaches Creative Writing

Next, I had a large udacity course and combining the whole thing was too bulky! I decided to split the course up into each module. This worked simply with a small tweak as follows and also added a fix for sorting so that order was maintained!!:

find . -type f -name '*.mp4' | sort | grep 01-Module | sed -e "s/ /\\\ /g" | perl -ne 'print "file $_"' | ffmpeg -f concat -safe 0 -protocol_whitelist "file,pipe,http,https,tcp,tls" -i - -c copy 01-Module-Movie_Joined.mp4

Credit: https://stackoverflow.com/questions/7333232/how-to-concatenate-two-mp4-files-using-ffmpeg