0

I've figured out a way to capture video on wayland (hyprland) with ffmpeg, but that method does not cover audio.

Most people on wayland will be using pipewire, pipewire has a compatibility layer for pulseaudio called pipewire-pulse which allows most audio designed for pulseaudio to be played or recorded through pipewire.

But in ffmpeg's case it doesn't seem to work.

ffmpeg -device /dev/dri/card1 -vaapi_device /dev/dri/renderD129 -f pulse -ac 2 -i easyeffects_sink.monitor -c:a libopus -framerate 60 -f kmsgrab -i - -c:v h264_vaapi -rc_mode QVBR -q:v 10 -maxrate 327680 -b 81920 -pix_fmt vaapi -vf hwmap=derive_device=vaapi,scale_vaapi=format=nv12:out_range=full out.mp4 

The above command fails with

Option device not found. Error opening input file easyeffects_sink.monitor. Error opening input files: Option not found 

But if I remove this part:

 -f pulse -ac 2 -i easyeffects_sink.monitor -c:a libopus 

It will work relatively fine. and if I am on x11 instead of wayland, using x11grab instead of kmsgrab

ffmpeg -vaapi_device /dev/dri/renderD129 -f pulse -ac 2 -i easyeffects_sink.monitor -c:a libopus -video_size 2560x1600 -framerate 60 -f x11grab -i :1.0 -c:v h264_vaapi -rc_mode QVBR -q:v 10 -maxrate 327680 -b 81920 -pix_fmt vaapi -vf format=nv12,hwupload out.mp4 

That command works perfectly fine even if it uses the exact same options that didn't work on kmsgrab.

Which leaves me with the question of whether ffmpeg is capable of capturing audio from a wayland environment at all.

1 Answer 1

2

You got something wrong with your ffmpeg command line: you seem to mean to specify the capture device as input, but you forget to do that. The first time you specify an input is -i easyeffects_sink.monitor, and you correctly mean -f pulse -ac 2 to "describe" that input, but you don't do the same for your capture input.

So, ffmpeg doesn't know what your -device option refers to.

Order of arguments makes a difference! Remember that ffmpeg's command line always looks like (top of man ffmpeg):

ffmpeg [global_options] {[input_file_options] -i input_url} ... {[output_file_options] output_url} ... 

The options describing an input must come directly prior to the respective -i!

1
  • 1
    You're correct, moving the -device part to behind -f kmsgrab solved the issue, I figured -device would be a global option like -vaapi_device but I guess not. Commented Aug 4 at 9:50

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.