Monday, March 26, 2018

NDI and ffmpeg streaming commands

Just starting to get ffmpeg with NDI going so we can have remote cameras in OBS Studio for streaming. For now, though, here are some useful commands. These are for Linux, they should also work on Windows if you replace v4l2 (and probably alsa) with dshow . 

List the capabilities of a webcam
ffmpeg -f v4l2 -list_formats all -i /dev/video0

Monitor the camera (you may need to change the pixel format to something from the previous command that your camera supports)
ffplay -f v4l2 -framerate 30 -video_size 1280x720 -pixel_format mjpeg -i /dev/video0

List all NDI sources on the network
ffmpeg -f libndi_newtek -find_sources 1 -i dummy

Monitor an NDI stream
ffplay -f libndi_newtek -i "HAYLAPTOP (FrontCamera)"

Stream a webcam to NDI
ffmpeg -f v4l2 -framerate 30 -video_size 1280x720 -pixel_format mjpeg -i /dev/video1 -f libndi_newtek -pix_fmt uyvy422 FrontCamera

List audio devices
arecord -L

Stream a webcam to NDI with audio (an HD3000 webcam in this example)
ffmpeg -f v4l2 -framerate 30 -video_size 1280x720 -pixel_format mjpeg -i /dev/video0 -f alsa -i plughw:CARD=HD3000,DEV=0 -f libndi_newtek -pixel_format uyvy422 FrontCamera


A quick description of the options:
-framerate is the number of frames per second
-video_size is the resolution of the camera you'd like to capture at
-pixel_format is the format of the video stream. Input and output streams can be different, compressed input streams (e.g. mjpeg) are probably preferred. NDI only accepts uyvy422, bgra, bgr0, rgba, or rgb0 as an output format.
/dev/video0 is the first video device, usually the built-in webcam (others will be /dev/video1 etc.)
alsa is one way that Linux handles audio input and output, we're using it for input here.
libndi_newtek is non-free, so ffmpeg needs to be compiled with that option rather than using downloaded (or apt-get) builds.
FrontCamera is just a human-readable NDI name, you can call your whatever you'd like.

Other helpful resources include:
https://www.ffmpeg.org/ffmpeg-devices.html
https://trac.ffmpeg.org/wiki/StreamingGuide

Hopefully that's enough to get you started with NDI if you're able to compile ffmpeg from source.

Let me know if any of this doesn't (or does) work for you.

No comments: