Categories
Audio and Video Blogging

Merging multi-file action cam videos (fast)

Gosh, it’s December already? This year is at the same time too long but with time flying too fast.

A one-off post unrelated to previous ones, to change the subject!

If you have an action camera and you shoot videos that go over 4 GB, then you know that the cam will split your footage in 4 GB chunks – and if you want to make a single video out of these, then you need to somehow merge the pieces into one.

My DJI Osmo Action camera is producing videos like that:

DJI_0062_001.MP4
DJI_0062_002.MP4
DJI_0062_003.MP4
...

Even if you have no need to edit the video at all, you probably end up working in some kind of video editor spending MANY hours exporting (or rendering, whatever is the word used in your software). Even with a decent GPUs capable of fast encoding this can take long time, growing exponentially with resolution. You can forget about rendering long 4K mp4 videos on a machine without a very capable GPU costing around €1000!

Guess what, I don’t have that, my main laptop doesn’t have any dedicated GPU at all – a 1 hour 4K video takes more than 24 hours to render! 😁

Ideally I need something that can “concatenate” videos without decoding and re-encoding, and the solutions exist. I’m on Windows and I’ve found these tools called MP4 Splitter and MP4 Joiner, but they were very unreliable with my files, crashing a lot and producing corrupted videos. Maybe Osmo Action is creating buggy files – I don’t know.

Even the most complex video and audio processing tasks can be done using this amazing tool call ffmpeg, it’s a real command line powerhouse able to do any kind of conversions on most audio and video formats. The command line interface is totally allright with me for my own usage, I don’t need a GUI for myself. So I did a bit of research and finally found what works well for my use case and this is the “quick and dirty” batch script I ended up with:

@echo ------------ STARTED ENCODING ---------------

set file-name=new_video

:: Create input File List
for %%i in (DJI*.mp4) do echo file '%%i'>> mylist.temp.txt

:: Concatenate input video files
ffmpeg -f concat -safe 0 -i mylist.temp.txt -c copy -hide_banner -loglevel warning -stats %file-name%.mp4

:: cleanup
rm mylist.temp.txt

@echo ------------ FINISHED ENCODING ---------------

As a prerequisite, you need:

  1. Install ffmpeg.exe and put it somewhere in user or system path. I already had one installed by “MP4Tools” https://www.mp4joiner.org/ so I used it but there are other prebuilt packages available.
  2. Put your video files to concatenate in a directory – they will be joined by the alphabetical order of their filenames
  3. Put the concat.bat in the same directory and just run it. When it finishes, you’ll have a new file “new_video.mp4” in the same directory, having roughly the total size of the original videos.

DJI_0062_001.MP4
DJI_0062_002.MP4
DJI_0062_003.MP4
new_video.mp4

...

On my i5 Lenovo T470 Notebook without GPU it takes about 30 minutes to process a 1-hour long 4K video which is so significantly faster than reencoding it in the video editor!

Keep hacking (•̀ᴗ•́)و ̑̑