record application audio only with ffmpeg
First of all don't use -sameq
: it does not mean "same quality" and has recently been removed from ffmpeg. Instead you can encode a losslessly with libx264:
ffmpeg -f x11grab -s $(xdpyinfo | grep 'dimensions:'|awk '{print $2}') -r 25 -i :0.0 -codec:v libx264 -preset ultrafast -qp 0 lossless.mkv
Using a lossless encoder is fast; meaning you have a better chance of actually capturing at your declared frame rate. However, the output can be a huge file, so once capturing is completed it is generally re-encoded to a more manageable size:
ffmpeg -i lossless.mkv -codec:v libx264 -preset medium -crf 23 -pix_fmt yuv420p output.mp4
If you computer can handle it you can skip the lossless intermediate step and encode directly to normal, lossy H.264 video.
As for the audio, according to HOWTO: Proper Screencasting on Linux:
Q: How can I control PulseAudio input? (e.g. capture application audio instead of mic)
A: Install “pavucontrol“. Start recording with ffmpeg. Start pavucontrol. Go to the “Recording” tab and you’ll find ffmpeg listed there. Change audio capture from “Internal Audio Analog Stereo” to “Monitor of Internal Audio Analog Stereo“. Now it should record system and application audio instead of microphone.
Your ffmpeg command may then look like:
ffmpeg -f alsa -ac 2 -i pulse -f x11grab -r 30 -s 1024x768 -i :0.0 -codec:a pcm_s16le -codec:v libx264 -preset ultrafast -qp 0 output.mkv
Also see the FFmpeg and x264 Encoding Guide.
Related videos on Youtube
Comments
-
Pavan K almost 2 years
I would like to use ffmpeg to use application audio only instead of the whole system audio while screen grabbing. How can I do this if the grabbing command is something like this? By application specific I mean it can be audio from chrome(audio is out from chrome through internet)
ffmpeg -f x11grab -s `xdpyinfo | grep 'dimensions:'|awk '{print $2}'` -r 25 -i :0.0 -sameq desktop.mkv
I tried to use pulse audio but I couldn't get it to work.
If someone could even post a link to a working pulse audio setup I would be grateful. I want to do this programatically. And also if I am running two separate audio streams I should be able to capture only one! I was not able to setup that using pavucontrol
-
Pavan K over 11 yearsBut I want to do this programatically. And also if I am running two separate audio streams I should be able to capture only one! I was not able to setup that using pavucontrol.
-
Elisa Cha Cha over 11 years@PavanK You should have mentioned this in your question.
-
Pavan K over 11 yearsI just did thanks for your answer and for your suggestion as well :)