- The article shows how to use FFmpeg with the avfoundation input device to record video from a USB capture device on macOS.
- The article provides the steps and commands to list the available input devices, start and stop recording, and specify the output format, resolution, frame rate, codec, and other parameters.
- The article also gives some troubleshooting tips and solutions for common problems, such as compatibility, connection, index, disk space, memory, and version issues.
If you have a USB capture device, such as an Elgato Cam Link or a Magewell USB Capture HDMI, you might want to record video from it on your Mac using FFmpeg. FFmpeg is a powerful and versatile command-line tool that can handle various multimedia tasks, such as encoding, decoding, filtering, streaming, and more. In this article, we will show you how to use FFmpeg with the avfoundation input device to capture video from a USB capture device on macOS.
Before we begin, you will need the following:
- A Mac computer running macOS 12.3.1 or later.
- A USB capture device that supports UVC (USB Video Class) standard, such as Elgato Cam Link or Magewell USB Capture HDMI.
- A video source that you want to capture, such as a camera, a game console, or a DVD player.
- A USB cable to connect the capture device to your Mac.
- FFmpeg installed on your Mac. You can download the latest version from the official website or use Homebrew to install it.
- Connect the USB capture device to your Mac and the video source to the capture device. Make sure the capture device is powered on and recognized by your Mac. You can check the System Information app to see if the capture device appears under the USB section.
- Open a Terminal app and run the following command to list all the available input devices for FFmpeg:
ffmpeg -f avfoundation -list_devices true -i ""
You should see something like this:
[AVFoundation indev @ 0x7f8a9c40a000] AVFoundation video devices: [AVFoundation indev @ 0x7f8a9c40a000]  FaceTime HD Camera [AVFoundation indev @ 0x7f8a9c40a000]  Capture screen 0 [AVFoundation indev @ 0x7f8a9c40a000]  Cam Link 4K [AVFoundation indev @ 0x7f8a9c40a000] AVFoundation audio devices: [AVFoundation indev @ 0x7f8a9c40a000]  Built-in Microphone [AVFoundation indev @ 0x7f8a9c40a000]  Cam Link 4K : Input/output error
In this example, we are using an Elgato Cam Link 4K as the capture device, and it appears as both a video device and an audio device with index 2 and 1 respectively. Note that the index may vary depending on your setup, so make sure you use the correct one for your device.
- Run the following command to start recording video from the capture device:
ffmpeg -f avfoundation -i "<video_device_index>:<audio_device_index>" output.mp4
Replace <video_device_index> and <audio_device_index> with the index of your capture device from the previous step. For example, if your capture device has index 2 for video and 1 for audio, use 2:1. If you don’t want to record audio, use none instead of the audio index. For example, 2:none.
Replace output.mp4 with the name of the output file that you want to save. You can also specify other options, such as -video_size, -framerate, -c:v, -c:a, etc., to control the output format, resolution, frame rate, codec, bitrate, and other parameters.
For example, if you want to record a 1080p video at 30 fps with H.264 codec and AAC audio codec, use:
ffmpeg -f avfoundation -video_size 1920x1080 -framerate 30 -i "2:1" -c:v libx264 -c:a aac output.mp4
- Press q or Ctrl+C to stop recording and exit FFmpeg. You should see a message like this:
frame= 1800 fps= 30 q=-1.0 Lsize= 24877kB time=00:01:00.00 bitrate=3395.6kbits/s speed= 1x video:23376kB audio:1415kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.341847%
- Check the output file and play it with your preferred media player. You should see the video and hear the audio from your capture device.
If you encounter any problems while recording video from your capture device, here are some possible solutions:
- Make sure your capture device is compatible with UVC standard and macOS. Some capture devices may require additional drivers or software to work properly. Check the manufacturer’s website for more information.
- Make sure your capture device is connected properly and recognized by your Mac. You can use the System Information app or the system_profiler SPUSBDataType command to check the status of your USB devices.
- Make sure you use the correct index for your capture device in the FFmpeg command. You can use the ffmpeg -f avfoundation -list_devices true -i “” command to list all the available input devices and their index.
- Make sure you have enough disk space and memory to record and save the video. You can use the df -h and free -m commands to check the disk space and memory usage on your Mac.
- Make sure you have the latest version of FFmpeg installed on your Mac. You can use the ffmpeg -version command to check the version of FFmpeg. You can download the latest version from the official website or use Homebrew to update it.
Frequently Asked Questions (FAQs)
Question: How can I record video from multiple capture devices at once?
Answer: You can use the -map option to specify which input streams to map to which output streams. For example, if you have two capture devices with index 2 and 3 for video and 1 and 4 for audio, you can use:
ffmpeg -f avfoundation -i "2:1" -f avfoundation -i "3:4" \ -map 0:v -map 0:a -c:v libx264 -c:a aac output1.mp4 \ -map 1:v -map 1:a -c:v libx264 -c:a aac output2.mp4
This will record video and audio from both capture devices and save them as two separate files.
Question: How can I record video from a specific region of the screen?
Answer: You can use the -video_size and -offset_x and -offset_y options to specify the size and position of the region to capture. For example, if you want to capture a 640×480 region at x=100 and y=200, use:
ffmpeg -f avfoundation -video_size 640x480 -offset_x 100 -offset_y 200 -i "1:none" output.mp4
Question: How can I record video from a specific window?
Answer: You can use the -capture_cursor option to enable capturing the cursor, then move it over the window that you want to capture. FFmpeg will automatically detect the window boundaries and crop the video accordingly. For example, if you want to capture a window with title “Calculator”, use:
ffmpeg -f avfoundation -capture_cursor 1 -i "1:none" output.mp4
Then move your cursor over the Calculator window and press q or Ctrl+C to start recording.
This article is for informational purposes only and does not constitute professional advice. The author is not responsible for any damages or losses caused by following the instructions or using the tools mentioned in this article. Use them at your own risk.