9

I have movie files with multiple audio tracks (in the MKV container). I want to watch a movie while sending one language to the speakers (for the kids) and another language to the headphones (for myself), keeping the tracks in sync if the movie is paused, etc.

Assume my system already has two audio outputs properly configured.

Is there a way to do this with a media player in Linux? I have checked MPlayer and VLC so far, and they only support selecting one of the available audio tracks.

  • 1
    You are asking an off-topic question (software shopping). Questions seeking product, service, or learning material recommendations are off-topic. See On Topic. Try softwarerecs.stackexchange.com but please first read What is required for a question to contain "enough information". – DavidPostill Apr 12 '16 at 20:22
  • Maybe you could re-encode the file, combining both audio streams into one. So if one is 5.1 and the other is stereo, you would have an 8 channel stream. You can map these channels to different output devices using Soundflower on OS X, but I don't know about Linux. Sounds very inconvenient. You could also use something like Adobe Premiere or another NLE to map different audio tracks to different outputs. – Elliott B Apr 27 '16 at 8:21
  • I'm afraid that the_"kids"_ already have learnt the other language...at least I hope. :-) – Hastur May 10 '16 at 16:19
  • You could also mix down the audio tracks to stereo, then put them all into a 5.1 audio track (ignoring the center / subwoofer channels), and then mux them back into the movie. Then you can play it on any 5.1 sound card, just plug headphones & speakers into the appropriate output. – JonasCz Dec 25 '18 at 10:48
3

The Idea

aka How to break a (butter)fly on the wheel [Fly].

You can stream locally the whole movie with all the audio and subtitle tracks, e.g. with vlc.
Then it will be "enough" to connect two clients to that stream, selecting the language (and/or subtitles) and the different audio output (that we assume already configured).

Moreover with a new television, tablet or mobile phones it is not needed to run the clients on the computer... and when you put in pause the streamer you put in pause all... and it should work with windows too (always assumed the audio output already configured maybe with third part programs, in the case you want to run the two clients on the computer).

Some words more

A typical streaming command line can be similar to

vlc "movie.mkv" --sout-all --sout="#rtp{dst=239.255.100.100,port=5004,mux=ts}"

It is needed the option --sout-all [SO]

 --sout-all, --no-sout-all  Enable streaming of all ES (default disabled)
 Stream all elementary streams (video, audio and subtitles) (default disabled)

Read vlc -H to have some hints for the other (tons of) options available.

To "play" the stream

vlc rtp://239.255.100.100:5004  --audio-track=x

where x is the number of the audio stream you want to listen on that client.
All should be easily done from the server/client GUI too...

References and further readings
You may want to read more from the Luuk's blog page "Use VLC to play multiple video clips on multiple computers in sync" [1], you can eventually try to add external audio track starting from this wiki page of videolan [2], or you can play with Gstreamer and different output as suggested by Antonio in this answer [3].

GStreamer:
# The number and order of the tracks must be known…

gst-launch-1.0 \
filesrc location=example.mkv ! decodebin name=decoded \
decoded.src_0 ! queue ! autovideosink \
decoded.src_1 ! queue ! audioconvert ! alsasink device=”hw:1,0″ \
decoded.src_2 ! queue ! audioconvert ! alsasink device=”hw:2,0″

The above Gstreamer command can be a minimal working answer by itself or a path to save the (butter)fly...
... but seldom I'm tempted to defend my own nickname.

  • Note the RST IP needs to be in the range 224.0.0.0 through 239.255.255.255 (multicast IP range)or you won't be able to connect more than client to it. Seems like any such IP will just work. – chx Apr 7 at 9:29
  • @chx Let me know if the idea works with your other issue... – Hastur Apr 7 at 16:20
  • Yes it does! I wrote it up superuser.com/a/1422462/41259 but I thought this detail was worth mentioning here. – chx Apr 7 at 16:59
0

Streaming solution has a drawback -- clients use cache and they can go out of sync. It happened to me.

Another approach to run two different tracks simultaneously which I found useful for myself is to run two instances of VLC and sync their playback. But I can't be done properly without automation (manual actions made one-by-one that causes delays).

The solution is to control both VLC instances synchronously using web interface. It can be enabled via GUI or console:

vlc --extraintf=http --http-host 127.0.0.1 --http-port 8081 --http-password any_password

For each VLC instance use different ports. To control playback one command is enough -- pause toggle: http://:any_password@127.0.0.1:8081/requests/status.xml?command=pl_pause"

More info on commands.

In that case all you have to do is to make a program/script that sends HTTP request to both URIs simultaneously. I wrote very simple golang program for it (here is the source code). JS is another good candidate for that purpose. Going further it's possible to make more commands, assign global key bindings to that program/script.

The main point that the approach works good.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.