This is an old revision of the document!
The normal text output of ffprobe
goes to stderr, so you usually need to add 2>&1
to parse the output. The alternative is to use the complex ffprobe options to format the output which then goes to stdout.
ffprobe "$in" 2>&1 | perl -nle '/^\s+Stream #(\d+:\d+): Audio/ && print $1'
with codec and number of channels:
ffprobe "$in" 2>&1 | perl -nle '/^\s+Stream #(\d+:\d+): Audio: (\S+).*(\d+)\s+channels/ && print join("\t", $1, $2, $3)'
or to have the tracks in a Bash array:
audio_tracks=( $(ffprobe "$in" 2>&1 | perl -nle '/^\s+Stream #(\d+:\d+): Audio/ && print $1') )
or the "official" way:
ffprobe -select_streams a -show_entries stream=index -of csv=p=0 "$in" ffprobe -select_streams a -show_entries stream=index,codec_name,channels -of csv=p=0 "$in" audio_tracks=( $(ffprobe -select_streams a -show_entries stream=index -of csv=p=0 "$in") )
For example to detect silent tracks/channels
ffmpeg -i "$in" -map 0:a -af "astats=measure_overall=none:measure_perchannel=Max_level" -f null - ffmpeg -i "$in" -map 0:a -af "astats=measure_overall=none:measure_perchannel=Max_level" -f null - 2>&1 | grep -E '(Channel|Max level):'
Or with volumedetect
, but it mixes all channels into a single value
ffmpeg -i "$in" -map 0:a -af "volumedetect" -f null - 2>&1 | grep max_volume
ffmpeg -i "$in" -vn -sn -dn -map 0:a -af "astats=measure_overall=none:measure_perchannel=Max_level" -f null - 2>&1 \ | perl -nle 'if ( ($id, $var, $val)=/^\[Parsed_astats_0 \@ 0x([\da-f]+)] (Channel|Max level): (\d+)/ ) { \ $c++ if ($id ne $h{$c}{id}); $h{$c}{id}=$id; $h{$c}{$var}=$val; } \ END { foreach $t (sort {$a<=>$b} keys %h) { \ print qq|Track $t ($h{$t}{id}) : ch $h{$t}{Channel} = $h{$t}{"Max level"}|} }'
for track in $(ffprobe -v error -select_streams a -show_entries stream=index -of csv=p=0 "$in"); do \ ffmpeg -i "$in" -vn -map 0:$track -c:a copy -f md5 - 2>/dev/null \ | while read md5; do \ printf "%32s Audio Track %2d %s\n" $md5 $track "$in"; \ done; \ done
ffprobe -v error -show_entries stream=index,codec_name:stream_tags=timecode -of csv=p=0 "$in"
Print sections structure and section information, and exit. The output is not meant to be parsed by a machine.
Show a hash of payload data, for packets with -show_packets and for codec extradata with -show_streams.