1

I am trying to sync two instances of mplayer with -upd-master and -udp-slave, and notice that the slave staggers for about a second when the master begins the loop anew.

I am running debian 7.1 with MPlayer SVN-r36545 and here are my commands for the two videos running on the same i7 8GBram 240GB SSD machine (acting as a dhcp server):

mplayer -vo xv -udp-master -udp-ip 10.42.0.255 -loop 0 Videos/HDV_0537.MP4
mplayer -vo xv -udp-slave -loop 0 Videos/HDV_0538.MP4
denjello
  • 383

2 Answers2

3

This was actually really tricky, because the problem was that the -loop 0 I had been using on the slave was actually waiting for the master to broadcast its position and sync up. In fact I talked to one of my friends who was one of the mplayer developers and he told me what I wanted to do was impossible.

So the hack that I ended up using was to constantly check the current position of the slave and just as it gets to the EOF restarting the file after a specific bit of sleep - which I had to tune by hand...

First to set up the master use this:

mplayer -udp-master -udp-ip 10.42.0.255 masterVideo.mp4 -loop 0

For the slave I used the following script:

#!/bin/bash

fifo="/tmp/fifo"

rm -rf $fifo
mkfifo $fifo

mplayer -nocache -slave -fixed-vo -idle -udp-ip 10.42.0.255 -udp-slave -udp-seek-threshold 0.5 -osdlevel 0 -input file=$fifo >$fifo.answer "slaveVideo.mp4" &

somepid=$!
echo $somepid

function getpos() {
    local newpos=none
    while ! [[ "$newpos" =~ ANS_TIME ]]; do
        echo "get_time_pos" > $fifo
        newpos=$(tail -n 1 $fifo.answer)
        [[ "$newpos" =~ "EOF code: 1" ]] && { pos=-1; echo > $fifo.answer; return; } 
        pos=${newpos#ANS_TIME_POSITION=}
    done
    pos=${pos#0}
    pos2=$(echo "$pos + 0.14" | bc )
    printf "%.2f" "$pos2"
} 

function getlen() {
    local newlen=none
    while ! [[ "$newlen" =~ ANS_LENGTH ]]; do
        echo "get_time_length" > $fifo
        newlen=$(tail -n 1 $fifo.answer)
        len=${newlen#ANS_LENGTH=}
        sleep 0.1
    done
    len=${len#0}
    echo ${len}
}

len=$(getlen)

while true; do
    pos=$(getpos)
    if [[ $pos == $len ]]
        then
            # YOU MUST TWEAK THE FOLLOWING
            # SLEEP TIME FOR YOUR MACHINE
            sleep 0.5
            echo "loadfile /media/media/1.mp4" > $fifo
        fi
done

By the way, I am using a compiled mplayer - not mplayer2. Pause works very cleanly, as does skip... However, it is quite important that the two files have exactly the same duration and use the same codecs...

denjello
  • 383
1

First let me thank you man. I have been using mplayer in multi monitors for nearly 15 years now. I was simply never able to get it working and I found nothing on the internet that worked. It felt so ridiculous like why has no one ever thought of this?

Man your script worked and I couldnt believe it, after all this time! Thanks so much man! I scripted it into files masterVideo and slavedVideo, I added the command line args to the file so i can call masterVideo and slavedVideo with the movie name as well. I also added -volume 0 to the slave script cause the sound was echoing. Its rough and hacky but its working!

On the same computer is working fine... I am now trying to use this script across the network, but it only works on the same computer for now. Is there a way to launch a slavedVideo across the network using the ip address? When I try it only works if the master and slave are on the same machine. Here is the exact error


armel@shiva:~/tmp$ ../bin/slavedVideo movie.avi
76666
do_connect: could not connect to socket
connect: No such file or directory
Failed to open LIRC support. You will not be able to use your remote 
control.
[mpeg4 @ 0x7f63c469c380]Requested frame threading with a custom         
get_buffer2() implementation which is not marked as thread safe. This is 
not supported anymore, make your callback thread-safe.
(standard_in) 1: illegal character: _
(standard_in) 1: syntax error
^C

MPlayer interrupted by signal 2 in module: sleep_timer


I searched it and ended up putting lirc=no in my .mplayer/config file, then the movie would start paused but never sync and I would get this error. The movies are exactly the same file.


armel@shiva:~/tmp$ ~/bin/slavedVideo movie.avi 
936655
[mpeg4 @ 0x7fdb253d7380]Requested frame threading with a custom     
get_buffer2() implementation which is not marked as thread safe. This is 
not supported anymore, make your callback thread-safe.
^C
MPlayer interrupted by signal 2 in module: calc_sleep_time

So I added on to the solution, but networking is not working... Is there some additional setup required to get this working across the network? Both machines are connected fine with ssh. I realize this post was a long time ago, thought I would reach out and try anyway. What you have already done has been extremely helpful man thanks. :)