[MPlayer-users] is it possible to play and to dump stream simultaneously ?

Nicolas George nicolas.george at normalesup.org
Sun Nov 30 19:02:04 CET 2008


Le decadi 10 frimaire, an CCXVII, The Wanderer a écrit :
> Some explicit way to say "output to stdout" would allow us to redirect
> the normal output text to stderr rather than having to turn it off,
> which could be helpful or at least nice...

It is already possible to do all this from the calling shell, provided the
operating system supports the /dev/fd/X feature (and the standard output is
not connected to a socket):

mplayer ... -dumpfile /dev/fd/3 ... 3>&1 1>&2

With this command, when mplayer is started, its fd 1 and 2 are connected to
the calling process' standard error, and its fd 3 is connected to the
calling process' standard output. Thus, the dump will go to the calling
process' standard output while all messages will go to standard error.

It would be quite easy to implement such a hack inside of mplayer, with
something like that:

static int real_stdout = -1;

int
open_output_file(const char *filename)
{
    if(strcmp(filename, "-") == 0) {
	if(real_stdout < 0) {
	    real_stdout = dup(1);
	    dup2(2, 1);
	    return real_stdout;
	} else {
	    return dup(real_stdout);
	}
    } else {
	return open(filename, O_WRONLY);
    }
}

(add error checks, of course)

The advantage of this method is that it is resistant even to crappy external
libraries that can not be prevented from writing to standard output.

Regards,

-- 
  Nicolas George
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 197 bytes
Desc: Digital signature
URL: <http://lists.mplayerhq.hu/pipermail/mplayer-users/attachments/20081130/516fbfca/attachment.pgp>


More information about the MPlayer-users mailing list