I have over 1000 audio files, all of which end in a mouse click. I would like to remove the last half second from all of them. The audio files have different length (i.e. 15sec, 5 sec ...) But one thing in common with all of them is the last half second has a mouse click sound. How do I trim in bulk the ending of the mp3 files within a folder using windows 10 command line? I already have FFMPEG downloaded. Thank you!
Asked
Active
Viewed 730 times
2 Answers
1
This is two questions in one:
- How to remove the last 0.5 seconds from inputs of arbitrary durations?
- How to incorporate this into a Windows batch script?
I'll answer #1 because I'm not a Windows user. The batch scripting will be up to you.
Get duration using ffprobe
:
ffprobe -v error -show_entries format=duration -of csv=p=0 input.mp3
Trim using ffmpeg
:
ffmpeg -i input.mp3 -t <duration> -c copy output.mp3
Replace <duration>
with the output from ffprobe
minus 0.5 seconds.

llogan
- 121,796
- 28
- 232
- 243
-
1Reminds me, there's a patch for input `-toeof` which could be revived. – Gyan Jul 26 '19 at 04:46
-
Thank you Llogan for the answer. I really appreciate it. I really cannot do it manually file by file. I need to run a batch.bat file if possible since there are over 1000 files. I hope someone will find the answer. Thank you! – user2828890 Jul 26 '19 at 11:59
1
- How to incorporate this into a Windows batch script?
This should do:
FOR %%A IN (*.mp3) DO (
FOR /F %%B IN ('ffprobe.exe -v error -show_entries format^=duration -of csv^=p^=0 "%%~A" ^| xidel -s - -e ". - 0.5"') DO (
ffmpeg.exe -i "%%~A" -t %%B -c copy "%%~dpnA_trimmed.mp3"
)
)
First of all, doing floating point calculations in Batch is officially impossible and unofficially really hard to script. That's why I suggest to let Xidel do the math. It's first of all a command line tool to download and extract data from HTML/XML/JSON, but it can do A LOT more!
- Loop over all mp3-files in the current directory.
- The ffprobe command as suggested by llogan piped to Xidel to subtract the 0.5s. For example,
25.547755
now becomes25.047755
.
Don't forget to escape the necessary characters inside the for-loop! The=
and|
in this case. - The ffmpeg command as suggested by llogan, which opens
"%%~A
(the mp3-file), sets the duration to%%B
and creates a new mp3-file (<filename>_trimmed.mp3
). - This code assumes the mp3-files,
ffprobe.exe
,xidel.exe
andffmpeg.exe
are all in the same directory.

Reino
- 3,203
- 1
- 13
- 21
-
Hi Reino. Thank you for the code. I am hoping it will work since it will save me days of manual coding. How do I make Xidel do the math? do I download it first, then place the downloaded file under the same folder as FFMPEG? I'm not familiar with any of the code above, so when you say don't forget to escape some for-loop, does that mean that I will need to modify the code further? Thank you! – user2828890 Jul 26 '19 at 13:15
-
With "_windows 10 command line_" I assumed you were already familiar with cmd/batch. Above is a simple batch script which you can copy/paste in Notepad and save as a `*.bat` file. Of course you can also type this command (as one line!) directly in cmd. Replace `%%` with `%` in that case. Xidel, just like FFmpeg, is not a standard Windows program, so yes you have to download it first. Same dir as ffmpeg.exe indeed if you want the above code to work. Escaping in batch means putting a `^` in front of certain characters. The `=` and `|` are already escaped so no need to modify the code any further – Reino Jul 26 '19 at 13:57
-
I did the following: I downloaded Xidel and put one copy of it inside FFmpeg folder and one copy immediately outside of it just in case. I also created a batch.bat file with the code above, but I get this error:For valid formats type CALL /? or FOR /? The syntax of the command is incorrect. – user2828890 Jul 26 '19 at 14:38
-
Are you sure you're using the code exactly as above in the bat-file? I believe such an error message indicates the use of `%` instead of `%%`. – Reino Jul 26 '19 at 15:00
-
-
I see the error, your code had: "%~dpnA_trimmed.mp3" missing the second %. I just corrected it and now I have stuff running in the background. I will check it once it run and let you know. – user2828890 Jul 26 '19 at 15:15
-
Ok after adding the %, the code ran through all the files. Each audio file it ran, generated the following error: C:\pathname\_test>(FOR /F %B IN ('ffprobe.exe -v error -show_entries format=duration -of csv=p=0 "test1.mp3" | xidel -s - -e ". - 0.5"') DO (ffmpeg.exe -i "test1.mp3" -t %B -c copy "C:\pathname\_test\test1_trimmed.mp3" ) ) 'ffprobe.exe' is not recognized as an internal or external command, operable program or batch file. – user2828890 Jul 26 '19 at 15:20
-
Ah, sorry about that. Forgot 1 `%` at the end indeed. Well, that's a very clear message, isn't it? You need `ffprobe.exe` (which comes together with `ffmpeg.exe`) to get the initial duration. – Reino Jul 26 '19 at 15:29
-
I don't see it inside the FFMPEG I have which is a couple years old. I'm downloading a new version. Hopefully it's there. I will let you know. Thank you! – user2828890 Jul 26 '19 at 15:30
-
Thank you Reino so much. I ran it again after adding the ffprove.exe and it worked as it is supposed to. I really appreciate your help. Have an awesome weekend! – user2828890 Jul 26 '19 at 16:13
-
That's good to hear! You're welcome. Please mark the answer "useful" on your way out. – Reino Jul 26 '19 at 16:31
-
-
Whoops! Must be the extremely high temperature here today. I'll correct my answer. – Reino Jul 27 '19 at 01:06
-
I tried to mark the answer up but it says I don't have enough reputation :-) Great work. Thank you again! – user2828890 Jul 27 '19 at 01:46