I learn something new everyday!


*Short but sweet this time!*

When I want more specificity than what ‘ffmpeg -i’ (-i for input) alone can offer,
then I’d use something along the lines of:

ffmpeg -i my-movie.mkv 2>&1 | cat - | grep -in 'stream'
## 2>&1 send stderr to stdout and pipe '|' this to cat on its stdin '-'
## (as for grep: -i for case insensitive and -n for numbered lines)
## Or when I use my aliases:
sniff my-movie.mkv 2>&1 | cat - | grepin 'stream'

This could result in something like (with the word/string ‘stream’ highlighted in my search term.):

17:Seems stream 0 codec frame rate differs from container frame rate: 180000.00 (180000/1) -> 100.00 (100/1)
22:    Stream #0.0(eng): Video: h264, yuv420p, 1920x1080 [PAR 1:1 DAR 16:9], 25 fps, 100 tbr, 1k tbn, 180k tbc
23:    Stream #0.1: Audio: ac3, 48000 Hz, stereo, s16, 128 kb/s

Instead of ‘ffmpeg’ passing its entire error output to my screen. 😉

## Now if I were to have a list of 'codecs' to parse through then the following line.
## Could be used to verify what we're about to work on really is what it says it is.
EXT=$(sniff "${DIR}" 2>&1 | cat - | grepi "video: "${codec}"" | awk '{print $4}') && echo "${EXT%,}"
## ^^ Future script!?
## This would as used in the example above,
## only print the string 'h264' to my screen.
Where:
DIR=red.dress.hires.mkv
Do:
ffmpeg -i $DIR
ffmpeg -i $DIR 2>&1 | cat - | grep -in 'stream'
EXT=$(ffmpeg -i "${DIR}" 2>&1 | cat - | grep -i "video: "${codec}"" | awk '{print $4}') && echo "${EXT%,}"

See the gallery.

Useful links:
http://tldp.org/LDP/Bash-Beginners-Guide/html/index.html
http://tldp.org/LDP/abs/html/

## From my ~/.bash_aliases file.
## A set of rather helpful aliases, if I say so myself.
# enable color support of ls and also add handy aliases
if [ "$TERM" != "dumb" ] && [ -x /usr/bin/dircolors ]; then
    eval "`dircolors -b`"
    alias l='ls --color=auto'
    alias l.='ls -d  --color=auto .*'
    alias la='ls -a --color=auto'
    alias ll='ls -l --color=auto'
    alias ld='ls -d --color=auto */'
    alias lh='ls -lh --color=auto'
    alias lx='ls -X --color=auto'
    alias lha='ls -lha --color=auto'
    alias list='ls -lhtFG --group-directories-first --color=auto'
    alias rlist='ls -lrhtFG --group-directories-first --color=auto'
    alias dir='dir --color=auto -clth'
    alias grep='grep --color=auto'
    alias grepi='grep -i --color=auto'
    alias grepin='grep -in --color=auto'        
    alias fgrep='fgrep --color=auto'
    alias egrep='egrep --color=auto'
fi