Skip to content

Instantly share code, notes, and snippets.

@KonradIT
Created August 6, 2016 14:38
Show Gist options
  • Save KonradIT/acc2ab5c89567037e3d0077982de2da5 to your computer and use it in GitHub Desktop.
Save KonradIT/acc2ab5c89567037e3d0077982de2da5 to your computer and use it in GitHub Desktop.
GoPro HERO4 Session FW2.00 streaming script
## GoPro Streaming script from Sonof8Bits for HERO4 Session running 2.00 Firmware
import sys
import socket
import urllib.request
import subprocess
from time import sleep
def get_command_msg(id):
return "_GPHD_:%u:%u:%d:%1lf\n" % (0, 0, 2, 0)
UDP_IP = "10.5.5.9"
UDP_PORT = 8554
KEEP_ALIVE_PERIOD = 2500
KEEP_ALIVE_CMD = 2
MESSAGE = get_command_msg(KEEP_ALIVE_CMD)
##
## HTTP GETs the URL that tells the GoPro to start streaming.
##
urllib.request.urlopen("http://10.5.5.9/gp/gpControl/execute?p1=gpStream&a1=proto_v2&c1=restart").read()
for i in range(5):
urllib.request.urlopen("http://10.5.5.9/gp/gpControl/status").read()
print("UDP target IP:", UDP_IP)
print("UDP target port:", UDP_PORT)
print("message:", MESSAGE)
print("Press ctrl+C to quit this application.\n")
##
## Opens the stream over udp in ffplay. This is a known working configuration by Reddit user hoppjerka:
## https://www.reddit.com/r/gopro/comments/2md8hm/how_to_livestream_from_a_gopro_hero4/cr1b193
##
subprocess.Popen("ffplay -fflags nobuffer -f:v mpegts -probesize 8192 udp://:8554", shell=True)
if sys.version_info.major >= 3:
MESSAGE = bytes(MESSAGE, "utf-8")
while True:
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
sock.sendto(MESSAGE, (UDP_IP, UDP_PORT))
sleep(KEEP_ALIVE_PERIOD/1000)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment