5

I'm trying to filter the output of the mpv media player, removing a particular line, but when I do so I am unable to control mpv with the keyboard. Here is the command:

mpv FILE | grep -v 'Error while decoding frame'

When I run the command, everything displays correctly, but I am unable to use the LEFT and RIGHT keys to scan through the file, or do anything else with the keyboard. How do I filter the output of the program while retaining control of it?

  • 1
    Are you sure mpv reads the keyboard if it detects it output is redirected to file? I.e if you do mpv FILE > somefile.out can you control it with the cursor? – Anthon Jun 30 '15 at 4:55
  • @Anthon Oops, it doesn't, so would that imply that the place to look is mpv's settings? – jaxuru Jun 30 '15 at 5:03
  • 1
    Maybe there is some commandline switch for mpv. Quite a lot of programs actually detect if their output goes to a file (e.g. try man | grep -F a and you will not be able to scroll back and forth). – Anthon Jun 30 '15 at 5:07
  • @Anthon there's a --input-terminal option but no dice, controls still changed, I think this is a dead end. Thanks for the help, though. – jaxuru Jun 30 '15 at 5:58
5

You can give mpv a fake terminal by using the script(1) program, for instance:

script -c 'mpv FILE' /dev/null | grep -v 'Error while decoding frame'

For Mac OS X, the syntax seems to be:

script /dev/null mpv 'FILE' | grep -v 'Error while decoding frame'

[edit: also check out Trick an application into thinking its stdin is interactive for additional solutions]

|improve this answer|||||
  • When I try to use script, it doesn't allow a -c option... and there's no --version option to try to see if its a version issue either. I'm running Mac OS Yosemite. – jaxuru Jun 30 '15 at 5:28
  • 1
    Yep, it's different; I added their syntax from the man page – remram Jun 30 '15 at 14:59
0

You can use nohup mpv FILE. The output is written to nohup.out which you can filter using tail and grep:

nohup mpv FILE
tail -f nohup.out |grep -v 'Error while decoding frame'
|improve this answer|||||
  • Tail just hangs waiting for text, even though mpv might have stopped producing output. If this is scripted, how do you detect EOF and exit? – PLG Mar 10 at 18:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.