How to output avconv with pipe

6,331

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:
6,331

Related videos on Youtube

Luis Alvarado
Author by

Luis Alvarado

System Engineer Social Engineer Master in Pedagogy Master in Open Source CCNA Certified Linux Foundation Certified Former Askubuntu Moderator Stack Careers | Linkedin | Launchpad | Ubuntu Wiki - Random SE Stuff - Latin American Members | JC Race Award | Human Robot Award 74

Updated on September 18, 2022

Comments

  • Luis Alvarado
    Luis Alvarado over 1 year

    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

    • Admin
      Admin over 11 years
      Try using single or double quotes around SOMETHING.
  • Luis Alvarado
    Luis Alvarado over 11 years
    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?
  • hytromo
    hytromo over 11 years
    please see my edited answer.
  • Luis Alvarado
    Luis Alvarado over 11 years
    Got it thanks. Did not notice that both outputs were there.
  • Nate C-K
    Nate C-K about 5 years
    I think the reason avconv writes info to stderr is because it supports writing the output file to stdout. Thus, stdout needs to be reserved for file data.
  • Pablo Bianchi
    Pablo Bianchi about 5 years
    You can use |& instead of 2>&1 |. Seems more easy to remember.