Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I am trying to pipe an output from avconv to grep but somehow the pipe is not working correctly. The following ways are not working:

avconv -i MOVIE.mkv | grep SOMETHING - Which should show only the lines from the avconv that have SOMETHING in them.

avconv -i MOVIE.mkv pipe: | grep SOMETHING - Which should show only the lines from the avconv that have SOMETHING in them.

avconv -i MOVIE.mkv pipe:1 | grep SOMETHING - Which should show only the lines from the avconv that have SOMETHING in them.

How can I output the information from avconv to pipe?

Why is it not working?

Piping something like this works, but not the -i information parameter: avconv -codecs | grep "264"

Tested on 12.04 and 12.10

share|improve this question
    
Try using single or double quotes around SOMETHING. –  hexafraction Sep 18 '12 at 23:25
    
Actually the output with single quotes, double quotes or without quotes is the same. This are only used when what we are looking for has a space or a symbol not friendly with the naming conventions. Like the space and other symbols that need the quotes to tell grep to look for that specific value. –  Luis Alvarado Sep 18 '12 at 23:28
add comment

1 Answer

up vote 4 down vote accepted

I am one of the developers of Format Junkie, so I kind of know how avconv works, and I assure you that it sends all the important data to stderr. So, you need to grep from stderr. Actually, you redirect all the stderr to stdout and then grep:

For example:

avconv -i 111.avi 2>&1 | grep Duration

correctly outputs:

  Duration: 00:01:05.02, start: 0.000000, bitrate: 2910 kb/s

The reason why the grep works only in some of avconv's output is that this specific output is being given to stdout, not to stderr, and so it is successfully piped to grep.

Normally stderr is used so as to output error messages and stdout so as to output normal informative messages.

It is not bad that both stderr and stdout exist, because you can filter the output the way you want. For example, consider the following:

command > log.txt 2> error_log.txt

This will output all the normal output (stdout) to log.txt and all errors (stderr) to error_log.txt

I don't know why avconv specifically uses stderr to display its messages, though.

share|improve this answer
    
Awesome thanks hakermania. Just a suggestion but wouldn't it be better if all outputs were the same way, to stdout, like first parsed before outputting the info. Or is there a reason why in some cases it is stderr? –  Luis Alvarado Sep 19 '12 at 0:21
1  
please see my edited answer. –  hakermania Sep 19 '12 at 0:23
    
Got it thanks. Did not notice that both outputs were there. –  Luis Alvarado Sep 19 '12 at 0:28
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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