Trying to mute all 5.1 channels of audio for a period of time within a video

Questions involving a Windows version of FFmpeg.
carlojoe
Posts: 8
Joined: Wed Oct 30, 2019 8:09 pm

Trying to mute all 5.1 channels of audio for a period of time within a video

Post by carlojoe » Wed Oct 30, 2019 8:14 pm

I'm wanting to mute audio for a portion of a video clip while keeping the video exactly as it is.
I came across this online.

ffmpeg -i ~/Downloads/in.mov -vcodec copy -af "volume=enable='between(t,0,3)':volume=0" ~/Downloads/out2.mov

Although it works, it converts the 5.1 audio to stereo. Isn't it possible to mute the first 3 seconds of all 5.1 channels of audio, while keeping the 5.1 channels intact within the finished output video file?


Here's the specs on my video/audio clip:

Stream #0:0[0x100]: Video: h264 (High) ([27][0][0][0] / 0x001B), yuv420p(progressive), 1280x720 [SAR 1:1 DAR 16:9], Closed Captions, 59.94 fps, 59.94 tbr, 90k tbn, 119.88 tbc
Stream #0:1[0x101]: Audio: ac3 ([129][0][0][0] / 0x0081), 48000 Hz, stereo, fltp, 192 kb/s
Stream #0:2[0x102]: Audio: ac3 ([129][0][0][0] / 0x0081), 48000 Hz, 5.1(side), fltp, 384 kb/s

Thank you.

pandy
Posts: 255
Joined: Mon Feb 24, 2014 1:46 pm

Re: Trying to mute all 5.1 channels of audio for a period of time within a video

Post by pandy » Thu Oct 31, 2019 6:28 pm

Try to extend your filter (signal) path by explicitly use 5.1 channel layout at the input, adjust level, output 5.1 channel layout and most important use audio codec capable to support 5.1 channel layout - quite important - you not use audio codec just relay on default settings used by ffmpeg for MOV container, audio codec selected by default may not support 5.1 channel layout thus ffmpeg automatically invoke conversion from 5.1 to stereo.

carlojoe
Posts: 8
Joined: Wed Oct 30, 2019 8:09 pm

Re: Trying to mute all 5.1 channels of audio for a period of time within a video

Post by carlojoe » Thu Oct 31, 2019 6:48 pm

Thanks pandy. I really appreciate the reply. I'm still a bit new to ffmpeg and find its deep syntax a bit complicated. Any chance you would put what you said into a command line example?

Thank you again.

pandy
Posts: 255
Joined: Mon Feb 24, 2014 1:46 pm

Re: Trying to mute all 5.1 channels of audio for a period of time within a video

Post by pandy » Fri Nov 01, 2019 9:26 am

Code: Select all

@set filename=%1
@ffmpeg.exe -report -hide_banner -v 32 -stats -y -i "%filename%" -map 0:v:0 -c:v:0 copy -map 0:a:0 -c:a:0 copy -map 0:a:1? -c:a:1 ac3 -b:a:1 512k -filter:a:1 aformat=channel_layouts=0x60f,volume=enable='between(t,0,3)':volume=0,aresample=resampler=soxr:osr=48000:cutoff=0.990:dither_method=none,aformat=channel_layouts=0x60f "%~n1_ac3.mkv"
I tested this script with two sources, one that have single video and single audio and second with single video and multiple audio tracks. In both cases script works (seem to be OK) however for single audio track you may get warning that there is no second audio track and as such option related are ignored.

Audio resampling filter is optional but i use it as it allow to deal with sample rates not supported by AC-3 (mostly newer, high end audio codecs - in my case Dolby Spheres Demo stream where audio track was 96kHz 7.1 - Dolby TrueHD) - if you don't need it then you can safely remove it, also forcing particular channel layout especially at the input of filter may be not required - i think it can be safely removed too - as i've wrote earlier - have impression that you didn't specified correctly stream mapping and i agree that ffmpeg syntax is not so obvious - this script cost me like an hour of testing and reading documentation but i'm not a programmer thus my scripting skill are quite poor.

carlojoe
Posts: 8
Joined: Wed Oct 30, 2019 8:09 pm

Re: Trying to mute all 5.1 channels of audio for a period of time within a video

Post by carlojoe » Fri Nov 01, 2019 4:33 pm

First, thank you so much for responding pandy! I can tell you're very knowledgeable and share your ffmpeg skills to help many others within this forum (and even other forums where I've seen your name come up).

I ran your code. Although it generated a file with 5.1 channel audio in place, it didn't mute the selected portion (i.e. 0-3 seconds). Below is the executed command and the results. I had to slightly adapt what you provided since I'm running ffmpeg (version 4.2.1) on a mac. Can you figure out why the audio is not muting?

Code: Select all

ffmpeg -report -hide_banner -v 32 -stats -y -i  ~/audio_mute_test.ts -map 0:v:0 -c:v:0 copy -map 0:a:0 -c:a:0 copy -map 0:a:1? -c:a:1 ac3 -b:a:1 512k -filter:a:1 aformat=channel_layouts=0x60f,volume=enable='between(t,0,3)':volume=0,aresample=resampler=soxr:osr=48000:cutoff=0.990:dither_method=none,aformat=channel_layouts=0x60f ~/finished_edits/audio_mute_test.ts

ffmpeg started on 2019-11-01 at 10:00:34
Report written to "ffmpeg-20191101-100034.log"
[h264 @ 0x7f8bda80ae00] Increasing reorder buffer to 2
[h264 @ 0x7f8bda80ae00] Increasing reorder buffer to 3
Input #0, mpegts, from '~/audio_mute_test.ts':
  Duration: 00:20:43.79, start: 1.400000, bitrate: 3921 kb/s
  Program 1 
    Metadata:
      service_name    : Service01
      service_provider: FFmpeg
    Stream #0:0[0x100]: Video: h264 (High) ([27][0][0][0] / 0x001B), yuv420p(progressive), 1280x720 [SAR 1:1 DAR 16:9], Closed Captions, 59.94 fps, 59.94 tbr, 90k tbn, 119.88 tbc
    Stream #0:1[0x101](eng): Audio: ac3 ([129][0][0][0] / 0x0081), 48000 Hz, 5.1(side), fltp, 384 kb/s
Codec AVOption b (set bitrate (in bits/s)) specified for output file #0 (~/finished_edits/audio_mute_test.ts) has not been used for any stream. The most likely reason is either wrong type (e.g. a video option with no video streams) or that it is a private option of some encoder which was not actually used for any stream.
Output #0, mpegts, to '~/finished_edits/audio_mute_test.ts':
  Metadata:
    encoder         : Lavf58.29.100
    Stream #0:0: Video: h264 (High) ([27][0][0][0] / 0x001B), yuv420p(progressive), 1280x720 [SAR 1:1 DAR 16:9], q=2-31, 59.94 fps, 59.94 tbr, 90k tbn, 90k tbc
    Stream #0:1(eng): Audio: ac3 ([129][0][0][0] / 0x0081), 48000 Hz, 5.1(side), fltp, 384 kb/s
Stream mapping:
  Stream #0:0 -> #0:0 (copy)
  Stream #0:1 -> #0:1 (copy)
Press [q] to stop, [?] for help
frame=74436 fps=32442 q=-1.0 Lsize=  595441kB time=00:20:43.75 bitrate=3921.9kbits/s speed= 542x    
video:481636kB audio:57914kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 10.358646%

pandy
Posts: 255
Joined: Mon Feb 24, 2014 1:46 pm

Re: Trying to mute all 5.1 channels of audio for a period of time within a video

Post by pandy » Fri Nov 01, 2019 6:05 pm

carlojoe wrote:
Fri Nov 01, 2019 4:33 pm
First, thank you so much for responding pandy!

I ran your code. Although it generated a file with 5.1 channel audio in place, it didn't mute the selected portion (i.e. 0-3 seconds). Below is the executed command and the results. I had to slightly adapt what you provided since I'm running ffmpeg (version 4.2.1) on a mac. Can you figure out why the audio is not muting?
Glad if i can help, and answer is quite simple - because your source stream has only single audio track and you asked for script dealing with case where there are 2 audio tracks, first stereo and you need to copy it and second 5.1 where your intention is to modify level. My script don't touch first audio track.

carlojoe
Posts: 8
Joined: Wed Oct 30, 2019 8:09 pm

Re: Trying to mute all 5.1 channels of audio for a period of time within a video

Post by carlojoe » Fri Nov 01, 2019 11:34 pm

Sorry about not using the same source file. In truth, I'm wanting to mute both streams (5.1 and stereo). So using this as my input....

Code: Select all

    Stream #0:0[0x100]: Video: h264 (High) ([27][0][0][0] / 0x001B), yuv420p(progressive), 1280x720 [SAR 1:1 DAR 16:9], Closed Captions, 59.94 fps, 59.94 tbr, 90k tbn, 119.88 tbc
    Stream #0:1[0x101](eng): Audio: ac3 ([129][0][0][0] / 0x0081), 48000 Hz, 5.1(side), fltp, 384 kb/s
    Stream #0:2[0x102](spa): Audio: ac3 ([129][0][0][0] / 0x0081), 48000 Hz, stereo, fltp, 192 kb/s
I tried this....

Code: Select all

ffmpeg -report -hide_banner -v 32 -stats -y -i / ~/audio_mute_test.ts \
   -map 0:v:0 -c:v:0 copy \
   -map 0:a:0? -c:a:0 ac3 -b:a:1 512k -filter:a:0 aformat=channel_layouts=0x60f,volume=enable='between(t,0,3)':volume=0,aresample=resampler=soxr:osr=48000:cutoff=0.990:dither_method=none,aformat=channel_layouts=0x60f \
   -map 0:a:1? -c:a:1 ac3 -b:a:1 512k -filter:a:1 aformat=channel_layouts=0x60f,volume=enable='between(t,0,3)':volume=0,aresample=resampler=soxr:osr=48000:cutoff=0.990:dither_method=none,aformat=channel_layouts=0x60f ~/finished_edits/audio_mute_test.ts
but it didn't work. It gave me this....

Code: Select all

ffmpeg started on 2019-11-01 at 17:13:38
Report written to "ffmpeg-20191101-171338.log"
[h264 @ 0x7f9e5100a800] Increasing reorder buffer to 2
[h264 @ 0x7f9e5100a800] Increasing reorder buffer to 3
Input #0, mpegts, from '/Users/csandqui/Desktop/Master_TS_file/audio_mute_test.ts':
  Duration: 00:20:27.58, start: 1.410833, bitrate: 4139 kb/s
  Program 1 
    Metadata:
      service_name    : Service01
      service_provider: FFmpeg
    Stream #0:0[0x100]: Video: h264 (High) ([27][0][0][0] / 0x001B), yuv420p(progressive), 1280x720 [SAR 1:1 DAR 16:9], Closed Captions, 59.94 fps, 59.94 tbr, 90k tbn, 119.88 tbc
    Stream #0:1[0x101](eng): Audio: ac3 ([129][0][0][0] / 0x0081), 48000 Hz, 5.1(side), fltp, 384 kb/s
    Stream #0:2[0x102](spa): Audio: ac3 ([129][0][0][0] / 0x0081), 48000 Hz, stereo, fltp, 192 kb/s
Only '-vf (null)' read, ignoring remaining -vf options: Use ',' to separate filters
Only '-af aformat=channel_layouts=0x60f,volume=enable=between(t,0,3):volume=0,aresample=resampler=soxr:osr=48000:cutoff=0.990:dither_method=none,aformat=channel_layouts=0x60f' read, ignoring remaining -af options: Use ',' to separate filters
    Last message repeated 1 times
Stream mapping:
  Stream #0:0 -> #0:0 (copy)
  Stream #0:1 -> #0:1 (ac3 (native) -> ac3 (native))
  Stream #0:2 -> #0:2 (ac3 (native) -> ac3 (native))
Press [q] to stop, [?] for help
[volume @ 0x7f9e51a00740] [Eval @ 0x7ffee8e0a300] Missing ')' or too many args in 'between(t'
[volume @ 0x7f9e51a00740] Error when evaluating the expression 'between(t' for enable
[AVFilterGraph @ 0x7f9e51905640] Error initializing filter 'volume' with args 'enable=between(t'
Error reinitializing filters!
Failed to inject frame into filter network: Invalid argument
Error while processing the decoded data for stream #0:1
Conversion failed!
What am I doing wrong? Thanks again for your help. You're amazing to do this.

carlojoe
Posts: 8
Joined: Wed Oct 30, 2019 8:09 pm

Re: Trying to mute all 5.1 channels of audio for a period of time within a video

Post by carlojoe » Tue Nov 05, 2019 12:05 am

@pandy, any ideas on my previous post? Thank you.

pandy
Posts: 255
Joined: Mon Feb 24, 2014 1:46 pm

Re: Trying to mute all 5.1 channels of audio for a period of time within a video

Post by pandy » Sun Nov 10, 2019 8:42 am

Sorry for late reply, was busy.

I don't know how to made ffmpeg script where ffmpeg will be aware of content in your stream then create necessary signal flow.
It may be possible but accordingly to my knowledge not automatically - probably stream need to be analysed (ffprobe as natural choice) then result must be parsed trough some analyzer and based on this created optimal command line for ffmpeg.

Easy way is to convert ALL audio track but there is issue with audio layout (convert all, even mono to 5.1?, allocate same very high 5.1 layout bitrate to track?).
Some editor (something like SED) could be used to automate ffmpeg commandline creation - but still i need get SED working (tried but failed).

carlojoe
Posts: 8
Joined: Wed Oct 30, 2019 8:09 pm

Re: Trying to mute all 5.1 channels of audio for a period of time within a video

Post by carlojoe » Sun Nov 10, 2019 3:54 pm

Thanks for the reply. Again, much appreciated. I'm not asking for ffmpeg to automatically know how to handle the various input streams. I'm just trying to get it to work for these two input audio streams.

Code: Select all

    Stream #0:0[0x100]: Video: h264 (High) ([27][0][0][0] / 0x001B), yuv420p(progressive), 1280x720 [SAR 1:1 DAR 16:9], Closed Captions, 59.94 fps, 59.94 tbr, 90k tbn, 119.88 tbc
    Stream #0:1[0x101](eng): Audio: ac3 ([129][0][0][0] / 0x0081), 48000 Hz, 5.1(side), fltp, 384 kb/s
    Stream #0:2[0x102](spa): Audio: ac3 ([129][0][0][0] / 0x0081), 48000 Hz, stereo, fltp, 192 kb/s
If I had a working example based on these two audio inputs, I'm hopeful I can adapt the code when things change. Again, I attempted to "adapt" based on what you provided before but it failed. Can you provide a working example where both audio streams (5.1 and stereo) are muted for 3 seconds starting 30 seconds into a video (i.e. 30-33 seconds no audio)?

Thank you!

Post Reply
'