You are not logged in.
Hi,
I'm hoping to do something with dzen to build a status bar for mplayer. Initially it will be very similar to mplayer's OSD, but in a bar above the video, not over the top of the video.
When you run mplayer you get output in the terminal like this (I'm just interested/showing the last few lines):
VO: [xv] 540x432 => 576x432 Planar YV12
A: 3.6 V: 3.6 A-V: 0.000 ct: 0.040 0/ 0 6% 1% 0.3% 0 0 The second line constantly updates as the audio/video plays, and it's what I'm interested in.
If you pipe it you will not see that second line, why is that? If you pipe it through grep or awk for example, you will not see that line while mplayer is running; you might do at the end, but it's no use then.
Can someone explain why this line does not get piped?
Thanks
PGP key: F40D2072
Key fingerprint: 8742 F753 5E7B 394A 1B04 8163 332C 9C40 F40D 2072
Offline
That's most likely because the tools you are piping to (you give awk and grep as examples) read line by line. Mplayer does not output a newline character, so the line is never "complete" until mplayer exits. Awk, grep, or any script with a "read line" command will block until mplayer appends the newline and exits.
You can write such a tool though - just don't wait for a newline. Mplayer can be piped through the following "repeater" that does absolutely nothing useful, but it does read and echo each character:
#include <stdio.h>
int main() {
int c;
while (c=getchar()) putchar(c);
return 0;
}You can expand on this to do something with those characters. Alternately, you could even make a non-endline piping tool that would check if 'c' was equal to the terminal code to move back to the start of the line and replace that with a '\n'. This would allow you to use this ~10 line C program as an interpreter while doing everything else with grep, or awk, or any bash script.
I would not be surprised if mplayer also has an option to output in such a format, but I don't know it off hand.
EDIT: the following works as a translator. Pipe through this to your preferred tool or script:
#include <stdio.h>
int main() {
int c;
int p1=0,p2=0;
while ( (c=getchar()) !=EOF ) {
putchar(c);
if (c == 'J' && p1 == '[' && p2 == 27) {
putchar('\n');
fflush(stdout);
}
p2 = p1; p1 = c;
}
return 0;
}Last edited by Trilby (2012-11-07 15:27:33)
"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman
Offline
I see, thanks for explanation and examples! That works well in the terminal or if I pipe it to dzen, but if I try and put something like awk '{print $2}' in there it looks fine in the terminal, but dzen is blank.
PGP key: F40D2072
Key fingerprint: 8742 F753 5E7B 394A 1B04 8163 332C 9C40 F40D 2072
Offline