How to play a movie listening to two sound tracks simultaneously?

Solution 1:

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.

Solution 2:

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://:[email protected]: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.