RTSP feed with ffmpeg and the Mac camera

I have two Macs in my network. On the first one I want to capture the FaceTime camera via ffmpeg and make a RTSP feed available on the network, which I can watch on the second Mac.


Solution 1:

I successfully implemented something close to this (not true RTSP, but instead RTP streaming over UDP) with the following hardware and software:

  • 2012 Macbook Pro, macOS Mojave 10.14.6
  • ffmpeg version 3.4.8
  • ffplay version 4.3.2 (my executable was named ffplay4)

List the audio and video input devices with ffmpeg -f avfoundation -list_devices true -i ""

On the 2012 MBP, the first video device (index 0) is FaceTime HD Camera (Built-in) and the first audio device (index 0) is Built-in Microphone.

The video capture/sending and the video receipt/playback can be done on the same machine, or ffmpeg can send to a remote IP. In this example, it is sending an MPEG transport stream over UDP to the loopback address 127.0.0.1:9988 but that could just as easily be the IP address and port of another Mac:

ffmpeg \
  -f avfoundation \
  -pix_fmt yuyv422 \
  -video_size 320x240 \
  -framerate 15 \
  -i "0:0" -ac 2 \
  -vf format=yuyv422 \
  -vcodec libx264 -maxrate 2000k \
  -bufsize 2000k -acodec aac -ar 44100 -b:a 128k \
  -f rtp_mpegts udp://127.0.0.1:9988

To receive and play the video:

ffplay4 -i udp://@0.0.0.0:9988

It may take a few seconds to start up and there will be a few errors at first, but the video should begin playing in ffplay4 within a couple seconds.

Bonus: this stream is also viewable with VLC (version 3.0.12). File->Open Network->URL rtp://@127.0.0.1:9988. Again, it will take a few seconds (5-10) to begin displaying the video.

Happy streaming.