Bash: save ffmpeg output to a variable

6

How can i save ffmpeg file-info output to a variable? if i put the following command into variable it's always empty, even though the command generates an output /usr/bin/ffmpeg/ffmpeg -i $1

what i've tried

INFO=$(/usr/bin/ffmpeg/ffmpeg -i $1)

if [ -z "$INFO" ]; then
        echo "empty variable"
else
        echo "$INFO"
fi

teslasimus

Posted 2013-01-21T10:27:13.930

Reputation: 443

what issue you are facing? – Guru – 2013-01-21T10:30:19.473

the variable is empty. – teslasimus – 2013-01-21T10:35:37.847

without saving into variable, can you try running the command directly within the script to make sure output is generated? – Guru – 2013-01-21T10:40:05.817

Answers

5

Try saving both STDERR and STDOUT. The following command will redirect standard error to standard output:

INFO=$(/usr/bin/ffmpeg/ffmpeg -i $1 2>&1)

By default, ffmpeg puts all its text output to STDERR, leaving STDOUT free for piping video/audio data to other applications.

Guru

Posted 2013-01-21T10:27:13.930

Reputation: 951