Skip to content

Instantly share code, notes, and snippets.

@Casxt
Last active November 19, 2018 11:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Casxt/1e5b51ff2396209fde244730d131005d to your computer and use it in GitHub Desktop.
Save Casxt/1e5b51ff2396209fde244730d131005d to your computer and use it in GitHub Desktop.
rstp to rmtp in python use ffmpeg
pipe = subprocess.Popen([FFMPEG_BIN,
'-y', # (optional) overwrite output file if it exists
'-f', 'rawvideo',
#'-loglevel','error',
#'-probesize','10M',
'-s', framesize, #'420x360', # size of one frame
'-pix_fmt', 'bgr24',
'-r', str(self.fps), # frames per second
'-i', '-', # The input comes from a pipe
'-an', # Tells FFMPEG not to expect any audio
#'-q','15',
'-f', 'flv',
'rtmp://localhost:1935/live/%s' % name]
, stdin=subprocess.PIPE)
video_capture = cv2.VideoCapture('rtmp://127.0.0.1:1935/live/%s' % self.name)
while video_capture.isOpened():
ret, frame = self.video_capture.read()
# print(ret)
if ret:
pipe.stdin.write(f.frame)
self.index += 1
else:
pass
pipe = subprocess.Popen([FFMPEG_BIN,
'-y', # (optional) overwrite output file if it exists
# '-f', 'rawvideo',
'-loglevel', 'error',
# '-probesize','10M',
# '-s', self.framesize, #'420x360', # size of one frame
# '-pix_fmt', 'bgr24',
# '-r', str(self.fps), # frames per second
'-rtsp_transport', 'tcp',
'-i', self.url, # The input comes from a pipe
'-codec:v', 'copy',
'-an', # Tells FFMPEG not to expect any audio
'-q', '15',
'-f', 'flv',
'rtmp://0.0.0.0:1935/live/%s' % name]
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment