Skip to content

Commit

Permalink
Add python RTSP->HLS example (#156)
Browse files Browse the repository at this point in the history
  • Loading branch information
sgfn authored Feb 22, 2024
1 parent 01c9597 commit 114d86c
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 1 deletion.
10 changes: 9 additions & 1 deletion examples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,13 @@ as well as the instructions necessary to run them.

## RTSP to HLS

### Elixir

1. Start a local instance of Jellyfish (e.g. by running `mix phx.server`)
2. Run `elixir examples/rtsp_to_hls.exs "rtsp://your-rtsp-stream-source:port/stream"`
2. Run `elixir ./rtsp_to_hls.exs "rtsp://your-rtsp-stream-source:port/stream"`

### Python

1. Install the Jellyfish Python Server SDK: `pip install jellyfish-server-sdk`
2. Start a local instance of Jellyfish (e.g. by running `mix phx.server`)
3. Run `python3 ./rtsp_to_hls.py "rtsp://your-rtsp-stream-source:port/stream"`
31 changes: 31 additions & 0 deletions examples/rtsp_to_hls.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import sys

# You can install the Jellyfish Python Server SDK by running `pip install jellyfish-server-sdk`
from jellyfish import RoomApi, ComponentOptionsHLS, ComponentOptionsRTSP


JELLYFISH_HOSTNAME="localhost"
JELLYFISH_PORT=5002
JELLYFISH_TOKEN="development"


if len(sys.argv) > 1:
stream_uri = sys.argv[1]
else:
raise RuntimeError("No stream URI specified, make sure you pass it as the argument to this script")

try:
room_api = RoomApi(server_address=f"{JELLYFISH_HOSTNAME}:{JELLYFISH_PORT}", server_api_token=JELLYFISH_TOKEN)

_jellyfish_address, room = room_api.create_room(video_codec="h264")
_component_hls = room_api.add_component(room.id, options=ComponentOptionsHLS())
_component_rtsp = room_api.add_component(room.id, options=ComponentOptionsRTSP(source_uri=stream_uri))

print("Components added successfully")

except Exception as e:
print(f"""
Error when attempting to communicate with Jellyfish: {e}
Make sure you have started it by running `mix phx.server`
""")
sys.exit(1)

0 comments on commit 114d86c

Please sign in to comment.