3

I have been trying to silence a section of a video with multiple audio streams. I'm not getting it to work correctly.

Trying with afade option gives me a silent video. Test video just has one audio stream to test.

ffmpeg -i input.asf -c:v copy -af "afade=t=out:st=10,afade=t=in:st=30" output.asf

Do I need to specify all the audio streams as well? Is there a better way to insert silence with a given time and duration?

FFMPEG OUTPUT

C:\dump\videoconvert>ffmpeg -i black.asf -c:v copy -af "afade=t=out:st=10,afade=t=in:st=30" out.asf
ffmpeg version N-66438-g4f4f08e Copyright (c) 2000-2014 the FFmpeg developers
  built on Sep 24 2014 22:26:49 with gcc 4.9.1 (GCC)
  configuration: --enable-gpl --enable-version3 --disable-w32threads --enable-avisynth --enable-bzlib --enable-font
config --enable-frei0r --enable-gnutls --enable-iconv --enable-libass --enable-libbluray --enable-libbs2b --enable-
libcaca --enable-libfreetype --enable-libgme --enable-libgsm --enable-libilbc --enable-libmodplug --enable-libmp3la
me --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-libopus --enable-librtmp --e
nable-libschroedinger --enable-libsoxr --enable-libspeex --enable-libtheora --enable-libtwolame --enable-libvidstab
 --enable-libvo-aacenc --enable-libvo-amrwbenc --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libw
ebp --enable-libx264 --enable-libx265 --enable-libxavs --enable-libxvid --enable-zlib
  libavutil      54.  7.101 / 54.  7.101
  libavcodec     56.  1.101 / 56.  1.101
  libavformat    56.  5.100 / 56.  5.100
  libavdevice    56.  1.100 / 56.  1.100
  libavfilter     5.  1.102 /  5.  1.102
  libswscale      3.  1.100 /  3.  1.100
  libswresample   1.  1.100 /  1.  1.100
  libpostproc    53.  1.100 / 53.  1.100
Guessed Channel Layout for  Input Stream #0.1 : stereo
Input #0, asf, from 'black.asf':
  Metadata:
    encoder         : Lavf56.5.100
  Duration: 00:05:49.44, start: 0.000000, bitrate: 352 kb/s
    Stream #0:0: Video: msmpeg4v3 (MP43 / 0x3334504D), yuv420p, 1024x768, 15 fps, 15 tbr, 1k tbn, 1k tbc
    Stream #0:1: Audio: wmav2 (a[1][0][0] / 0x0161), 44100 Hz, 2 channels, fltp, 128 kb/s
File 'out.asf' already exists. Overwrite ? [y/N] y
Output #0, asf, to 'out.asf':
  Metadata:
    WM/EncodingSettings: Lavf56.5.100
    Stream #0:0: Video: msmpeg4v3 (MP43 / 0x3334504D), yuv420p, 1024x768, q=2-31, 15 fps, 1k tbn, 1k tbc
    Stream #0:1: Audio: wmav2 (a[1][0][0] / 0x0161), 44100 Hz, stereo, fltp, 128 kb/s
    Metadata:
      encoder         : Lavc56.1.101 wmav2
Stream mapping:
  Stream #0:0 -> #0:0 (copy)
  Stream #0:1 -> #0:1 (wmav2 (native) -> wmav2 (native))
Press [q] to stop, [?] for help
frame= 5240 fps=1172 q=-1.0 Lsize=   15056kB time=00:05:49.36 bitrate= 353.0kbits/s
video:8911kB audio:5459kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 4.767603%
1

The problem

Your output is silent because your fade out makes everything silent after fading out, so there is nothing for the fade in to work with. Then the fade in makes everything silent until the fade in occurs, and therefore "wiping out" your first afade, resulting in a silent output.

The solution

You can use timeline editing to enable filters at specific times.

Example command

ffmpeg -i input.asf -af "afade=enable='between(t,10,30)':t=out:st=10,afade=enable='gte(t,30)':t=in:st=30" -c:v copy output.asf

Notes

  • 'between(t,10,30)' will make the fade out active between 10-30 seconds.
  • 'gte(t,30)' will enable the fade in filter at 30 seconds.
  • -c:v copy will stream copy (re-mux) the video since you may not need to filter and re-encode it.

Inputs with multiple audio streams

Your input may contain multiple audio streams. In the example ffmpeg console output below [0:0] is the video, [0:1] is the first audio stream, and [0:2] is the second audio stream:

Input #0, matroska,webm, from 'input.mkv':
  Metadata:
    ENCODER         : Lavf56.4.101
  Duration: 00:00:30.28, start: 0.068000, bitrate: 265 kb/s
    Stream #0:0: Video: h264 (High 4:4:4 Predictive), yuv444p, 320x240 [SAR 1:1 DAR 4:3], 25 fps, 25 tbr, 1k tbn, 50 tbc (default)
    Stream #0:1: Audio: mp3, 44100 Hz, stereo, s16p, 112 kb/s
    Stream #0:2: Audio: mp3, 44100 Hz, stereo, s16p, 112 kb/s

Example command

You will have to make a fade out/in for each stream:

ffmpeg -i input.asf -filter_complex \
"[0:a:0]afade=enable='between(t,10,30)':t=out:st=10,afade=enable='gte(t,30)':t=in:st=30[a0] \
 [0:a:1]afade=enable='between(t,10,30)':t=out:st=10,afade=enable='gte(t,30)':t=in:st=30[a1]" \
-map 0:v -map "[a0]" -map "[a1]" -c:v copy output.asf

Notes

  • Use -filter_complex instead of -af for complex filtergraphs. Complex filtergraphs involve one or more inputs and one or more outputs.

  • [0:a:0] refers to the first audio stream of the first input; alternatively you could use [0:1] as shown in the ffmpeg console output above, but I find that syntax to be less flexible because for other inputs [0:1] could possibly refer to a video stream. [0:a:1] refers to the second audio stream of the first input; alternatively you could use [0:2] as shown in the ffmpeg console output above.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.