Skip to content

Instantly share code, notes, and snippets.

@rish-0-0
Last active March 30, 2025 20:56
Show Gist options
  • Save rish-0-0/322e4b1d1367b45614e3151c5a822f36 to your computer and use it in GitHub Desktop.
Save rish-0-0/322e4b1d1367b45614e3151c5a822f36 to your computer and use it in GitHub Desktop.
For streaming your android phone's primary camera and reading the stream in OpenCV
# conda create -n env python=3.6
# pip install opencv-python # this is important because you need ffmpeg enabled
import cv2
import numpy as np
import time
import os
# For UDP Speed instead of default TCP
os.environ["OPENCV_FFMPEG_CAPTURE_OPTIONS"] = "rtsp_transport;udp"
my_android_phone = "rtsp://192.168.0.100:8080/h264_pcm.sdp"
vcap = cv2.VideoCapture(my_android_phone)
def run(cap):
while True:
ret, frame = cap.read()
if not ret:
print("Frame is empty")
time.sleep(0.5)
continue
cv2.imshow('VIDEO', frame)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
if __name__ == "__main__":
run(vcap)
vcap.release()
cv2.destroyAllWindows()
@rish-0-0
Copy link
Author

Forgot to mention. Please install the Android app from the play store: IP Webcam.
You can find it here Link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment