Streaming video frame by frame using Python and SRT

Viewed 51

Almost every implementation of exposing a video stream in Python i managed to find is based on opencv and then writing frame (numpy.ndarrays) converted to bytes to FFMPEG stream, which goes to RTMP exposed on nginx server which works pretty fine, however now i have to expose SRT. Would anyone be so kind to tell me if it's possible using FFMPEG (i already have ffmpeg recompiled with libsrt), and if it is how should i do? What command should I use? Basically whole pipeline at the moment looks like: RTMP (stream source) -> Python processing frame by frame -> process.stdin.write(frames.tobytes()) -> RTMP (stream out). Where the process is FFMPEG process opened with subprocess lib, the direct command is:

command = [
    'ffmpeg',
    '-y',
    '-f', 'rawvideo',
    '-vcodec', 'rawvideo',
    '-pix_fmt', 'bgr24',
    '-s', "{}x{}".format(1920, 1080),
    '-r', str(30),
    '-i', '-',
    '-c:v', 'libx264',
    '-pix_fmt', 'yuv420p',
    '-preset', 'ultrafast',
    '-f', 'flv',
    url
]
process = subprocess.Popen(command, stdin=subprocess.PIPE)

I'd also like to ask if any other server will be necessary, because i had to get rtmp module for nginx to make this pipeline work as it should, so I'm pretty sure that there's work to do too. Ofcourse I could grab the output RTMP, put it to OBS and configure it to spit out the SRT, but I'd like to expose SRT stream directly from Python code, as correct output. I'll be really gratefull for any help. Thanks in advance :).

0 Answers
Related