This is a follow-up question from my previous question asked here, where I needed to look for silence within a specific audio track. Here is the ffmpeg
life-saver solution where helps to get some metadata:
ffmpeg -i file -map 0:a:1 -af astats -f null -
But I have other type of input .mp4
files where they have one single track of 8
(i.e. 7.1) audio channels. Apparently these files are transcoded from an original file (somehow the 4 track stereos are squished into these files). Now similar to my previous, I need to know if the original file was 2-channel stereo or 5.1 (6) channel.
How to know if a specific channel of an audio track (say Center
channel) is silent/mute, possibly using ffmpeg
? Here is a sample .mp4
file.
You can use the channelsplit filter to split the audio channels and run silencedetect on each.
Example:
ffmpeg -i test2.mp4 -filter_complex "[0:a]channelsplit=channel_layout=7.1:channels=FC[fc];[fc]silencedetect" -f null /dev/null
You can find more on audio channel manipulation here: https://trac.ffmpeg.org/wiki/AudioChannelManipulation
There is also the astats filter which can be used to detect silent tracks/channels.
This i what it outputs for the channel 4 of the suggest test file, which appears indeed to be perfectly silent.
ffmpeg -i "$in" -vn -sn -dn -map 0:a -af "astats=measure_overall=none" -f null -
... [Parsed_astats_0 @ 0x6beed00] Channel: 4 [Parsed_astats_0 @ 0x6beed00] DC offset: 0.000000 [Parsed_astats_0 @ 0x6beed00] Min level: 0.000000 [Parsed_astats_0 @ 0x6beed00] Max level: 0.000000 [Parsed_astats_0 @ 0x6beed00] Min difference: 0.000000 [Parsed_astats_0 @ 0x6beed00] Max difference: 0.000000 [Parsed_astats_0 @ 0x6beed00] Mean difference: 0.000000 [Parsed_astats_0 @ 0x6beed00] RMS difference: 0.000000 [Parsed_astats_0 @ 0x6beed00] Peak level dB: -inf [Parsed_astats_0 @ 0x6beed00] RMS level dB: -inf [Parsed_astats_0 @ 0x6beed00] RMS peak dB: -inf [Parsed_astats_0 @ 0x6beed00] RMS trough dB: -inf [Parsed_astats_0 @ 0x6beed00] Crest factor: 1.000000 [Parsed_astats_0 @ 0x6beed00] Flat factor: -inf [Parsed_astats_0 @ 0x6beed00] Peak count: 6057984 [Parsed_astats_0 @ 0x6beed00] Bit depth: 0/0 [Parsed_astats_0 @ 0x6beed00] Dynamic range: -inf [Parsed_astats_0 @ 0x6beed00] Zero crossings: 0 [Parsed_astats_0 @ 0x6beed00] Zero crossings rate: 0.000000 [Parsed_astats_0 @ 0x6beed00] Number of NaNs: 0 [Parsed_astats_0 @ 0x6beed00] Number of Infs: 0 [Parsed_astats_0 @ 0x6beed00] Number of denormals: 0 [Parsed_astats_0 @ 0x6beed00] Channel: 5 ...
Something like this would show an overview of all channels:
ffmpeg -i "$in" -vn -sn -dn -map 0:a -af "astats=measure_overall=none" -f null - 2>&1 \
| egrep 'Channel|(Max|Peak) level'
[Parsed_astats_0 @ 0x7567d00] Channel: 1 [Parsed_astats_0 @ 0x7567d00] Max level: 0.978271 [Parsed_astats_0 @ 0x7567d00] Peak level dB: -0.190818 [Parsed_astats_0 @ 0x7567d00] Channel: 2 [Parsed_astats_0 @ 0x7567d00] Max level: 0.978271 [Parsed_astats_0 @ 0x7567d00] Peak level dB: -0.190818 [Parsed_astats_0 @ 0x7567d00] Channel: 3 [Parsed_astats_0 @ 0x7567d00] Max level: 0.000006 [Parsed_astats_0 @ 0x7567d00] Peak level dB: -103.162709 [Parsed_astats_0 @ 0x7567d00] Channel: 4 [Parsed_astats_0 @ 0x7567d00] Max level: 0.000000 [Parsed_astats_0 @ 0x7567d00] Peak level dB: -inf [Parsed_astats_0 @ 0x7567d00] Channel: 5 [Parsed_astats_0 @ 0x7567d00] Max level: 0.000006 [Parsed_astats_0 @ 0x7567d00] Peak level dB: -103.162709 [Parsed_astats_0 @ 0x7567d00] Channel: 6 [Parsed_astats_0 @ 0x7567d00] Max level: 0.000006 [Parsed_astats_0 @ 0x7567d00] Peak level dB: -103.162709 [Parsed_astats_0 @ 0x7567d00] Channel: 7 [Parsed_astats_0 @ 0x7567d00] Max level: 0.978271 [Parsed_astats_0 @ 0x7567d00] Peak level dB: -0.190818 [Parsed_astats_0 @ 0x7567d00] Channel: 8 [Parsed_astats_0 @ 0x7567d00] Max level: 0.978271 [Parsed_astats_0 @ 0x7567d00] Peak level dB: -0.190818
来源:https://stackoverflow.com/questions/54662733/ffmpeg-check-channels-of-a-7-1-audio-for-silence