I have a big mp3 file including more songs. Is there any way to split the file by detecting silent parts? I would prefer a command line tool (e.g. ffmpeg).
Tried:
youtube-dl --ignore-errors --format bestaudio --extract-audio --audio-format mp3 --audio-quality 160K --output "%(title)s.%(ext)s" --yes-playlist
You can do this manually with
ffmpeg
, and of course it can all be scripted if you prefer.Get silent timestamps
Get silence with the silencedetect filter:
Note the default minimum length for silence is set to 2 seconds, but it can be adjusted. See
ffmpeg -h filter=silencedetect
.There is also a silenceremove filter.
Example output using
awk
:Split
There are a few methods to split.
segment muxer
Example of splitting with the segment muxer:
You will need to delete the silent segments. You could perform a Bash loop on the output files, use silencedetect to find these segments, then delete/move them if you want to script that process.
Note the use of
-c:a copy
which enables stream copy mode so your MP3 does not get re-encoded to avoid generation loss.-ss
and-t
or-to
Using these options will omit the silent segments but is more work to make the commands:
…and so on.
Or do it in one command:
As in the segment muxer command this also uses stream copy.
You will likely not get a ready-to-go solution but will need to create a script yourself. pydub is made for this (it uses ffmpeg or libav internally) and it has a functions called
split_on_silence()
with some settings likekeep_silence=100
.Some references from stackoverflow that have examples: 37725416 and 45526996 And from the creator of pydub.
From the 1st link the interesting part:
mp3splt is a command for splitting mp3s and I believe mp3splt has a silence detector (among other methods of detection)... without re-encoding. To install:
Usage using Silence mode (
-s
):Mp3splt will try to automatically detect splitpoints with silence detection and will split all tracks found with default parameters.
Or
passing desired parameters, splitting 10 tracks (or less if too much) with the most probable silence points at a threshold of -50 dB.
Get the timings by playing clip that you want to cut, I generally do long video clips that I want to trim or to cut out parts of the clip. It can be trimed by using video editing software, but these will typically also recompress the file on export. This reduces the quality of the video, and it also takes a long time. a solution is to perform zero loss cutting is there in ubuntu, in ubuntu there is a way to do this with FFmpeg :
example :
above will cut clip from about 0h10min10s to 0h09min0s, and this takes few seconds to complete.
I know you'd prefer a command-line tool, and I can't blame you. At the same time, if you're doing what I think you might be doing, Audacity is a better choice. It will let you split the file with greater precision and with far less trial-and-error.
(I've tried using ffmpeg to split such files and I will sometimes get a split where I don't want one.)
Here's the relevant part of the Audacity manual.