Score:0

How can I use ffmpeg to record my screen with its input and output audios?

in flag

I was trying to use ffmpeg to record my screen with its audios. I'm basing myself on the commands used on this answer. I know that I can record my screen without the audio by using the command:

ffmpeg -video_size 1920x1080 -framerate 30 -f x11grab -i :0.0 -map '0' 0.mp4

I also know I can record the audio of my computer with the command:

ffmpeg -f pulse -i "alsa_input.pci-0000_00_1f.3.analog-stereo" -map '0' 0.mp3

However, if I try to put these commands together with:

ffmpeg -video_size 1920x1080 -framerate 30 -f x11grab -i :0.0 -f pulse -i "alsa_input.pci-0000_00_1f.3.analog-stereo" -map '0' 0.mp4

It generates a video with no sound in it. What am I missing? How can I put these two commands together in order to generate a video with audio using ffmpeg?

mchid avatar
bo flag
Have you tried using alsa instead of pulse: `-f alsa -i hw:0` for example?
mchid avatar
bo flag
[This answer](https://askubuntu.com/questions/892482/how-to-record-desktop-with-audio-on-ffmpeg) shows an example using alsa instead of pulse.
raylight avatar
in flag
@mchid Even though when I use the command from that answer it generates a video with audio, the video doesn't show what's on my screen. It shows something like a gray blurry image and the audio is very bad. I'm not sure if I should tweak some of the parameters there in order to make it show my screen correctly.
mchid avatar
bo flag
On [this answer](https://askubuntu.com/a/450786/167115), you may try this with your original command. What they do is install pavucontrol: `sudo apt update` and `sudo apt install pavucontrol` and then open the pavucontrol application (it may show up as pulse audio volume control in your installed apps). Next, start ffmpeg recording and go to the "recording" tab of pavucontrol. Here, ffmpeg should show and you can change the input to "monitor".
mchid avatar
bo flag
Sorry, I didn't include a link. I edited the previous comment to include the link.
mchid avatar
bo flag
You may also want to check out that original question as they use options like `-acodec libmp3lame` and others which may be necessary for an mp4 file?
raylight avatar
in flag
@mchid I'm tweaking the parameters and trying to make it work here... The closest that I got from making it work is with `ffmpeg -video_size 1920x1080 -framerate 30 -f x11grab -i :0.0 -f alsa -i hw:0 0.mp4`... It records the video well but the audio is very bad, I can't distinguish what's being said, I just know that there's an audio. I've tried putting `-acodec libmp3lame` before the file name and it executes too... But the result is still the same...
mchid avatar
bo flag
Like I said, try with the pulse option but open `pavucontrol` before you run the command. Then, run the command and go to the "Recording" tab on pavucontrol and make sure it is set to the one you want with "monitor" so that it will record the actual output of that device. Another option would be to install the `alsa-utils` package: `sudo apt install alsa-utils` and then run the command `alsamixer` and then adjust the volume. Make sure none of the volumes show in red. Also, make sure automute is disabled.
raylight avatar
in flag
@mchid Ah, it's solved now. In my case, `pavucontrol` was showing everything alright on its controls. The problem was my `ffmpeg` command. The command from the question on your second link does exactly what I need `ffmpeg -f x11grab -y -r 60 -s 1920x1080 -i :0.0 -vcodec mpeg4 -f alsa -i pulse -ar 44100 -acodec libmp3lame -ab 192k -ac 2 output.mp4 -qscale 0`. Although the OP there said it wasn't working for him, for me it works fine :)
za flag
Myself, loathe to alter any PA configuration, as this creates many problems for my setup. Suggestion... For a GUI approach, simple, try "simplescreenrecorder" from the repos. This records the screen only. To add audio, use a microphone to record from speakers. If you have good hardware, you will have good results. I use this simple, quick method to record live stream off the net (but not to violate copyrights).
mchid avatar
bo flag
Remember though, usually, it's not important that pavucontrol shows the correct device on the record tab, it must show the correct device listed as "monitor of" the correct device. But if it's working it's working. I got it working using the following as well `ffmpeg -f pulse -ac 2 -i default -f x11grab -r 30 -s 1920x1080 -i :0 -c:v libx264 filename.mp4`
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.