Ask Your Question
0

OpenCV + WebCam + H.264 Streaming

asked 2020-06-21 17:06:32 -0600

Hi, I have the following problem. I want to grab frames from webcam (I know how to do that in OpenCV I am familiar with this library), then take the frame, and encode it via H.264 and sent it to another computer. The other computer needs to decode each frame with OpenCV and process it.

My main problems are:

  • I do not know if it is possible to encode to H.264 frame by frame (I think that this is only possible with a buffer).
  • I do not know the better way to send my video frame by frame to another computer by the network.
  • I want to keep the framerate higher as it would be possible.

I searched in lots of forums but every new post made me more confused...

I am working on Linux with OpenCV 3 on Raspberry Pi (but my question is in general for Linux, no only specific for rpi).

Thanks in advance, and new ideas and proposals are welcome :)

edit retag flag offensive close merge delete

Comments

if you have gstreamer support builtin, you could use opencv's VideoWriter with a custom (server) pipeline

also look up the MJPG protocol, you can send single (JPG or PNG encoded) frames via tcp

berak gravatar imageberak ( 2020-06-22 05:42:56 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
0

answered 2020-06-22 02:39:41 -0600

palladin gravatar image

updated 2020-06-22 02:40:14 -0600

I do not know if it is possible to encode to H.264 frame by frame (I think that this is only possible with a buffer).

Yes, it is possible. Use VideoWriter, but it saves video only to a file. Therefore, I recommend using the ffmpeg library (libav).

I do not know the better way to send my video frame by frame to another computer by the network.

Better way or better library? Better way - via TCP.

I want to keep the framerate higher as it would be possible.

It all depends on the encoding parameters and hardware.

edit flag offensive delete link more

Comments

Thank you, I know that is possible to do with videowrite, but as you said this procedure saves a video file. However, I want to send the frame retrieved by the webcam as soon as possible to the other computer avoiding using a video file. I think that it is possbiel because some IP cameras do this process but I do not know how.

About the sent to the other computer, is it desirable to use TCP instead of UDP?

i02rolof gravatar imagei02rolof ( 2020-06-22 05:11:48 -0600 )edit

ffmpeg is able to do encode in memory. Functions avcodec_send_frame()/avcodec_receive_packet() only work with memory, after which the given AVPacket can be sent to the network.

UDP will not increase the speed of sending and will not reduce the delay, but you will have to take into account packet losses.

palladin gravatar imagepalladin ( 2020-06-23 04:09:10 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2020-06-21 17:02:08 -0600

Seen: 1,895 times

Last updated: Jun 22 '20