简体   繁体   中英

Streaming video from android to desktop

I'm doing some sound and image processing and for faster prototyping I'm using python and opencv. So far I've been recording some videos on phone (can't use webcam - need to check specific camera I have in phone), uploading to desktop and then working offline on file.

Though It becomes a little bit tedious and I was wondering if there is any way to do realtime streaming video and processing those video frames in python? I notice there is app like: DroidCam but there is not app for MacOS and seems it works only via WiFI. I've also checked android scripting but there is only a way to record to a file.

Because low latency is important in my case streaming via USB would be a plus. I noticed that adb allows port forwarding so looks like there is a way to do without specific android /python USB api and only using sockets.

Does there exist already any tool for that or the easiest way would be to write something by yourself using sockets and adb forwarding?

Something similar for iOS would be great as well.

Try setting up a UDP server, here is the code to send images,

UDPSock = socket(AF_INET,SOCK_DGRAM)

  while 1:
    image = camProxy.getImageLocal(nameId)
    size = (image[0], image[1])
    data = image[6]
    im = Image.fromstring("YCbCr", size, data)
    s = StringIO.StringIO()
    im.save(s, "JPEG")

    UDPSock.sendto(s.getvalue(), addr)

    camProxy.releaseImage(nameId)

  UDPSock.close()

Code to recieve stream:

  UDPSock = socket(AF_INET,SOCK_DGRAM)
  UDPSock.bind(addr)

  while 1:
    data, addr = UDPSock.recvfrom(buf)
    # here add code to process image and receive image

  UDPSock.close()

Check out:

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM