Saturday, September 21, 2024

Re: Using ffmpeg to record x11 screen & audio

On Fri, Sep 20, 2024 at 10:47:42PM -0700, patrick keshishian wrote:
> Hi folks,
>
> Attempting to do a screen capture (x11) including audio; say chrome is
> playing a video clip and I want to capture a portion of the screen
> along with the audio.
>
> Quick search shows following example:
>
> ffmpeg -f x11grab -probesize 32M -thread_queue_size 32 -i :0 \
> -f sndio -thread_queue_size 32 -i snd/0 \
> -codec:v libx264rgb -crf 0 -preset ultrafast \
> -codec:a pcm_s16le \
> raw.mkv
>
> Unfortunately, play back of raw.mkv file using ffplay, there is no
> audible audio.

You need to use the monitoring stream to capture audio produced by
applications. See here how to set it up:

https://www.openbsd.org/faq/faq13.html#recordmon

In the script I use to not hand-type all the ffmpeg syntax, I have this:

-f sndio -i snd/1.mon

(in your case likely snd/0.mon after setting it up)

>
> Also, this command captures the entire screen. I am only interested in
> capturing a portion of the screen, so my modified command is:
>
> ffmpeg -f x11grab -s:0 640x480 -framerate 25 -i :0.0+100+50 -f sndio
> -i snd/0 -crf 0 -preset ultrafast out.mp4
>
> With this, the capture is at offset 100+50 and a size of 640x480.
> Still no audio (unsurprisingly).
>
> Can someone give me a hint as to how to get audio to record as well?
>
> Cheers,
> --patrick
>
>
>
> ffmpeg details while playing raw.mkv
> Input #0, matroska,webm, from '/tmp/raw.mkv': 0KB sq= 0B f=0/0
> Metadata:
> ENCODER : Lavf58.76.100
> Duration: 00:00:49.33, start: 0.000000, bitrate: 10079 kb/s
> Stream #0:0: Video: h264 (High 4:4:4 Predictive), gbrp(tv, gbr/unknown/unknown
> , progressive), 1366x768, 29.25 fps, 29.25 tbr, 1k tbn, 58.50 tbc
> (default) Metadata:
> ENCODER : Lavc58.134.100 libx264rgb
> DURATION : 00:00:49.333000000
> Stream #0:1: Audio: pcm_s16le, 48000 Hz, 2 channels, s16, 1536 kb/s (default)
> Metadata:
> ENCODER : Lavc58.134.100 pcm_s16le
> DURATION : 00:00:48.981000000
> 29.27 A-V: -0.122 fd= 11 aq= 763KB vq= 5676KB sq= 0B f=0/0
>

No comments:

Post a Comment