How to record webcam video and audio using ffmpeg

Introduction

Hello! 👋

In this tutorial I will show you how to use the ffmpeg command to record your webcams video and audio to an mp4 file.

The Command

The command is a pretty simple one liner. (Please note my machine is Linu…

Introduction

Hello! 👋

In this tutorial I will show you how to use the ffmpeg command to record your webcams video and audio to an mp4 file.

The Command

The command is a pretty simple one liner. (Please note my machine is Linux so the format/input may change depending on your OS)
You can alter the command based on your webcam input by checking the following documentation:
https://trac.ffmpeg.org/wiki/Capture/Webcam

ffmpeg -f pulse -ac 2 -i default -f v4l2 -i /dev/video0 -t 00:00:20 -vcodec libx264 record.mp4

The -f defines the format, pulse for audio and v4l2(Video 4 Linux 2).
The -ac defines the audio channels, in this case 2.
The -i defines the input, default for audio and the webcam for video.
The -t defines the duration of the recording, in this case 20 seconds.
The -vcodec defines the output video codec, since it is an mp4 file it is set to libx264 (H.264)
Audio should default to AAC so -acodec is not needed.

Conclusion

Here I’ve given a very simple demonstration on how to use the ffmpeg command to capture the user’s webcam footage with audio.

I’m thinking of creating a C++ example and will let you know when that’s finished. 😎

Side note, I’m sorry for the wait on my WebRTC Android Tutorial, been pretty hectic recently but it’s almost finished!

Hope you found this quick tutorial useful and if you have any useful resources for learning FFmpeg please share them with me.

Like me work? I post about a variety of topics, if you would like to see more please like and follow me.
Also I love coffee.

“Buy Me A Coffee”


Print Share Comment Cite Upload Translate
APA
Ethan | Sciencx (2024-03-29T00:19:59+00:00) » How to record webcam video and audio using ffmpeg. Retrieved from https://www.scien.cx/2022/09/24/how-to-record-webcam-video-and-audio-using-ffmpeg/.
MLA
" » How to record webcam video and audio using ffmpeg." Ethan | Sciencx - Saturday September 24, 2022, https://www.scien.cx/2022/09/24/how-to-record-webcam-video-and-audio-using-ffmpeg/
HARVARD
Ethan | Sciencx Saturday September 24, 2022 » How to record webcam video and audio using ffmpeg., viewed 2024-03-29T00:19:59+00:00,<https://www.scien.cx/2022/09/24/how-to-record-webcam-video-and-audio-using-ffmpeg/>
VANCOUVER
Ethan | Sciencx - » How to record webcam video and audio using ffmpeg. [Internet]. [Accessed 2024-03-29T00:19:59+00:00]. Available from: https://www.scien.cx/2022/09/24/how-to-record-webcam-video-and-audio-using-ffmpeg/
CHICAGO
" » How to record webcam video and audio using ffmpeg." Ethan | Sciencx - Accessed 2024-03-29T00:19:59+00:00. https://www.scien.cx/2022/09/24/how-to-record-webcam-video-and-audio-using-ffmpeg/
IEEE
" » How to record webcam video and audio using ffmpeg." Ethan | Sciencx [Online]. Available: https://www.scien.cx/2022/09/24/how-to-record-webcam-video-and-audio-using-ffmpeg/. [Accessed: 2024-03-29T00:19:59+00:00]
rf:citation
» How to record webcam video and audio using ffmpeg | Ethan | Sciencx | https://www.scien.cx/2022/09/24/how-to-record-webcam-video-and-audio-using-ffmpeg/ | 2024-03-29T00:19:59+00:00
https://github.com/addpipe/simple-recorderjs-demo