How to Setup an Camera for RTMP Streaming
Uses the video4linux2 (or simply v4l2) input device to capture live input such as from a webcam.
install
1 | sudo apt install v4l-utils |
To list the supported, connected capture devices you can use the v4l-ctl tool. This example shows two connected webcams: /dev/video0 and /dev/video1.
1 | v4l2-ctl --list-devices |
To list available formats (supported pixel formats, video formats, and frame sizes) for a particular input device:
1 | ffmpeg -f v4l2 -list_formats all -i /dev/video0 |
Alternatively you could use v4l2-ctl –list-formats-ext to list available formats.
Example to encode video from /dev/video0
1 | ffmpeg -f v4l2 -framerate 25 -video_size 640x480 -i /dev/video0 output.mkv |
Use LiveGo as rtmp sever. LiveGo is a simple and efficient live broadcast server.
https://github.com/gwuhaolin/livego
Directly downloading the compiled binary file or compile from source.
Download the source code git clone https://github.com/gwuhaolin/livego.git
Go to the livego directory and execute ‘go build’.
First, execute the livego binary file to start the livego service.
Get a channelkey from http://localhost:8090/control/get?room={appname} and copy data like your channelkey.
Such as you enter http://localhost:8090/control/get?room=cam and the browser return
1 | {"status":200,"data":"rfBd56ti2SMtYvSgD5xAV0YU99zampta7Z7S575KLkIZ9PYk"} |
The appname is cam. And channelkey is rfBd56ti2SMtYvSgD5xAV0YU99zampta7Z7S575KLkIZ9PYk.
After start the LiveGO, now You can use ffmpeg to push your camera stream.
1 | ffmpeg -f v4l2 -i /dev/video0 --vcodec libx264 -f flv rtmp://localhost:1935/live/cam |
Now is time to downstream playback.
FLV: http://localhost:7001/live/rfBd56ti2SMtYvSgD5xAV0YU99zampta7Z7S575KLkIZ9PYk.flv
HLS: http://localhost:7002/live/rfBd56ti2SMtYvSgD5xAV0YU99zampta7Z7S575KLkIZ9PYk.m3u8