Commit e7c53242 authored by Gihan Jayatilaka's avatar Gihan Jayatilaka

a

parent 77af0150
......@@ -8,8 +8,8 @@ VIDEO_WIDTH=1920
NO_FRAMES=0
if __name__ == "__main__":
print("python synchronize-time-1.py video-rec.mp4 0 screen-time.ts 0 cam-time.ts 0 output.mp4")
print("python synchronize-time-1.py sys.argv[1] [2] [3] [4] [5] [6] [7] ")
print("python synchronize-time-1.py video-rec.mp4 0 screen-time.ts 0 cam-time.ts 0 output.mp4 debug.mp4 1000000")
print("python synchronize-time-1.py sys.argv[1] [2] [3] [4] [5] [6] [7] [8] [9]")
INPUT_VIDEO_FILE=sys.argv[1]
......@@ -19,7 +19,8 @@ if __name__ == "__main__":
CAMERA_TIME_FILE=sys.argv[5]
CAMERA_OFFSET=int(sys.argv[6])
OUTPUT_VIDEO_FILE=sys.argv[7]
DEBUG_VIDEO_FILE=sys.argv[8]
SCREEN_TIME_OFFSET=int(sys.argv[9])
......@@ -34,6 +35,8 @@ if __name__ == "__main__":
fourcc=cv2.VideoWriter_fourcc(*'XVID')
vidOut=cv2.VideoWriter(OUTPUT_VIDEO_FILE,fourcc,60,(VIDEO_WIDTH,VIDEO_HEIGHT))
# debugVidOut=cv2.VideoWriter(DEBUG_VIDEO_FILE,fourcc,60,(VIDEO_WIDTH,VIDEO_HEIGHT))
print("Input video {} of size {}x{} and {} frames".format(INPUT_VIDEO_FILE,VIDEO_HEIGHT,VIDEO_WIDTH,NO_FRAMES_VIDEO))
......@@ -80,20 +83,29 @@ if __name__ == "__main__":
vidIn.read()
print("Screen time ",screenTime[:100])
print("Camera time ",cameraTime[:100])
print("\nScreen time ",screenTime[:100])
print("\nCamera time ",cameraTime[:100])
for i in range(len(screenTime)-1,-1,-1):
screenTime[i]=screenTime[i]-screenTime[0]
screenTime[i]=screenTime[i]-screenTime[0]+SCREEN_TIME_OFFSET
for i in range(len(cameraTime)-1,-1,-1):
cameraTime[i]=cameraTime[i]-cameraTime[0]
# cameraTime=cameraTime[2:]
print("\nScreen time ",screenTime[:100])
print("\nCamera time ",cameraTime[:100])
print("Screen time ",screenTime[:100])
print("Camera time ",cameraTime[:100])
cameraTimeStep=[0]
screenTimeStep=[0]
for i in range(len(cameraTime)-1):
cameraTimeStep.append(cameraTime[i+1]-cameraTime[i])
for i in range(len(screenTime)-1):
screenTimeStep.append(screenTime[i+1]-screenTime[i])
# input("Hi!")
input("Start aligning? [Press ENTER]")
skipCamFrame=[True for _ in range(len(cameraTime))]
......@@ -103,7 +115,7 @@ if __name__ == "__main__":
ret,fr=vidIn.read()
for scrIdx in range(len(screenTime)):
print("Staring iteration with camIdx {} for scrIdx {}".format(camIdx,scrIdx))
# print("Staring iteration with camIdx {} for scrIdx {}".format(camIdx,scrIdx))
if camIdx+1 == len(cameraTime):
print("END")
break
......@@ -119,11 +131,19 @@ if __name__ == "__main__":
# cv2.imshow("AA",fr)
# cv2.waitKey(100)
vidOut.write(fr)
print("Saved camIdx {} for scrIdx {}".format(camIdx,scrIdx))
# cv2.rectangle(img=fr,pt1=(10,10),pt2=(500,500),color=[255,0,0],thickness=10)
# print("Saved camIdx {} for scrIdx {}".format(camIdx,scrIdx))
# print("camIdx={} camTime={} scrIdx={} scrTime={} camStep={} scrStep={} camTimeScrTimeDiff={} avgScrTime={} avgCamTime={}".format(camIdx,cameraTime[camIdx],scrIdx,screenTime[scrIdx],cameraTimeStep[camIdx],screenTimeStep[scrIdx],cameraTime[camIdx]-screenTime[scrIdx],screenTime[scrIdx]/max(1,scrIdx),cameraTime[camIdx]/max(1,camIdx)))
# camIdx+=1
# ret,fr=vidIn.read()
break
# debugVidOut.write(fr)
camIdx+=1
ret,fr=vidIn.read()
# print("camIdx={} camTime={} camStep={} IF-THIS-MATCH-diff={}".format(camIdx,cameraTime[camIdx],cameraTimeStep[camIdx],cameraTime[camIdx]-screenTime[scrIdx]))
if not ret:
print("ERROR")
break
......@@ -134,12 +154,15 @@ if __name__ == "__main__":
if scrIdx%100==99:
print("screen,cam ",scrIdx,camIdx)
print("{} of {} completed".format(scrIdx+1,len(screenTime)))
# if scrIdx==100:
# break
# debugVidOut.release()
vidOut.release()
print("Finished writing to video {}".format(OUTPUT_VIDEO_FILE))
print("Finished writing to video {}".format(DEBUG_VIDEO_FILE))
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment