Tinku Tinku - 13 days ago 4x
Python Question

How to check if videos overlap

I am new to video analysis and python and is working on a project on video composition. I have three videos that overlap.
for example below are the start and end time of the videos

video1 video2 video3
start 19-13-30 19-13-25 19-13-45
end 19-13-55 19-13-35 19-13-59

In the above scenario video1 & video2 overlap for 5 sec(19-13-30 to 19-13-35) and video1 and video3 overlap for 10 sec(19-13-45 to 19-13-55).

So,is there a way to identify the overlaps in the videos given the timestamps and returning the timestamps for which they overlap or by just analyzing the video


Suppose you have a list of starttime and endtime of the videos [[video1_starttime,video1_endtime],[video2_starttime,video2_endtime],[video3_starttime,video3_endtime]], you can first sort the list based on startimes and then iterate over it to check if it is overlapping.

You can use the below code to check for it:

overlapping = [ [x,y] for x in intervals for y in intervals if x is not y and x[1]>y[0] and x[0]<y[0] ]
for x in overlapping:
    print '{0} overlaps with {1}'.format(x[0],x[1])

where intervals is the list of [starttime,endtime]

To compare the timestamps, convert them to datetime objects using:

from datetime import datetime
dateTimeObject = datetime.strptime(timestampString)