Combine/Concatenate...
 
Notifications
Clear all

Combine/Concatenate video clips that overlaps recording.  

  RSS
dpathan
(@dpathan)
Junior Member

I have multiple small video clips that needs to be stitched together. The problem is that each clips overlaps each other (has recording of couple seconds from previous clip at the beginning of next clip). The clips are from an old dvr which recorded motion and normal video in seperate clips. the motion overlaps with normal recording clips.
I am looking for a tool or script that can automatically combine the clips by pulling timestamp from the frames and place it in a timeline. Two tracks should be enough.

for e.g
clip 1 starts 120001 am ends 120605 am
clip 2 starts 120545 am ends 120900 am.

need a tool to export one clip from 120001 to 120900.

Other thing we can use is to join and trim using timestamps in filename. The file names have start and end timecode on it. If there is a script using ffmpeg, we can create a sequence of 1 hour and start placing video by a time with reference of that 1 hour sequence.

I have already analyzed recording on HDD and latest dvr firmware. The embedded player in firmware does merge and play these seperate together but it doesn't have functionality to export as such.

Any other ideas are welcome.

Quote
Posted : 20/09/2018 12:21 am
MDCR
 MDCR
(@mdcr)
Active Member

Any modern video editing software should be able to truncate the start and end of each clip.

ReplyQuote
Posted : 20/09/2018 3:34 pm
dpathan
(@dpathan)
Junior Member

I was looking for something that would automate the truncate based on csv/txt input. There is over 1000 clips for 6 hr video.

ReplyQuote
Posted : 20/09/2018 7:31 pm
jaclaz
(@jaclaz)
Community Legend

Is the overlapping constant?
Is each clip the same duration?
Do they have already an order?

I mean, can you trim each video by stripping n seconds at the end (or from the beginning of the n+1) and then stitch the result together?

Something loosely along the lines of
https://superuser.com/questions/1229945/ffmpeg-split-video-and-merge-back
https://superuser.com/questions/138331/using-ffmpeg-to-cut-up-video
https://superuser.com/questions/1061877/ffmpeg-trim-and-merge-video-clips-without-reencoding

Also
https://markheath.net/post/cut-and-concatenate-with-ffmpeg

This would probably do as a base (Bash/Linux)
https://www.jeffgeerling.com/blog/2016/converting-batch-dashcam-videos-timelapse
(of course you need not to speed up the video)

On windows, depending on the camera/format of the video, this seems like would do as well
http//registratorviewer.net/RegistratorViewer/features_en.html
though you should get it from here
https://dashcamtalk.com/forum/threads/google-maps-fix-for-registratorviewer-windows.27756/
The developer has passed away and there are issues with expired web hosting/domains, the above version should work fine with the Registry modification.

jaclaz

ReplyQuote
Posted : 21/09/2018 10:17 am
dpathan
(@dpathan)
Junior Member

@jaclaz Thankyou for the reply. Unfortunately the video length and the overlapping is not constant. There is no pattern to it as well. Only help is the timestamp in file names. I exported the timestamp to csv and was able to calculate the overlapping duration of each clip in excel.

This way, I am hoping if any experienced ffmpeg programmer can write a script that can read the truncate duration from the file while concatenating. I know how to input the list of filenames to concatenate and set a constant duration to cut the clip. Trying to see if somehow that constant duration can be changed to variable based on the csv input.

However, I will try the Registrator viewer and check its funcationality. Thankyou for the suggestion.

Peace.

ReplyQuote
Posted : 22/09/2018 7:30 pm
jaclaz
(@jaclaz)
Community Legend

@jaclaz Thankyou for the reply. Unfortunately the video length and the overlapping is not constant. There is no pattern to it as well. Only help is the timestamp in file names. I exported the timestamp to csv and was able to calculate the overlapping duration of each clip in excel.

This way, I am hoping if any experienced ffmpeg programmer can write a script that can read the truncate duration from the file while concatenating. I know how to input the list of filenames to concatenate and set a constant duration to cut the clip. Trying to see if somehow that constant duration can be changed to variable based on the csv input.

However, I will try the Registrator viewer and check its funcationality. Thankyou for the suggestion.

Peace.

Well, if you have the data in Excel is not that difficult to build in Excel a ffmpeg command, one per line, to cut the overlapping from each file, and execute them sequentially instead of a FOR loop.

Post just a few filenames (let's say five or six) as they are.

jaclaz

ReplyQuote
Posted : 22/09/2018 8:14 pm
MDCR
 MDCR
(@mdcr)
Active Member

If you have a 10 second clip, this cuts of 1 second from the start and the end


ffmpeg -i test.avi -ss 000001 -to 000009 test_cut.avi

ReplyQuote
Posted : 22/09/2018 9:29 pm
dpathan
(@dpathan)
Junior Member

Here is the example of the file names.

180804-210351-210427
180804-210426-210529
180804-210516-210551
180804-210551-210630
180804-210616-210652
180804-210651-210754
180804-210742-210817

For excel I did text to columns, applied date and time format (had to seperate hh,mm,ss in columns and combine using time function) and calculated the overlap difference.

ReplyQuote
Posted : 28/09/2018 9:24 pm
dpathan
(@dpathan)
Junior Member

Here is the link of excel file with built ffmpeg command for each video. @jaclaz I am able to input this as a batch. I am sure there is more efficient way if someone wants to take this further.

Please note, there is still 0.05% error in trimming and concatenate due to how the original videos were stored and also there is no millisecond data to use for stripping.

link https://drive.google.com/file/d/1ED43-TpunBFtII1RDc7sRjmC6bWygiPG/view?usp=sharing

ReplyQuote
Posted : 28/09/2018 10:09 pm
dpathan
(@dpathan)
Junior Member

here is another idea (though it may be stupid). export every frame in those videos, calculate hash values, delete duplicate hashes. bring all the frames together.

It is a great idea, I had tried it earlier. It would take a lot of time. I have 24 hours of video from 5 different channels. I may have to do that if it is required later in the case. Or else i'll leave it at this. But it is definitely fun project if we have a pc to spare for computing.

However when I extracted the frames, there is an issue with number of frames per second. The media info states it is 12 fps but when I exported it they were not consistent. Some time only 3 frames per second and sometime it was more than 12. So it will be hard to stitch them back together.

The DVR program was stupid, not the idea. I said was because the "manufacturer" released an updated firmware to fix this issue in new models but didn't thought of a workaround fro previous model.

ReplyQuote
Posted : 28/09/2018 10:42 pm
jaclaz
(@jaclaz)
Community Legend

As I see it, the Excel is "good enough", you just copy the column "I" to a batch file and execute it, making a more elaborate batch would only "move" the calculation to it and put the ffmpeg commands into a FOR loop, it would be much more "elegant" but it won't shave anything from computing time, i.e. nothing more "efficient" as the number of ffmpeg commands will be anyway the same.

Elaborating on calimelo's idea ) , you could maybe "intentionally" leave only 1 second of overlap and then extract the frames for this 1 second only (twice, 1 second from the "tail" of the "before" file and 1 second from the "head" of the "after" file).
This way the amount of frames to extract and hash will be minimal.

jaclaz

ReplyQuote
Posted : 30/09/2018 2:38 pm
Share: