Record Webcam Video and Audio with FFmpeg DirectShow
This guide provides a straightforward walkthrough on how to capture synchronized video and audio from a webcam on Windows using FFmpeg and the DirectShow (dshow) device interface. You will learn how to locate your device names and execute the proper command-line instructions to record your media into a single output file.
Step 1: List Your DirectShow Devices
Before recording, you must find the exact names of your webcam and microphone as recognized by Windows. Open your Command Prompt or PowerShell and run the following command:
ffmpeg -list_devices true -f dshow -i dummyFFmpeg will output a list of your connected hardware. Look under the
“DirectShow video devices” and “DirectShow audio devices” sections. Note
down the exact device names inside the quotation marks (e.g.,
"Integrated Camera" and
"Microphone (Realtek Audio)").
Step 2: Run the Capture Command
Once you have your device names, use the following template to start capturing video and audio simultaneously:
ffmpeg -f dshow -i video="Your Video Device":audio="Your Audio Device" output.mp4Replace Your Video Device and
Your Audio Device with the exact names you found in Step 1.
For example:
ffmpeg -f dshow -i video="Integrated Camera":audio="Microphone (Realtek Audio)" output.mp4Step 3: Optimize the Recording (Recommended)
To prevent dropped frames, ensure audio-video synchronization, and compress the output file efficiently, use a more detailed command that specifies the frame rate, resolution, and encoders:
ffmpeg -f dshow -rtbufsize 100M -framerate 30 -video_size 1280x720 -i video="Integrated Camera":audio="Microphone (Realtek Audio)" -c:v libx264 -preset ultrafast -c:a aac -b:a 128k output.mp4Here is what these parameters do: * -rtbufsize 100M:
Sets a 100 MB real-time buffer memory to prevent stuttering and
buffer-overflow errors during recording. * -framerate 30:
Forces the webcam to capture at 30 frames per second. *
-video_size 1280x720: Sets the video resolution to 720p
(adjust this to match your webcam’s supported resolutions). *
-c:v libx264 -preset ultrafast: Encodes the video using the
H.264 codec with the fastest preset to minimize CPU usage while
recording. * -c:a aac -b:a 128k: Encodes the audio using
the AAC codec at a bitrate of 128 kbps.
Press Q on your keyboard while the Command Prompt window is active to safely stop the recording and finalize the output file.