import numpy as np
import cv2

cap = cv2.VideoCapture('transformers-4.mp4')
seen_black = False
start_black = []
end_black = []
frame_number = 0
while(True):
    # Capture frame-by-frame
    ret, frame = cap.read()

    # Our operations on the frame come here
    gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)

    number_of_zeros = np.count_nonzero(gray > 10)
    if number_of_zeros == 0 and not seen_black:
        gray[0:100,0:100] = 255
        seen_black = True
        start_black.append(frame_number)
    elif number_of_zeros > 0 and seen_black:
        end_black.append(frame_number)
        seen_black = False

    # Display the resulting frame
    cv2.imshow('frame',gray)
    if cv2.waitKey(1) & 0xFF == ord('q'):
        break
    frame_number += 1

print start_black
print end_black	
# When everything done, release the capture
cap.release()
cv2.destroyAllWindows()

@@ -137,16 +137,255 @@
 ber = 0%0A
+current_clip_number = 0%0A%0Adef get_video_writer(clip_number):%0A    fourcc = cv2.cv.CV_FOURCC(*'XVID')%0A    out = cv2.VideoWriter('clip%25d.avi' %25 clip_number,fourcc, 20.0, (640,480))%0A    return out%0Awriter = get_video_writer(current_clip_number)%0A
 while(Tr
@@ -736,24 +736,49 @@
 ame_number)%0A
+        writer.release()%0A
     elif num
@@ -876,17 +876,202 @@
 = False%0A
+        current_clip_number += 1%0A        writer = get_video_writer(current_clip_number)%0A    %0A    if number_of_zeros %3E 0:%0A        print 'wrote frame'%0A        writer.write(frame)%0A        
 %0A
-
     # Di
@@ -1283,16 +1283,16 @@
 capture%0A
-
 cap.rele
@@ -1297,16 +1297,33 @@
 lease()%0A
+writer.release()%0A
 cv2.dest

Write file