[MPlayer-dev-eng] running a program with a keystroke - passing playing filename to it

Elias Gabriel Amaral da Silva tolkiendili at gmail.com
Sun Dec 19 12:33:55 CET 2010


2010/12/17 Reimar Döffinger <Reimar.Doeffinger at gmx.de>:
> On Fri, Dec 17, 2010 at 12:44:22PM -0300, Elias Gabriel Amaral da Silva wrote:
>> I think mplayer could define some variables for the execing
>> proccess. Like MPLAYER_FILENAME, MPLAYER_POS.. I am about to
>> implement it (unless there is another way to do what I
>> want). Does this seem reasonable?
>
> If it was just one thing it might be reasonable, but it
> sounds like your program might want all kinds of information.

I use mplayer at command line to handle audio or video file. I don't
actually want to use a front-end. It's my music player (it has an
equalizer, with find I can have shuffled regex-based playlists..), and
so on. My use cases:

a) mplayer as an editor

sometimes I'm hearing a music that I would like to cut. Maybe I want
to discard a piece, maybe I want to split in 2 or more pieces (I don't
need to rewrite the file mplayer is playing, I'm satisfied to write
new files and eventually unlinking the original one). I am too lazy to
open an actual editor, so I just forget, and next time this file pops
up, it will bother me again (a GUI editor such like audacity would be
inconvenient. I would need to find the offset. And to find I need to
hear it again..).

I just wanted to press a key to "mark" a point and press another to
"cut" the file in two files (or three, etc. if I had more marks). I
can move back with arrows and pause for better accuracy. this would be
really convenient. mplayer has no business in doing that, but I
figured that it could run arbitrary external commands. If only it
could pass filename, current point in seconds, and maybe the total
length..

b) mplayer as an tagger / rater / organizer

sometimes I separate files in categories. sometimes I view a file that
is in the wrong category. I usually have few categories, so I could
press a key A to signal that it should be in category A. this time I
don't need to see the position.

also, I might want to rate files as good / junk (I might then run a gc
script to discard junk, etc). etc

> You should probably just use slave mode, though the issue is
> that replies will be sent to stdout which will be hard to access
> from a child process.
> Still, since I don't know the purpose I can't say, but I think there's
> a good chance you should implement this as a slave-mode wrapper
> instead.

I didn't know about slave mode. Compn suggested it at #mplayerdev. It
is nice. With rlwrap it seems a nice command prompt.

I don't know how to build a layer on top slave that is like regular
mplayer, but with this added feature.. (maybe that libplayer would
help with this?)

> However being able to use arbitrary properties in commands might
> be a useful feature.

I implemented it, just for filename. (After a lot of time figuring out
where to change.. and understanding how to get the filename.. it ended
up being quite simple, but I still don't know where this filename
variable is defined)

I am not sure if I can use the variable filename directly, and not,
say, mp_property_path or some other wrapper. I think that
mp_property_path gets used only while expanding ${filename} somewhere.
I'm puzzled, I think I've never edited a file with 3.5k+ lines..

I see that filename might be null (it is checked for null at
mp_property_filename. But not at mp_property_path - maybe
m_property_string_ro checks for it?), so I checked it for null.

I see that mp_property_stream_time_pos and mp_property_length is used
for returning current / total time. But it expects an.. option? I
think I need to call mp_property_do to get it. Or something like that.
It gets called across that function multiple times, why isn't it
defined on top of the function?

I think that after getting this option I would call

mp_property_length(option, M_PROPERTY_GET, str, mpctx);
setenv("MPLAYER_LEN", str);

But not entirely sure, will try later.

Index: DOCS/tech/slave.txt
===================================================================
--- DOCS/tech/slave.txt	(revision 32718)
+++ DOCS/tech/slave.txt	(working copy)
@@ -508,7 +508,9 @@
     Run <value> as shell command. In OSD menu console mode stdout and stdin
     are through the video output driver.

+    It sets the variable MPLAYER_FILENAME to the current playing filename.

+
 Available properties:

 name               type      min     max     get set step comment
Index: command.c
===================================================================
--- command.c	(revision 32718)
+++ command.c	(working copy)
@@ -3375,7 +3375,10 @@
         case MP_CMD_RUN:
 #ifndef __MINGW32__
             if (!fork()) {
+                setenv("MPLAYER_FILENAME",
+                       filename != NULL ? filename : "", 1);
                 execl("/bin/sh", "sh", "-c", cmd->args[0].v.s, NULL);
+
                 exit(0);
             }
 #endif


More information about the MPlayer-dev-eng mailing list