gopro-py-api icon indicating copy to clipboard operation
gopro-py-api copied to clipboard

GoPro Hero 8 USB live streaming url with opencv

Open BrainGym opened this issue 2 years ago • 11 comments

Hi, I wanted to broadcast from GoPro Hero 8 firmware 2.50 using USB and display live with opencv (windows 10)

I used ifaddr interface to get the IP address (work fine)

for adapter in ifaddr.get_adapters():
    if "GoPro" in adapter.nice_name:
        for ip in adapter.ips:
            if ip.is_IPv4:
                addr = ip.ip.split(".")
                addr[len(addr) - 1] = "51"
                addr = ".".join(addr)

then I used the IP address to wake up the gopro (goprocam 4.1.0) gopro = GoProCamera.GoPro(ip_address=addr, camera=constants.gpcontrol)

image

I want to get the live streaming by using livestream("start") function, but I lost here, I get an error when I pass the address in opencv

cam= cv2.VideoCapture(addr)
_, frame = cam.read()
cv2.imshow('Image', frame)

error: (-215:Assertion failed) size.width>0 && size.height>0 in function 'cv::imshow'

I even tried with vlc with this url: http://IP_address/gp/gpControl/execute?p1=gpStream&c1=start but nothing shows up

BrainGym avatar Oct 02 '21 12:10 BrainGym

You have to use a properly constructed UDP URI.

udp://%s:8554 % addr

KonradIT avatar Oct 02 '21 13:10 KonradIT

u mean by using gopro.stream("udp adress") function?

BrainGym avatar Oct 02 '21 14:10 BrainGym

Nope. For stream function you have to provide your own addy.

KonradIT avatar Oct 02 '21 16:10 KonradIT

Finally I figure it out After waking up the camera, I must call the startWebcam() function, then use an udp address, it work fine with opencv

gopro = GoProCamera.GoPro(ip_address=addr, camera=constants.gpcontrol)
gopro.startWebcam()
udp_addr = "udp://@{}:8554".format(addr)

BrainGym avatar Oct 04 '21 02:10 BrainGym

Sorry @KonradIT another question, After calling the stopWebcam() function, the camera mantain on the ready mode is there in a function to put in normal mode or something ?

BrainGym avatar Oct 04 '21 08:10 BrainGym

What do you mean normal mode? You could try putting it in video/photo mode.

KonradIT avatar Oct 04 '21 08:10 KonradIT

For you question I mean the mode that display usb connected on the camera screen putting it in video mode, l will try that

BrainGym avatar Oct 04 '21 09:10 BrainGym

hi again @KonradIT I wanted to connect two cameras GoPro using usb and stream each one independently unfortunately, I didn't get wat I expect, just look in the link below : https://streamable.com/pp2ian I get one stream for the both cameras

BrainGym avatar Oct 22 '21 16:10 BrainGym

Yep, that happens when a system receives 2 UDP streams on the same port (albeit different IP addresses)

KonradIT avatar Oct 22 '21 17:10 KonradIT

Can I use another port than 8554 ? or it's impossible

BrainGym avatar Oct 23 '21 10:10 BrainGym

You could use an intermediary device, eg: raspberry pi to ingest via port 8554, and then output via a different port.

KonradIT avatar Oct 23 '21 11:10 KonradIT

I need to connect two camera to raspberry Pi. When using alone it's working fine how can connect both. How can the swtich the on stream to redirect.

How can I switch the port? For one camera

I am using this method. this good working when I use one Gopro Camera. https://github.com/KonradIT/goprowifihack/blob/master/HERO9/GoPro-Connect.md

sakthivelj avatar Nov 20 '22 02:11 sakthivelj