Linux: How to join video files and generate time-lapse
Dash cameras or even GoPro camera split video to segments. This is handy for managing space but cause problems when dealing with video. This article describe easy way how to join such a videos and optionally generate time-lapse from it. (Tested with DDPai M6+ and GoPro).
Source material should not contain duplicate frames or gaps in video. Files are joined seamlessly only if source device properly split them. Duplicate frames can be fixed by video editor ...
Here is example using command line tool "ffmpeg video converter".
Step 1 - generate filelist
Put all files to one directory and generate filelist in format:
file video1.mp4 file video2.mp4 file video3.mp4 ...
If timestamp of files is correct then you may use following command:
ls -tr1 | grep -v -F list.txt | sed 's/^/file /' > list.txt
Examine list.txt
before continuing. Files should be listed in chronological order. If this is not case then fix content of file.
Step 2 - merge files
Following command will use list generated in previous step to join files:
- without audio track:
ffmpeg -f concat -i list.txt -c copy -an concat_output.mp4
- with audio track:
ffmpeg -f concat -i list.txt -c copy concat_output.mp4
Step 3 - generate time-lapse
Following command will "speed-up" video so it appear as to be captured by time-lapse camera. Modify target frame rate (-r
) or speed factor (setpts
) if necessary.
ffmpeg -i concat_output.mp4 -r 60 -filter:v "setpts=0.1*PTS" speedup_60fps_0-9.mp4
Note: this command will show dropped frames. It is expected in this mode.