0

How can I use a single ffmpeg or ffplay command to play two audio files at the same time, but through different output devices?

As is documented, this command plays a single audio through the output device with index 1:

ffmpeg -i audio.mp3  -f audiotoolbox -audio_device_index 1 -

But how can I play two at the same time? Without using two commands (because eventually I want to arrive at a filter suitable for mpv synchronous playback https://superuser.com/a/1325668/325613)

theonlygusti
  • 888
  • 4
  • 14
  • 30
  • 1
    Try using [Tee pseudo-muxer](https://ffmpeg.org/ffmpeg-formats.html#tee): `ffmpeg -i audio.mp3 -f tee -map 0:a -f tee "[f=audiotoolbox:audio_device_index=1]pipe:0|[f=audiotoolbox:audio_device_index=2]pipe:1"` (I can't test it). – Rotem Oct 04 '22 at 16:01
  • 1
    Example for streaming to two UDP ports: `ffmpeg -re -f lavfi -i testsrc=size=192x108:rate=25 -f lavfi -i sine=frequency=400 -vcodec libx264 -tune zerolatency -g 1 -pix_fmt yuv420p -acodec aac -ar 22050 -f tee -map 0:v? -map 1:a? "[f=mpegts]udp://127.0.0.1:5000|[f=mpegts]udp://127.0.0.1:6000"` Playing using two FFplay instances: `ffplay -timeout 100000000 -vf setpts=0 -i udp://127.0.0.1:5000` and `ffplay -timeout 100000000 -vf setpts=0 -i udp://127.0.0.1:6000` – Rotem Oct 04 '22 at 16:19
  • @Rotem in your first comment, where is the second audio inputted? – theonlygusti Oct 04 '22 at 22:25
  • @Rotem Why are the mappings necessary? – theonlygusti Oct 04 '22 at 22:29
  • I see I misunderstood your question. I thought there is one input and two outputs. Two inputs and two outputs is possible with mapping. No need to use tee muxer. – Rotem Oct 05 '22 at 00:04
  • Example for two audio inputs and two outputs: `ffmpeg -re -i audio0.mp3 -re -i audio1.mp3 -c copy -map 0:a -f mpegts udp://127.0.0.1:5000 -c copy -map 1:a -f mpegts udp://127.0.0.1:6000` – Rotem Oct 05 '22 at 09:00
  • @Rotem `ffmpeg -i 1.mp3 -i 2.mp3 -map 0:a -f audiotoolbox -audio_device_index 3 - -map 1:a -f audiotoolbox -audio_device_index 1 -` only plays `2.mp3` out of audio device 1, audio device 3 is silent – theonlygusti Oct 05 '22 at 12:33
  • @Rotem `ffmpeg -i 1.mp3 -i 2.mp3 -map 0:a -f audiotoolbox -audio_device_index 3 -` plays `1.mp3` through device 1 (obviously, device 3 is silent) – theonlygusti Oct 05 '22 at 12:37
  • Same problem with naming the output files `1` and `3` instead of `-` and `-` (https://ffmpeg.org/ffmpeg-devices.html#AudioToolbox) `ffmpeg -i 1.mp3 -i 2.mp3 -map 0:a -f audiotoolbox 3 -map 1:a -f audiotoolbox 1` – theonlygusti Oct 05 '22 at 12:53
  • You may try replacing the two`-` with `pipe:0` and `pipe:1`. Consider using UDP streaming, it may be sutible for MPV. – Rotem Oct 05 '22 at 14:53

0 Answers0