Ask Your Question

how to stream preprocessed video over network

asked 2013-03-02 09:42:00 -0500

Bertl gravatar image

Hello, i read a lot of threads on how to get live streams from ip cams but i´m looking for a possibility to transver a videostream from IplImages or a video e.g .x264 via multicast or rtp connection to another client.

Can anyone help?

edit retag flag offensive close merge delete



maybe it helps, if you explain a bit, on which side of the process you need opencv ?

there's always a server and a client side to the connection, and vlc is good at both, so you probably don't need to code both sides.

with a bit of luck, your opencv version already supports to read from streams already by dispatching that job to ffmpeg ( the "client" side ), you could try, if :

VideoCapture capture("");

gives you a (mjpg) stream to read from ( in c++ )

berak gravatar imageberak ( 2013-03-02 14:39:33 -0500 )edit

that propobly works. My intention is to read from a webcam, process it with opencv and then send it to the network as (hd) stream. i´m sure that vlc,.... can read that stream easily but i don´t know how to send the iplimages or the .avi TO the network.

Bertl gravatar imageBertl ( 2013-03-03 04:46:32 -0500 )edit

i had a look at virtual devices in linux, so i think that a videowriter in opencv can write the images to that device and finally the device can be used with vlc to read from and transver it as stream to the network. But how can i write into a virtual device so that vlc can read it from?

Bertl gravatar imageBertl ( 2013-03-03 04:50:07 -0500 )edit

my opencv is compiled with ffmpeg support

Bertl gravatar imageBertl ( 2013-03-03 04:50:40 -0500 )edit

to explain it in detail, i´m using an embedded board (Pandaboard with Linux 12.04 Server) where opencv is used to process images and i want to display the result on a desktop.

Bertl gravatar imageBertl ( 2013-03-03 04:52:27 -0500 )edit

ah, pandaboard. shame i don't own one. Linux 12.04 Server probably is a stripped ubuntu ? like , without desktop and such ?

if it comes with a webserver, you could try to build a cgi-interface for that. similar to what php or perl would be doing, only that your program would just write a html-header then imencode() the image in memory, and then print it to the console.

if you're a bit into networking, sockets, even writing your own webserver for that (same idea, imencode() and send out) might be an idea

berak gravatar imageberak ( 2013-03-03 05:02:49 -0500 )edit

if you only need to send it from the panda to your workstation, simple serial transfer over usb, might work, too. (probably too slow for hd, though)

berak gravatar imageberak ( 2013-03-03 05:07:42 -0500 )edit

networking is not really my business. i wanna keep it as simple as possible. Does anyone have examples how to do that. i already have an example how to send an iplimage by splitting and sending via a socket. But that is very processloading. I´d rather use vlc with compression like x.264.

Bertl gravatar imageBertl ( 2013-03-03 05:11:27 -0500 )edit

<strike>netcat, even ;)</strike>

ok, ignore. i got no real solution.

berak gravatar imageberak ( 2013-03-03 05:13:19 -0500 )edit

netcat is really simple Thanks!!!

Bertl gravatar imageBertl ( 2013-03-03 08:41:08 -0500 )edit

1 answer

Sort by » oldest newest most voted

answered 2020-09-13 09:48:45 -0500

AbhiTronix gravatar image

updated 2020-09-13 09:50:07 -0500

Hey, if you're dealing with python, then you can use my powerful vidgear library that supports FFmpeg backend with its WriteGear API for writing to network directly from OpenCV. The complete example for writing opencv frames to a RTP stream is as follows:

# import required libraries
from vidgear.gears import WriteGear
import cv2

# Open your source
stream = cv2.VideoCapture(0) 

# define required FFmpeg parameters for your writer
output_params = {"-vcodec":"libx264","-profile:v":"main","-preset:v":"veryfast","-g":60,"-keyint_min":60,"-sc_threshold":0,"-b:v":"2500k","-maxrate":"2500k","-bufsize":"2500k", "-f":"flv"}

# Define writer with defined parameters and address such as `rtp://`
writer = WriteGear(output_filename = 'rtp://', logging =True, **output_params)

# loop over
while True:

    # read frames from stream
    (grabbed, frame) =

    # check for frame if Nonetype
    if not grabbed:

    # {do something with the frame here}

    # write frame to writer

    # Show output window
    cv2.imshow("Output Frame", frame)

    # check for 'q' key if pressed
    key = cv2.waitKey(1) & 0xFF
    if key == ord("q"):

# close output window

# safely close video stream

# safely close writer


edit flag offensive delete link more
Login/Signup to Answer

Question Tools


Asked: 2013-03-02 09:42:00 -0500

Seen: 4,265 times

Last updated: Sep 13