ffmpegmp4

How can I remove silence of a video?


I wanted to automatically remove the silence from some of my videos.

I found the following command by searching:

ffmpeg -i C:\Users\`*`myusername`*`\Desktop\videowithsielence.mp4 -af silenceremove=1:0:-50dB C:\Users\`*`myusername`*`\Desktop\newvideo.mp4

There isn't any error and this is the following output:

ffmpeg version N-117094-g2bf588f273-20240921 Copyright (c) 2000-2024 the FFmpeg developers
  built with gcc 14.2.0 (crosstool-NG 1.26.0.106_ed12fa6)
  configuration: --prefix=/ffbuild/prefix --pkg-config-flags=--static --pkg-config=pkg-config --cross-prefix=x86_64-w64-mingw32- --arch=x86_64 --target-os=mingw32 --enable-gpl --enable-version3 --disable-debug --disable-w32threads --enable-pthreads --enable-iconv --enable-zlib --enable-libfreetype --enable-libfribidi --enable-gmp --enable-libxml2 --enable-lzma --enable-fontconfig --enable-libharfbuzz --enable-libvorbis --enable-opencl --disable-libpulse --enable-libvmaf --disable-libxcb --disable-xlib --enable-amf --enable-libaom --enable-libaribb24 --enable-avisynth --enable-chromaprint --enable-libdav1d --enable-libdavs2 --enable-libdvdread --enable-libdvdnav --disable-libfdk-aac --enable-ffnvcodec --enable-cuda-llvm --enable-frei0r --enable-libgme --enable-libkvazaar --enable-libaribcaption --enable-libass --enable-libbluray --enable-libjxl --enable-libmp3lame --enable-libopus --enable-librist --enable-libssh --enable-libtheora --enable-libvpx --enable-libwebp --enable-libzmq --enable-lv2 --enable-libvpl --enable-openal --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenh264 --enable-libopenjpeg --enable-libopenmpt --enable-librav1e --enable-librubberband --enable-schannel --enable-sdl2 --enable-libsoxr --enable-libsrt --enable-libsvtav1 --enable-libtwolame --enable-libuavs3d --disable-libdrm --enable-vaapi --enable-libvidstab --enable-vulkan --enable-libshaderc --enable-libplacebo --enable-libvvenc --enable-libx264 --enable-libx265 --enable-libxavs2 --enable-libxvid --enable-libzimg --enable-libzvbi --extra-cflags=-DLIBTWOLAME_STATIC --extra-cxxflags= --extra-libs=-lgomp --extra-ldflags=-pthread --extra-ldexeflags= --cc=x86_64-w64-mingw32-gcc --cxx=x86_64-w64-mingw32-g++ --ar=x86_64-w64-mingw32-gcc-ar --ranlib=x86_64-w64-mingw32-gcc-ranlib --nm=x86_64-w64-mingw32-gcc-nm --extra-version=20240921
  libavutil      59. 37.100 / 59. 37.100
  libavcodec     61. 17.100 / 61. 17.100
  libavformat    61.  6.100 / 61.  6.100
  libavdevice    61.  2.101 / 61.  2.101
  libavfilter    10.  3.100 / 10.  3.100
  libswscale      8.  2.100 /  8.  2.100
  libswresample   5.  2.100 /  5.  2.100
  libpostproc    58.  2.100 / 58.  2.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'C:\Users\*myusername*\Desktop\stille.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    encoder         : Lavf61.1.100
  Duration: 00:00:17.60, start: 0.000000, bitrate: 14994 kb/s
  Stream #0:0[0x1](und): Video: h264 (Constrained Baseline) (avc1 / 0x31637661), yuv420p(tv, bt709, progressive), 1920x1080 [SAR 1:1 DAR 16:9], 14915 kb/s, 60 fps, 60 tbr, 15360 tbn (default)
      Metadata:
        handler_name    : VideoHandler
        vendor_id       : [0][0][0][0]
  Stream #0:1[0x2](und): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 83 kb/s (default)
      Metadata:
        handler_name    : SoundHandler
        vendor_id       : [0][0][0][0]
Stream mapping:
  Stream #0:0 -> #0:0 (h264 (native) -> h264 (libx264))
  Stream #0:1 -> #0:1 (aac (native) -> aac (native))
Press [q] to stop, [?] for help
[libx264 @ 000002b596997d00] using SAR=1/1
[libx264 @ 000002b596997d00] using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2 AVX FMA3 BMI2 AVX2
[libx264 @ 000002b596997d00] profile High, level 4.2, 4:2:0, 8-bit
[libx264 @ 000002b596997d00] 264 - core 164 - H.264/MPEG-4 AVC codec - Copyleft 2003-2024 - http://www.videolan.org/x264.html - options: cabac=1 ref=3 deblock=1:0:0 analyse=0x3:0x113 me=hex subme=7 psy=1 psy_rd=1.00:0.00 mixed_ref=1 me_range=16 chroma_me=1 trellis=1 8x8dct=1 cqm=0 deadzone=21,11 fast_pskip=1 chroma_qp_offset=-2 threads=18 lookahead_threads=3 sliced_threads=0 nr=0 decimate=1 interlaced=0 bluray_compat=0 constrained_intra=0 bframes=3 b_pyramid=2 b_adapt=1 b_bias=0 direct=1 weightb=1 open_gop=0 weightp=2 keyint=250 keyint_min=25 scenecut=40 intra_refresh=0 rc_lookahead=40 rc=crf mbtree=1 crf=23.0 qcomp=0.60 qpmin=0 qpmax=69 qpstep=4 ip_ratio=1.40 aq=1:1.00
Output #0, mp4, to 'C:\Users\*myusername*\Desktop\Aufzeich.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    encoder         : Lavf61.6.100
  Stream #0:0(und): Video: h264 (avc1 / 0x31637661), yuv420p(tv, bt709, progressive), 1920x1080 [SAR 1:1 DAR 16:9], q=2-31, 60 fps, 15360 tbn (default)
      Metadata:
        handler_name    : VideoHandler
        vendor_id       : [0][0][0][0]
        encoder         : Lavc61.17.100 libx264
      Side data:
        cpb: bitrate max/min/avg: 0/0/0 buffer size: 0 vbv_delay: N/A
  Stream #0:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 128 kb/s (default)
      Metadata:
        handler_name    : SoundHandler
        vendor_id       : [0][0][0][0]
        encoder         : Lavc61.17.100 aac
[out#0/mp4 @ 000002b594b08800] video:2969KiB audio:180KiB subtitle:0KiB other streams:0KiB global headers:0KiB muxing overhead: 0.825545%
frame= 1055 fps=236 q=-1.0 Lsize=    3174KiB time=00:00:16.54 bitrate=1571.3kbits/s speed= 3.7x
[libx264 @ 000002b596997d00] frame I:5     Avg QP:14.66  size:136185
[libx264 @ 000002b596997d00] frame P:351   Avg QP:18.48  size:  6338
[libx264 @ 000002b596997d00] frame B:699   Avg QP:25.92  size:   191
[libx264 @ 000002b596997d00] consecutive B-frames:  1.5%  6.1% 73.1% 19.3%
[libx264 @ 000002b596997d00] mb I  I16..4: 61.0% 21.9% 17.2%
[libx264 @ 000002b596997d00] mb P  I16..4:  0.2%  0.1%  0.0%  P16..4:  4.8%  0.8%  0.8%  0.0%  0.0%    skip:93.4%
[libx264 @ 000002b596997d00] mb B  I16..4:  0.0%  0.0%  0.0%  B16..8:  2.0%  0.0%  0.0%  direct: 0.0%  skip:98.0%  L0:75.0% L1:22.4% BI: 2.5%
[libx264 @ 000002b596997d00] 8x8 transform intra:22.8% inter:38.2%
[libx264 @ 000002b596997d00] coded y,uvDC,uvAC intra: 57.3% 73.0% 56.4% inter: 1.0% 1.0% 0.1%
[libx264 @ 000002b596997d00] i16 v,h,dc,p: 31% 25% 32% 12%
[libx264 @ 000002b596997d00] i8 v,h,dc,ddl,ddr,vr,hd,vl,hu: 24% 21% 42%  2%  2%  2%  2%  3%  3%
[libx264 @ 000002b596997d00] i4 v,h,dc,ddl,ddr,vr,hd,vl,hu: 33% 31% 22%  2%  2%  2%  2%  2%  3%
[libx264 @ 000002b596997d00] i8c dc,h,v,p: 41% 32% 13% 13%
[libx264 @ 000002b596997d00] Weighted P-Frames: Y:0.3% UV:0.0%
[libx264 @ 000002b596997d00] ref P L0: 68.2%  7.2% 20.4%  4.2%  0.0%
[libx264 @ 000002b596997d00] ref B L0: 79.0% 18.8%  2.2%
[libx264 @ 000002b596997d00] ref B L1: 98.4%  1.6%
[libx264 @ 000002b596997d00] kb/s:1382.74
[aac @ 000002b596a4f680] Qavg: 21440.516

But the new video is exactly the same as the first one. I also tried changing the 50dB number but that didn't work either... My question is "Why?" and "How can I fix this?"...


Solution

  • Looking at the ffmpeg documentation for silenceremove, this should work:

    silenceremove=stop_periods=-1:stop_duration=1:stop_threshold=-50dB
    

    This trim all silence encountered from beginning to end where there is more than 1 second of silence in audio.

    So the command would be:

    ffmpeg -i C:\Users\`*`myusername`*`\Desktop\videowithsielence.mp4 -af silenceremove=stop_periods=-1:stop_duration=1:stop_threshold=-50dB C:\Users\`*`myusername`*`\Desktop\newvideo.mp4
    

    To trim the video to match the audio use the -shortest option:

    silenceremove=stop_periods=-1:stop_duration=1:stop_threshold=-50dB -shortest