Skip to content

Commit

Permalink
Merge pull request #27 from 360ls/sprint5/integration
Browse files Browse the repository at this point in the history
Sprint5/integration
  • Loading branch information
dongy7 authored Dec 11, 2016
2 parents 136eab0 + a2d3582 commit 8b22dac
Showing 1 changed file with 40 additions and 20 deletions.
60 changes: 40 additions & 20 deletions app/services/stitcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,13 @@ def parse_args():
parser.add_argument('--width', type=int, default=640)
parser.add_argument('--height', type=int, default=480)
parser.add_argument('--url', dest='url', default='rtmp://54.227.214.22:1935/live/myStream')
parser.add_argument('--debug', dest='debug', action='store_true')
parser.add_argument('--frames', type=int, default=100)
parser.add_argument('--playback', dest='playback', action='store_true')
parser.set_defaults(preview=False)
parser.set_defaults(stream=False)
return parser.parse_args()

def check_index(index):
"""
Checks if given index is valid
"""
sample_cap = cv2.VideoCapture(index)
frame = sample_cap.grab()
sample_cap.release()
return frame

def main():
"""
Parses command line arguments and starts the stitcher
Expand All @@ -48,19 +42,27 @@ def main():
index = args.i
height = args.height
width = args.width
count = 0

if args.playback:
cap = cv2.VideoCapture(args.f)
else:
cap = cv2.VideoCapture(index)

cap = cv2.VideoCapture(index)
codec = cv2.cv.CV_FOURCC('m', 'p', '4', 'v')
out = cv2.VideoWriter(dest, codec, 20.0, (width, height))
dimensions = str(width) + 'x' + str(height)

if args.f and not args.playback:
out = cv2.VideoWriter(dest, codec, 20.0, (width, height))

def handler(signum, frame): # pylint: disable=unused-argument
"""
Interrupt handler
"""
# When everything done, release the capture
cap.release()
out.release()
if args.f and not args.playback:
out.release()
cv2.destroyAllWindows()
sys.exit(0)

Expand All @@ -74,17 +76,35 @@ def handler(signum, frame): # pylint: disable=unused-argument
'libx264', '-pix_fmt', 'uyvy422', '-r', '28', '-an', '-f', 'flv',
args.url], stdin=subprocess.PIPE)

while True:
# Capture frame-by-frame
_, frame = cap.read()
if args.playback:
playback(cap, args.width, args.height)
else:
while True:
if args.debug and count > args.frames:
break

frame = cv2.resize(frame, (width, height))
count += 1

if not args.preview:
out.write(frame)
# Capture frame-by-frame
_, frame = cap.read()

if args.stream:
proc.stdin.write(frame.tostring())
frame = cv2.resize(frame, (width, height))

if args.f:
out.write(frame)

if args.stream:
proc.stdin.write(frame.tostring())

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

def playback(cap, width, height):
while (cap.isOpened()):
# Capture frame-by-frame
_, frame = cap.read()

# Display the resulting frame
cv2.imshow('frame', frame)
Expand Down

0 comments on commit 8b22dac

Please sign in to comment.