Processing Camera stream in Opencv, pushing it over RTMP (NGINX RTMP Module) using FFMPEG
Output video: https://youtu.be/VxfoBQjoY6E
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.
Hello!
Tell me please does frame cv::Mat object or something else. I try to port your code to C++, but it doesn't work...
@hvzh, please do not post answers here, if you have a comment or question, thank you.