Skip to content

Instantly share code, notes, and snippets.

@jonahlyn
Last active September 27, 2020 15:57
Show Gist options
  • Save jonahlyn/ef817bc3a6b6eaa907cfcce316d3eff3 to your computer and use it in GitHub Desktop.
Save jonahlyn/ef817bc3a6b6eaa907cfcce316d3eff3 to your computer and use it in GitHub Desktop.
RTSP

Reading from an RTSP stream in Python

import numpy as np
import subprocess as sp

FFMPEG_BIN = '/usr/bin/ffmpeg'
RTSP_STREAM = "https://590804fbbbc47.streamlock.net:444/ruidosowebcorp2/ruidosowebcorp2.stream/playlist.m3u8"

COMMAND = [ FFMPEG_BIN,
            '-loglevel', 'panic',
            '-i', RTSP_STREAM,
            '-f', 'image2pipe',
            '-pix_fmt', 'rgb24',
            '-vcodec', 'rawvideo', '-']

VWIDTH = 800
VHEIGHT = 450

# Grab an image from the RTSP stream
pipe = sp.Popen(COMMAND, stdin = sp.PIPE, stdout = sp.PIPE)
raw_image = pipe.stdout.read(VWIDTH*VHEIGHT*3) # = 1 frame
image =  np.frombuffer(raw_image, dtype='uint8').reshape((VHEIGHT,VWIDTH,3))

Source: http://zulko.github.io/blog/2013/09/27/read-and-write-video-frames-in-python-using-ffmpeg/

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