Version 3 of Watching a remotely stored video

Updated 2004-07-05 08:22:12 by TV

by Theo Verelst

Maybe a bit of a specialistic page, but fun.

I tried using tcl to set up a connection to a remote machine, over a simple ethernet connection, where a video file would be transfered with two short tcl scripts.

The one machine, with the video file on it, would run this script:

 set ss [socket -server servvid 1234]

 proc servvid {s i p} {
   global argv
   puts "connection from $i"
   flush stdout
 #   set f [open h:/dinsd2b.wmv r]
   set f [open [lindex $argv 0] r]
   fconfigure $s -translation binary
   fconfigure $f -translation binary
   fileevent $s readable "puts \"read: \[gets $s\]\" ; flush stdout
      if \[eof $s\] { 
      close $s 
      close $f 
      puts {End of file.}} "
   after 2000
   fileevent $s writable "fcopy $f $s -size 1024
      if \[eof $s\] { 
      close $s 
      close $f 
      puts {End of file.}} "
 }

 vwait forever

called like this (I used cygwin):

 tclsh servvid.tcl i:/Videos/Thunderbold\ and\ Lightfoot.mpg

where the mpeg file is a large file (the example is about 7 Gigabytes), which is the reason it's not simply copied to the other machine. It may not have enough free disc space, and even over 100baseT it would take some time to copy.

On the other machine, I used another smal tcl script to take date from the above dedicated server script, and copies it to stdout:

 set s [socket 192.168.0.1 1234]
 fconfigure $s -translation binary
 fconfigure stdout -translation binary
 fileevent $s readable "puts -nonewline stdout \[read $s 1024\]; flush stdout"

 vwait forever

this script is called like this to pipe it's output to mplayer a linux/windows video player of good visual quality:

 tclsh socktostdout.tcl | mplayer -

With a from-tv recorded movie in (D1) DVD quality, on 'consumer' machines (not too slow) this works neat, except one cannot wind through the video, it starts and then runs, and can be paused (press p in mplayer) but always runs from the beginning.

Remarkably enough, with this 6Mb/s movie material, there are no glitches or hickups, display is nice and smooth.

File sharing of some kind would be possible as alternative, of course, instead of the socket connection, but the machine I used as server has an internet connection, and I don't want to take the risk of anything shared on it. The above script allows serving of only a specific file and nothing else, so can be considered safe, just like that I use pcom with local-only connections to start xterms.

See also: