0

As I read silenceremove will reencode file.

Usually I do it manually creating file like:

file 'file.mp3'
inpoint 0
outpoint 01:55:00.0

file 'file.mp3'
inpoint 02:03:50.0

and executing this command:

ffmpeg -f concat -safe 0 -i list.txt -c copy file.mp3

Maybe I can use silencedetect for creating the same file...

Vitaly Zdanevich
  • 190
  • 1
  • 3
  • 18
  • 1
    Because MP3 is a compressed format, the silences can be identified only by decompressing, necessitating recompression after removal. To remove silences without further degradation you would need to edit the original file before MP3 encoding; if this is unavailable, the best you can do is to decompress, remove the silences and save with a lossless encoder, but you will then have much poorer compression in comparison with MP3. – AFH Nov 11 '18 at 15:47
  • But with ffmpeg we already can cut parts of mp3 without reencoding specifying regions manually. – Vitaly Zdanevich Nov 11 '18 at 17:16
  • I was not expecting that, but after looking at the MP3 specification it seems that each data block may be independently compressed. You should be able to create an edit list from `silencedetect`, but it is probably worth checking if you can add `-c copy` to the `silenceremove` command string. Unfortunately I don't have these options in my copy of `ffmpeg` (3.4.4), so I can't test if it works. – AFH Nov 11 '18 at 18:51
  • @AFH [From another answer](https://stackoverflow.com/a/29411973/1879101): `You cannot use -acodec copy to keep the original quality.` – Vitaly Zdanevich Nov 11 '18 at 20:23
  • I've looked at @harrymc's answer and links: I found that I _do_ have `silenceremove` as a filter, but when I tried to combine it with `-c copy` I got `Filtergraph 'silenceremove=0.5:-50dB' was defined for audio output stream 0:0 but codec copy was selected.`/`Filtering and streamcopy cannot be used together.` So I think that must be your answer, though an edit list may still allow an answer without reencoding. – AFH Nov 11 '18 at 20:50
  • Mate, what you're trying to accomplish isn't possible without re-encoding the file. – tripulse Jul 13 '19 at 16:02
  • 1
    @nullptr why not, because now we already can cut a part of a file without reencoding. – Vitaly Zdanevich Jul 17 '19 at 07:15
  • How to use the decoded file simply as your reference to find the silences, but perform the actual cuts on the encoded file? – johny why Apr 30 '20 at 19:10

1 Answers1

0

This is answered in the Stack Overflow post using FFMPEG with silencedetect to remove audio silence.

The first remark is that silencedetect only detects the silence, not remove it. You should use instead the silenceremove filter.

To detect whether your version of ffmpeg has this filter run:

ffmpeg -hide_banner -filters | grep silenceremove

The output should look like:

silenceremove A->A Remove silence

The command to remove silent parts may look like:

ffmpeg -i input.mp3 -af silenceremove=1:0:-50dB output.mp3

Where the silenceremove parameter is explained as removing:

  • at the beginning (indicated by the first argument 1)
  • with minimum length zero (indicated by the second argument 0)
  • silence is classified as anything under -50 decibels (indicated by -50dB)

Reference: FFMPEG silence remove filter.

For finding the right value for silence, normalize first the input audio volume to 0dB, described in this answer.

harrymc
  • 455,459
  • 31
  • 526
  • 924
  • Comment under your first link: `Please note, that -af silenceremove **will re-encode** your audio files`. – Vitaly Zdanevich Nov 11 '18 at 20:18
  • This would actually be required, since the encoding scheme may need to re-encode the audio immediately before or after the cut-out silent part. – harrymc Nov 11 '18 at 20:24
  • But using ffmpeg we can manually cut parts of the mp3 without reencoding. – Vitaly Zdanevich Nov 11 '18 at 20:26
  • I have no knowledge about how this filter was programmed. – harrymc Nov 11 '18 at 20:29
  • 1
    @VitalyZdanevich Filtering requires re-encoding. The input is [decoded, fed to the filter, then encoded](https://ffmpeg.org/ffmpeg.html#Simple-filtergraphs) to your output format. So you can't [stream copy](https://ffmpeg.org/ffmpeg.html#Stream-copy) when filtering. "Manually cut parts of the mp3" with stream copy omits decoding/encoding and only re-muxes. – llogan Nov 11 '18 at 21:38
  • How to use the decoded file simply as your reference to find the silences, but perform the actual cuts on the encoded file? – johny why Apr 30 '20 at 19:12