Explanation:
I want to: Process camera stream in Opencv and push it over to RTMP server. I already have NGINX (RTMP module) set up and I have tested streaming videos with both RTMP (Flash Player) and HLS.
I am reading the frames in a loop and using 'subprocess' in python to execute ffmpeg command. Here's the command I am using:
command = [ffmpeg,
'-y',
'-f', 'rawvideo',
'-vcodec','rawvideo',
'-pix_fmt', 'bgr24',
'-s', dimension,
'-i', '-',
'-c:v', 'libx264',
'-pix_fmt', 'yuv420p',
'-preset', 'ultrafast',
'-f', 'flv',
'rtmp://10.10.10.80/live/mystream']
import subprocess as sp
...
proc = sp.Popen(command, stdin=sp.PIPE,shell=False)
...
proc.stdin.write(frame.tostring()) #frame is read using opencv
Problem:
I can see the stream fine but it freezes and resumes frequently. Here's the output of FFMPEG terminal log:
Stream mapping:
Stream #0:0 -> #0:0 (rawvideo (native) -> h264 (libx264))
frame= 117 fps= 16 q=22.0 size= 344kB time=00:00:04.04 bitrate= 697.8kbits/s speed=0.543x
It mentions speed at the end. I believe it should be close to 1x. I am not sure how to achieve that.
And I am on the same network as server, I can post my python code if required. Need some ffmpeg guru to give me some advise.