Create a virtual output device, and a virtual source from it's monitor.
pactl load-module module-null-sink sink_name="virtual_speaker" sink_properties=device.description="virtual_speaker"
pactl load-module module-remap-source master="virtual_speaker.monitor" source_name="virtual_mic" source_properties=device.description="virtual_mic"
Any sound played to "virtual_speaker" will be sent to "virtual_mic".
You can play sound directly from ffmpeg with -f pulse
, but using this together with -re
(which you want for video playback to a virtual webcam) seems to add a couple of seconds of delay to the audio...
In my testing, this also made the video output laggy (still showing it was running at 1x). The only way I've been able to get smooth audio and video is by running two ffmpeg instances in parallel... Not a great solution.
ffmpeg -nostdin -re -i myfile.mkv -f v4l2 /dev/video0 &
PULSE_SINK=virtual_speaker ffmpeg -i myfile.mkv -f pulse "stream name"
kill $!
-nostdin
is needed for it to run in background.
PULSE_SINK=virtual_speaker
can be used with any audio player.
"stream name"
is just a display name the audio stream will get.
kill $!
will kill the video encoder, if the audio encoder exits.