/projects/mpsync last modified 37.114 days ago

mpsync: an mplayer synchronization utility for linux

This project, mpsync, is the result of manually syncing videos with friends while chatting over IRC. After all obtaining the same video, I would call out, "5,4,3,2,1,GO" and we would all unpause our players, starting at the zero position. In increments of 5 seconds, I would then call out positions (:05, :10:, :15, etc) until we were all synchronized.

My latest utility brings some automation to watching videos in sync. Mpsync is a client/server application, and includes both parts in the same program. As a server, mpsync will start mplayer and keep track of the playing video's position. It will also open a port for clients to connect to.

When running as a client, mpsync will connect to a master server and periodically check for the master's position. If the server's video is ahead or behind the client's, the client will tell mplayer to seek to the master's position. The client will respond to the server seeking forward to backward in the video, as well as pausing or stopping.

The synchronization process is done automatically, and is relatively smooth. Generally it takes the client 5-10 seconds to get within a 1-second delta of the server. The master position and delta are displayed in the console.

Currently this program only works in Linux. Mplayer does not seem to output the position in Windows like it does in Linux, so mpsync is naturally unable to function correctly on any Windows platform.

Mpsync is written in PHP and, to clarify for the newbies, is not web-based. It is a CLI application that will run as long as a PHP binary is present. The default location in the script for PHP is /usr/local/bin/php. If your binary is located elsewhere (such as at /usr/bin/php), create a symlink or simply change the first line of the file. In order for mpsync to act as a server, PHP must be compiled with --enable-sockets. Mpsync was developed with PHP5, but should work on PHP4 as long as the socket extension is present.

Download: http://labs.quadpoint.org/mpsync

Brief guide to using mpsync

1) Set up the server on 0.0.0.0:9011 (default) and play movie.avi. Assume the server is located at mpsync.domain.com.

mpsync -s -f "movie.avi"

2) Set up clients to connect to master. Assume the client is connecting from user.anotherdomain.com (10.0.4.5).

mpsync -c mpsync.domain.com -f "movie.avi"

On the server:

*** 10.0.4.5 connected

On the client:

Master position: 8.4, delta: 7.9
Master position: 9.8, delta: -4.3
Master position: 12.0, delta: -2.7
Master position: 14.0, delta: -0.6
Master position: 16.0, delta: -2.5
Master position: 18.0, delta: -0.5
Master position: 20.0, delta: -0.1
Master position: 21.9, delta: 0

Tips

1) If you would rather use gmplayer, the mplayer GUI, or if mplayer is not located in the path, use the -m switch:

mpsync -s -m "/usr/bin/gmplayer" -f "movie.avi"

2) You can include other mplayer options (such as those to change/fix the aspect, or go fullscreen) by adding them in with the -f switch:

mpsync -s -f "-fs -aspect 4:3 movie.avi"