Ask Your Question
0

Processing Camera stream in Opencv, pushing it over RTMP (NGINX RTMP Module) using FFMPEG

asked 2016-04-11 05:48:57 -0600

asymptote gravatar image

updated 2016-04-11 09:02:48 -0600

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.

edit retag flag offensive close merge delete

Comments

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 gravatar imagehvzh ( 2016-12-21 08:10:59 -0600 )edit

@hvzh, please do not post answers here, if you have a comment or question, thank you.

berak gravatar imageberak ( 2016-12-21 08:47:49 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
0

answered 2016-06-06 06:08:00 -0600

asymptote gravatar image

It had to do with the fps of input stream (which was extremely low) and HLS settings on my streaming server. Once I reduced the packet length (in time) it worked fine.

edit flag offensive delete link more

Question Tools

2 followers

Stats

Asked: 2016-04-11 05:48:57 -0600

Seen: 7,093 times

Last updated: Dec 21 '16