-1

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.

Tina J
  • 4,983
  • 13
  • 59
  • 125
  • Replace `0:a:1` with `0:a:0` to analyze the first stream. – Gyan Feb 13 '19 at 05:16
  • Thanks. Is there any way to see only output of specific channel? say `Center`? I also don't know the layout, which # is which. – Tina J Feb 13 '19 at 16:25
  • 1
    ffmpeg's layout may not be [reliable](https://video.stackexchange.com/q/23140/1871) for MOV/MP4. In any case, something like channelsplit to isolate the channel, or grep the astats readout. – Gyan Feb 13 '19 at 16:48
  • @Gyan wondering why the result of your command is different from the answer. Your command doesn't say `-inf` for Channel #3. But the command in the answer says `FC` is silence. – Tina J Feb 14 '19 at 23:30
  • 2
    `-inf` is for perfect digital silence. Channel #3 has a few stray samples: `Min level: -0.000007 Max level: 0.000006`. silencedetect has a threshold and any volume below that threshold is registered as silence. `-90db` or lower is effectively digital silence. – Gyan Feb 15 '19 at 07:20
  • ummm I see. Maybe I can just take Ch#4 which shows as `RMS level dB: -inf` for empty (I assume this never will be -inf for full 7.1 contents). Or just get `<-100db` for ch#3. Are my assumptions valid? – Tina J Feb 15 '19 at 18:23
  • What exactly are you trying to determine? Audible silence, then -60 or lower. is sufficient. Perfect null-sampled track, then -inf. – Gyan Feb 15 '19 at 18:40
  • To detect full silence. I was expecting a digital silence on FC on my sample test, but looks like it is not digital. I think it is fine to consider it as digital. – Tina J Feb 15 '19 at 22:07

2 Answers2

4

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

aergistal
  • 29,947
  • 5
  • 70
  • 92
  • What I got was this: `[silencedetect @ 0000024c44b02700] silence_start: 0 frame= 1891 fps=0.0 q=-0.0 Lsize=N/A time=00:01:03.10 bitrate=N/A speed=73.8x video:990kB audio:5916kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: unknown [silencedetect @ 0000024c44b02700] silence_end: 63.104 | silence_duration: 63.104`. So what does it mean? – Tina J Feb 13 '19 at 16:09
  • You got 63.104s of silence – aergistal Feb 13 '19 at 19:20
  • I need to know if it is fully silence. Any ways? (like my command in question, a metadata says `-inf` which is what I look for) – Tina J Feb 13 '19 at 19:48
  • 1
    Compare `silence_duration` with the duration of the audio stream? – aergistal Feb 13 '19 at 20:35
  • Yeah..that can be a dirty solution. Is that `time=00:01:03.10` the total stream duration? – Tina J Feb 13 '19 at 22:21
  • Btw, FC is the center channel. Right? How to know which channel # it is? – Tina J Feb 13 '19 at 22:22
  • wondering why the result of your command is different from one in my question. Ch#3 in `ffmpeg -i file -map 0:a:0 -af astats -f null -` doesn't say silent. But your command says FC is silent. Can you verify please? – Tina J Feb 14 '19 at 23:31
  • 2
    *Compare silence_duration with the duration of the audio stream* --> astats obviates that by allowing to accumulating statistics over the whole stream. Of course, there's also volumedetect. – Gyan Feb 15 '19 at 06:33
1

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
mivk
  • 13,452
  • 5
  • 76
  • 69