Screen recording using ffmpeg

9,751

Solution 1

If you want your computer's audio to be recorded along with your screen at full resolution, rather than your microphone, (the question was unclear as to which one you wanted) follow these instructions:

The device 'Stereo Mix (Realtek Audio)' probably needs to be enabled, in my case, it wasn't.

Stereo mix is what allows you to record your computer's audio in Windows.

  1. Go to control panel --> hardware and sound --> sound

  2. Then click the 'recording' tab.

  3. Now right click inside the device list and make sure that 'show disabled devices' is ticked. Stereo Mix should then show up.

  4. Now right click it and select 'enable'.

Note that Stereo Mix's full name is 'Stereo Mix (Realtek Audio)'

Now, to record your audio and pc screen at full resolution, you would type:

ffmpeg -f gdigrab -framerate 30 -i desktop -c:v libx264 output.mkv -f dshow -i audio="Stereo Mix (Realtek Audio)" output.mkv

Also note that if you have multiple sound devices (i.e I use a laptop with a monitor - my 2 devices are system speakers and monitor speakers) make sure you have set the sound device to be your default in the volume tab (e.g. I would set my sound output to be the laptop speakers because they are my default). If you don't have multiple sound devices, then just ignore this.

You should now be able to record your screen and pc audio, if that's what you were looking for, otherwise, if you wanted your microphone to be recorded instead, see It Wasn't Me's answer.

Hope this helps

Solution 2

1. Get microphone device name using @Leo Chapiro/answer

2>&1 ffmpeg -list_devices true -f dshow -i dummy -hide_banner|find "Micro"

rem :: outputs is your microphone device :: 
[dshow @ 000001f8ff8d8c40]  "Microphone (Realtek High Definition Audio)"

2. Add your device input with -f dshow -i audio="Microphone (Realtek High Definition Audio)" ...

ffmpeg -f gdigrab -framerate 30 -i desktop -f dshow -i audio="Microphone (Realtek High Definition Audio)" output.mkv

3. For full hd, try:

ffmpeg -f gdigrab -framerate 30 -i desktop -c:v libx264 -qp 0 output.mkv  -f dshow -i audio="Microphone (Realtek High Definition Audio)" output.mkv

Save audio="String" in variable in loop:

  • In command line:
for /f tokens^=2delims^=^" %i in ('"2>&1 ffmpeg -list_devices true -f dshow -i dummy -hide_banner|find "Micro""')do set "_mic="%~i""
  • In Bat/Cmd file:
for /f tokens^=2delims^=^" %%i in ('"2>&1 ffmpeg -list_devices true -f dshow -i dummy -hide_banner|find "Micro""')do set "_mic="%%~i""

To direct use in loop audio="String" in loop:

  • In command line:
for /f tokens^=2delims^=^" %i in ('"2>&1 ffmpeg -list_devices true -f dshow -i dummy -hide_banner|find "Micro""')do 
ffmpeg -f gdigrab -framerate 30 -i desktop -f dshow -i audio="%~i" output.mkv
  • In Bat/Cmd file:
for /f tokens^=2delims^=^" %%i in ('"2>&1 ffmpeg -list_devices true -f dshow -i dummy -hide_banner|find "Micro""')do 
ffmpeg -f gdigrab -framerate 30 -i desktop -f dshow -i audio="%%~i" output.mkv
Share:
9,751
Nikto
Author by

Nikto

Updated on September 18, 2022

Comments

  • Nikto
    Nikto almost 2 years
    ffmpeg -f gdigrab -framerate 30 -i desktop output.mkv
    

    I use this command and I have two questions:

    1. My screen allows full-hd, but seems like output.mkv in bad (not full-hd) quality. How to record screen in the best quality?

    2. My command doesn't record audio. How to record audio too?

  • Nikto
    Nikto almost 4 years
    It's that's what i actually was looking. Thanks
  • Nikto
    Nikto almost 4 years
    I can't play output.mkv. Final output file doesn't play. There is ffmpeg log: pastebin.com/29wUD1Vy Early, stereo mix was disabled, but now i have turned on Stereo Mix.
  • Nikto
    Nikto almost 4 years
    thanks, but i still have some issues. 1)When i say any phrase, i don't heard it in the final output file. 2)Sound from my computer successfully records, but i made test: I had runed my command and after that i was starting watch movie. And my movie in final output file freezes If you haven't understood me, i can give you a link on example of my final output file. How to fix it? And seems like resolution of final output file is better. Thanks again.
  • Nikto
    Nikto almost 4 years
    And messages from ffmpeg here: Thread message queue blocking; consider raising the thread_queue_size option (current value: 8) Stream #0: not enough frames to estimate rate; consider increasing probesize Guessed Channel Layout for Input Stream #1.0 : stereo
  • pigeonburger
    pigeonburger almost 4 years
    To fix the thread_queue_size issue see this post: stackoverflow.com/questions/61723571/…
  • pigeonburger
    pigeonburger almost 4 years
    As for the other issues, it could be your cpu is straining too hard - what sort of cpu do you have and also what gpu? Thanks
  • Nikto
    Nikto almost 4 years
    Bounty ends in 2 hours. I will award your answer, and you will answer about other issues: 1), 2) - ok?
  • Nikto
    Nikto almost 4 years
    As far as i understand, your the last message about second problem. My cpu is: intel core i5:8300H. And my gpu is: GeForce GTX 1050. And i have any ideas about first problem. Seems like we should add another input device and it will be microphone. Eventually, we will have 3 input devices: Stereo mix, Microphone and desktop(-i desktop). If i just add -f dshow -i audio="Microphone (Realtek High Definition Audio)" output.mkv in the end of ur command, will it reslove my problem?
  • Nikto
    Nikto almost 4 years
    Only when i record movie.
  • Nikto
    Nikto almost 4 years
  • Nikto
    Nikto almost 4 years
    pls, read my last comment in the chat.
  • Nikto
    Nikto almost 4 years
    i have written you in the chat.
  • giantqtipz
    giantqtipz over 2 years
    would you have any insight on how to do this for the Mac? I've been searching since yesterday and struggling to find a solution... Basically trying to record screen along with the audio as well.