8

I have an audio file which has both leading and trailing silence and with the following specifics:

Codec: MPEG AAC Audio (mp4a) Channels: Stereo Sample rate: 44100 Hz Bitrate: 253 kbps

I want to remove the silences AND keep the quality intact.

So far I've tried

ffmpeg -i 1.m4a -af silenceremove=1:0.5:0:1:0.5:0 2.m4a 

This is supposed to remove both the leading and trailing silences. But for some reason it doesn't remove the trailing silence. This seems to be a recurring problem. Found the following on another forum.

http://ffmpeg-users.933282.n4.nabble.com/How-to-delete-digital-silence-tp4667256p4667356.html

Also, ffmpeg reduces the bitrate to 128kbps. This I could fix by adding -ab 253k and making the command:

ffmpeg -i 1.m4a -af silenceremove=1:0.5:0:1:0.5:0 -ab 253k 3.m4a 

Now the problem is that the trailing silence isn't removed and when I want to process a batch of files I can't use the same bitrate (like 253kbps ) for every file. I'd like to know how VBR could be used for this case.

I know I can use sox and use the silence and reverse features to trim the silences.

http://digitalcardboard.com/blog/2009/08/25/the-sox-of-silence "Example 3 in this post"

But sox has the following problems:

  1. It can't handle m4a files, I had to convert all files to mp3.
  2. When using the silence filter in sox it caps the bitrate at 128kbps.

    sox 1.mp3 2.mp3 silence 1 0.5 1% reverse silence 1 0.5 1% reverse
    
CreativiTimothy
  • 103
  • 1
  • 8
Tejas Anil Shah
  • 1,421
  • 11
  • 20

1 Answers1

0

Your question is actually consists of two, one about trailing silence, and second about bitrate.

Here's an answer to second question: For keep EXACT quality of audio source you can use -c:a pcm_s16le and .wav container if it's applicable.

Second option is to use quality scale -q:a N, N (unlike -q:v is codec-specific, and you'd better to test different values, for MP3 it's from 0 to 9, where 0 is highest quality)

If both, uncompressed WAV and Quality Scale are not an options, but you still want to achieve original quality (so, no reencoding) answer would be tricky:

  1. Make a track with silence removed from start.
  2. Subtract original track length from silence-removed track (to know how long silence is)
  3. Convert original track using -ss TIMESTAMP (start time of input) and -c:a copy
  4. Repeat same for tail silence.
Alex
  • 526
  • 2
  • 8