Getting the error while using FFmpeg to record live streams

I am building a platform where a person can live stream using a camera or screen and has the option to record the stream whereas, the audience can join the stream as views.
I am using FFmpeg to record the stream in WEBM file format but getting the following error:

Only VP8 or VP9 or AV1 video and Vorbis or Opus audio and WebVTT subtitles are supported for WebM and incorrect codec parameters
Can someone please help me with this?

This error message indicates that you are trying to use FFmpeg to encode a file using a codec that is not supported for the WebM format. The WebM format is a container format specifically designed for use on the web, and it only supports a limited set of codecs for video, audio, and subtitles.

The specific codecs supported for WebM are VP8, VP9, and AV1 for video, Vorbis, and Opus for audio, and WebVTT for subtitles. If you are trying to use a different codec for any of these components, FFmpeg will not be able to create a WebM file.

So what should I do to fix it?

To fix this error, you will need to re-encode your video, audio, or subtitle streams using one of the supported codecs, or choose a different container format that supports the codecs you are using.

You can use the -c:v, -c:a, and -c:s options to specify the codecs for the video, audio, and subtitle streams, respectively. For example, to re-encode a video using the VP8 codec, you could use a command like this:

ffmpeg -i input.mp4 -c:v libvpx -c:a libvorbis output.webm
Remember that you may also need to use other options to specify the bitrate, resolution, and other parameters for the codecs you are using. You can find more information about these options in the FFmpeg documentation.

Otherwise, you can also try to record screen in FFmpeg

Thanks Gumlet community.