V
V
Vladimir Merk2017-01-03 14:20:03
linux
Vladimir Merk, 2017-01-03 14:20:03

How to organize live streaming from a webcam in linux?

Greetings!
Happy New Year 2017 everyone!
Before me, the task was to organize streaming broadcasting from a webcam on Linux.
Broadcasting takes place within the local network, so I want to use rtp, rtsp, or udp as the transmission protocol - by and large, the protocol does not matter, but I think not http for sure.
Picture quality comes first. In windows, this webcam shows very well, it even uses face lighting in the dark.
It is also very desirable to separate video and audio into 2 different streams, because. as a result, separate processing of video and audio for different tasks is planned.
On one linux debian machine with a webcam connected, well, another windows on which I check the results of the broadcast using the vlc player.
I am not strong in Linux and the task is quite specific, so Google did not help much.
What I did:
1) It turned out to broadcast video using cv2 in python - I understand that this is a wild crutch, but I checked the performance. I was not satisfied with the fact that the quality of webcam capture with this method is very low. The image is bad and no settings gave an acceptable result. Maybe it's because opencv uses its own generic webcam driver, but that's a guess.
2) I tried to use vlc - but I used the settings from google examples. As a result, only this option worked:

vlc v4l2:// :v4l2-dev=/dev/video0 :v4l2-width=1280 :v4l2-height=720 --sout="#transcode{vcodec=h264,vb=800,scale=1,acodec=mp4a,ab=128,channels=2,samplerate=44100}:rtp{sdp=rtsp://:8554/live.ts}" -I dummy

At the same time, there was no sound at all, and the image was gray, with blurred kennels of what is in front of the camera.
3) Using ffmpeg did not work at all, on the viewing side, although playback did not cause any errors, there was no image at all, as well as sound. An example code of what I wrote:
ffmpeg -f video4linux2 -i /dev/video0 -f alsa -vcodec libx264 -s 320x240 -pix_fmt yuv420p -vb 200000 -minrate 200000 -maxrate 200000 -bufsize 2000000 -acodec libmp3lame -ab 128k -ar 44100 -ac 2 -f rtp rtp://:8554/

As a result, none of the options led to a successful broadcast.
I would like to get help with setting up this ill-fated broadcast, on which I have already spent more than one hour :)
Thank you)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexey Sergey, 2017-01-03
@dev_random

You can look in the direction of GStreamer, I myself am now dealing with it.
start with this pipe and expand to audio processing, h264 encoding and subsequent rtp streaming. there is already Google, I only know that the corresponding plug-ins are available.
gst-inspect-1.0 -> show available plugins (pipeline items like v4l2src above)
gst-inspect-1.0 ${plugin} -> show plugin details and available settings

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question