0

I'm writing a bash script to make DVD authoring more automated (but, mainly, so that I can learn some more bash scripting) and I'm trying to find out if it's possible to control how an exterrnal command presents its output.

For instance, the output from ffmpeg is a load of (to me) irrelevant cruft about options, libraries, streams, progress and so on.

What I really want is to be able to select for display only the lines with the input and output filenames and then to display the progress on the same line each time. Similarly for mkisofs and wodim.

I've tried Googling for this and am beginning to suspect that either it's not possible or nobody's thought of it before (or, possibly, that it's so obvious that nobody thinks it necessary to say how :-) ).

Many thanks, in advance,

David Shaw

5
  • 2
    Could you provide some examples of what the output looks like now and what you would like it to look like? Commented Mar 26, 2014 at 15:58
  • 1
    It is very possible. Try using sed, awk, or grep: bash script.sh | grep <regex> Commented Mar 26, 2014 at 16:18
  • Have you tried changing the ffmpeg -loglevel? The default is "info - Show informative messages during processing. This is in addition to warnings and errors.". You can turn it all the way down to "quiet - Show nothing at all; be silent." Commented Mar 26, 2014 at 16:19
  • I don't think you can control how an external command presents its output without modifying the external command... However, you can capture or filter its output, modify it, and produce the modified output within your program... Commented Mar 26, 2014 at 16:21
  • For handling process output I would use python. It might make sense to write a python script that spawns ffmpeg and processes its output. You can use bash for rest of the logic. The python script will be just a wrapper around ffmpeg sensoring its output. Commented Mar 26, 2014 at 16:22

1 Answer 1

2

You want to use grep and pipes. They are your friends. You want to pipe the output of the ffmpeg into grep and have it output only lines containing the text you want.

Assuming you have the input and output file names as command lines arguments $1 and $2 to your shell script, you might try something like

ffmpeg .... | grep "$1\|$2"
            ^          ^
            |          +--  escape and OR character
            +--pipe character

The '\|' is an escape and an OR character for regular expressions. The OR '|' is also the pipe character so you have to escape that.

This will output only output lines that contain the files you are looking for.

This assumes all output is via stdout. If ffmpeg is outputting text via stderr then you will need to add some redirects at the end of ffmpeg line to redirect those back to stdout.

EDIT: I used the wrong quotes in the first example. Use double quotes or it won't expand the parameters $1 and $2

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.