Home | Blog | Software | Reviews and Features | Forum | Help | Donate | About us
topbanner_forum
  *

avatar image

Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
  • December 10, 2016, 11:58:00 PM
  • Proudly celebrating 10 years online.
  • Donate now to become a lifetime supporting member of the site and get a non-expiring license key for all of our programs.
  • donate

Author Topic: 30SecondSilencer - add silence every 30 seconds to an mp3 file  (Read 2492 times)

Nod5

  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 858
    • View Profile
    • Donate to Member
30SecondSilencer - add silence every 30 seconds to an mp3 file
« on: January 10, 2016, 03:54:02 AM »
30SecondSilencer is a windows tool to add 30 seconds of silence every 30 seconds to an mp3 file.

30secondsilencer.png

But the duration of the silence and music segments can be customized. For example you can add 10s silence every 55s in the mp3 file. Optional fade in/out.

Download binary and source here
http://nod5.dcmember...0secondsilencer.html


Requirements:
ffmpeg (and ffprobe that comes with ffmpeg)
http://ffmpeg.zeranoe.com/builds/

To compile from source:
Autohotkey (v1.1.21 or newer)
https://autohotkey.com/

changelog
v160113
first version with GUI
now uses windows temp folder as workdir (can be changed in source)
now outputs C:\<inputfolder>\<inputfilename>_30ss.mp3

v160109
first version, no GUI (pm if you want the old source)

Code: Autohotkey [Select]
  1. if !A_IsCompiled and FileExist("30SecondSilencer.ico")
  2.  Menu, Tray, Icon, 30SecondSilencer.ico
  3.  
  4. info =
  5. (
  6. 30SecondSilencer
  7. version 160113 -- free software GPLv3 -- by nod5.dcmembers.com
  8.  
  9. Adds 30 seconds silence every 30 seconds to an mp3 file
  10. But the duration of the silence and music segments can be customized
  11.  
  12. Requirements:
  13. ffmpeg (and ffprobe that comes with ffmpeg)
  14. http://ffmpeg.zeranoe.com/builds/
  15.  
  16. To compile from source:
  17. Autohotkey (v1.1.21 or newer)
  18. https://autohotkey.com/
  19.  
  20. source = Input mp3 file. Example: C:\music\some music file.mp3
  21. ffmpeg = Example: C:\tools\ffmpeg.exe (note: ffprobe.exe must be in same folder)
  22. silence = Length of each silence segment, in seconds. Default: 30
  23. music = Length of each Music segment. Default: 30
  24. fade = set 1 for 3s fade in/out for music segments. Blank for no fade.
  25. slow = set 1 for slower, less stuttery processing. Blank for maximum speed.
  26. )
  27.  
  28. arr := {1:"",2:"",3:30,4:30,5:1,6:0}  ;defaults
  29. names = source|ffmpeg|silence|music|fade|slow
  30.  
  31. FileRead, ini, %A_ScriptFullPath%.ini
  32. Loop, Parse, ini, |
  33.  arr[A_index] := A_LoopField ? A_LoopField : arr[%A_index%]
  34. Loop, parse, names, |
  35.         {
  36.         %A_LoopField% := arr[%A_index%]
  37.         xs := a_index == 1 ? "section" : a_index==4 or a_index==6 ?  "x+15" : "xs"
  38.         w := a_index > 2 ? 50 : 200
  39.         gui, add, text,%xs%, %A_LoopField%
  40.         gui, add, edit, R1 yp xp+40 w%w% v%A_LoopField%, % arr[A_index]
  41.         }
  42. gui, add, text,xs cBlue ginfo, ?
  43. gui, add, button, Default xp+200 gdo, Start
  44. gui, show,,30SecondSilencer
  45. return
  46.  
  47. info:
  48. msgbox % info
  49. return
  50.  
  51.  
  52. do:
  53.  
  54. ;audio quality
  55. ;https://trac.ffmpeg.org/wiki/Encode/MP3
  56. qual = -b:a 320k
  57.  
  58. ;check paths
  59. SplitPath, source,,sdir,, noext
  60. SplitPath, ffmpeg,,fdir
  61. workdir := A_Temp  ;change to use another temp workdir
  62.  
  63. if !FileExist(source) or !FileExist(workdir) or !FileExist(ffmpeg) or !FileExist(fdir "\ffprobe.exe")
  64.  
  65. ;save ini
  66. FileDelete, %A_ScriptFullPath%.ini
  67. FileAppend, %source%|%ffmpeg%|%silence%|%music%|%fade%|%slow%, %A_ScriptFullPath%.ini
  68.  
  69. ;Clear old files
  70. Filedelete %workdir%\30ss-silent.mp3
  71. Filedelete %workdir%\30ss_*.mp3
  72. Filedelete %sdir%\%noext%_30ss.mp3
  73. Filedelete %workdir%\30ss_*.txt
  74.  
  75. ;Get source duration in seconds
  76. ;http://superuser.com/a/945604
  77. RunWait %comspec% /c ""%fdir%\ffprobe.exe" -v error -show_entries format=duration -of default=noprint_wrappers=1:nokey=1 "%source%" >> "%workdir%\30ss_duration.txt"" ,,Min
  78. FileRead, dur, %workdir%\30ss_duration.txt
  79. length := Ceil(dur)
  80. if !length
  81.  
  82. ;split source into 30 seconds long mp3 chunks
  83. ;http://stackoverflow.com/a/7945753
  84. steps := Ceil(length / music) ; number of steps
  85. start = 0
  86. ToolTip, Splitting 0 / %steps%
  87.  
  88. Loop, %steps%
  89. {
  90. c := StrLen(a_index)==1 ? "00" a_index : StrLen(a_index)==2 ? "0" a_index : a_index
  91. if !slow
  92.  Run "%ffmpeg%" -ss %start% -i "%source%" %qual% -t %music% "%workdir%\30ss_%c%.mp3" ,,Min
  93. else
  94.  RunWait "%ffmpeg%" -ss %start% -i "%source%" %qual% -t %music% "%workdir%\30ss_%c%.mp3" ,,Min
  95. start := start + music
  96. ToolTip, Splitting %A_index% / %steps%
  97. }
  98. ToolTip, Processing...  ;wait for ffmpeg to make all chunks
  99.  
  100. waitproc("Processing")
  101.  
  102. ;make 30 sec silent audio mp3 file
  103. ;http://stackoverflow.com/a/32027123
  104. ToolTip, make silent.mp3
  105. RunWait "%ffmpeg%" -f lavfi -i anullsrc %qual% -t %silence% "%workdir%\30ss-silent.mp3",,Min
  106.  
  107. ;fade chunks in/out 3 seconds
  108. ;http://stackoverflow.com/a/27913617
  109. ;use temp file because afade errors if direct overwrite
  110. if fade
  111. {
  112. ToolTip, Fading 0 / %steps%
  113. st := music - 3
  114. Loop, Files,  %workdir%\30ss_*.mp3
  115. {
  116. if !slow
  117.  Run "%ffmpeg%" -i "%A_LoopFileFullPath%" %qual% -af afade=t=in:ss=0:d=3`,afade=t=out:st=%st%:d=3 "%A_LoopFileDir%\temp_%A_LoopFileName%",,Min
  118. else
  119.  RunWait "%ffmpeg%" -i "%A_LoopFileFullPath%" %qual% -af afade=t=in:ss=0:d=3`,afade=t=out:st=%st%:d=3 "%A_LoopFileDir%\temp_%A_LoopFileName%",,Min
  120. ToolTip, Fading %A_index% / %steps%  
  121. }
  122.  
  123. waitproc("Fading")
  124.  
  125. Loop, Files, %workdir%\temp_30ss_*.mp3
  126.         {
  127.         temp := SubStr(A_LoopFileName,6)  ;trim temp_
  128.         FileMove, %A_LoopFileFullPath% , %A_LoopFileDir%\%temp% , 1  ;overwrite nonfade chunks
  129.         }
  130. }
  131.  
  132. ;Concatenate chunk1 silence chunk2 silence ...
  133. ;https://trac.ffmpeg.org/wiki/Concatenate
  134. ToolTip, Concatenate...
  135. Loop, Files, %workdir%\30ss_*.mp3
  136.  FileAppend, file '%workdir%\%A_LoopFileName%'`nfile '%workdir%\30ss-silent.mp3'`n, %workdir%\30ss_list.txt
  137. RunWait "%ffmpeg%" -nostats -loglevel 0 -f concat -i "%workdir%\30ss_list.txt" %qual% -c copy "%sdir%\%noext%_30ss.mp3" ,,Min
  138.  
  139. ;cleanup
  140. Filedelete %workdir%\30ss-silent.mp3
  141. Filedelete %workdir%\30ss_*.mp3
  142. Filedelete %workdir%\30ss_*.txt
  143.  
  144. ToolTip, Finished!
  145. sleep 1000
  146.  
  147. waitproc(mode){
  148.         Loop
  149.         {
  150.         pcount = 0
  151.         for process in ComObjGet("winmgmts:").ExecQuery("Select * from Win32_Process")
  152.                 if InStr(process.Name, "ffmpeg.exe")
  153.                  pcount++
  154.         if pcount < 1
  155.          break
  156.         ToolTip %mode% %pcount% left
  157.         sleep 400
  158.         }
  159.         return
  160. }

Thanks to Attronarch (and mom!) for test driving the script, and for coming up with the use case.  :)
« Last Edit: January 13, 2016, 11:36:32 AM by Nod5, Reason: Updated to version with GUI »

Ath

  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 2,790
    • View Profile
    • Donate to Member
Re: 30SecondSilencer - add silence every 30 seconds to an mp3 file
« Reply #1 on: January 10, 2016, 04:00:39 AM »
Nice job!
I saw it grow in the other thread, and it's spot-on.

Too bad NANY is already finished, it would have been a great entry :Thmbsup:

Nod5

  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 858
    • View Profile
    • Donate to Member
Re: 30SecondSilencer - add silence every 30 seconds to an mp3 file
« Reply #2 on: January 10, 2016, 05:05:09 AM »
Thanks Ath! Yeah, bad timing. Will do something for NANY next year!

Attronarch

  • Supporting Member
  • Joined in 2012
  • **
  • Posts: 116
    • View Profile
    • Donate to Member
Re: 30SecondSilencer - add silence every 30 seconds to an mp3 file
« Reply #3 on: January 10, 2016, 06:48:33 AM »
Nod5, thank you for making the script. With addition of editable music and silence parts this script is great utility for making various training soundtracks, e.g. for circuit training, intervals, tabatas, and sparring / randori sessions...

It is better than using stopwatch and manually operating stereo equipment, puts a lot more pressure.

kilele

  • Charter Member
  • Joined in 2006
  • ***
  • default avatar
  • Posts: 204
    • View Profile
    • Donate to Member
Re: 30SecondSilencer - add silence every 30 seconds to an mp3 file
« Reply #4 on: January 11, 2016, 07:00:18 PM »
Nice tool! I like a few seconds pause between tracks so I can listen to nature when cycling around

Nod5

  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 858
    • View Profile
    • Donate to Member
Re: 30SecondSilencer - add silence every 30 seconds to an mp3 file
« Reply #5 on: January 13, 2016, 11:33:30 AM »
Updated first post with new version with GUI and icon

mouser

  • First Author
  • Administrator
  • Joined in 2005
  • *****
  • Posts: 36,435
    • View Profile
    • Mouser's Software Zone on DonationCoder.com
    • Read more about this member.
    • Donate to Member
Re: 30SecondSilencer - add silence every 30 seconds to an mp3 file
« Reply #6 on: January 13, 2016, 11:43:08 AM »
just wanted to post and say how nice it is to see when a request and a coder come together so perfectly to produce something that is useful to others.