Let’s just say you have one big audio file which you want to extract parts of it into individual files. Typical usecase is youtube jukebox videos where you would get a song name and the start time of the song. After downloading the audio file, which is one big file, you can use the below bash script to extract the individual files:
Here we use ffmpeg to accomplish this task, download ffmpeg from here and have it on your environment path.

Save the following file with any file name ending in .ps1 extension.
While trying to run the powershell script, if you get “execution of scripts is disabled on this system.” error, then do the following:
Set-ExecutionPolicy RemoteSigned
Read the comments in the following code to do some minor changes that suits your needs.

#replace the following with file names that you need
$names= "file1","file2"
 
#these are the start times of the audio, observe one extra last element here, that is the total audio length
$timelength = "00:00:00","00:04:59","00:08:23"
 
for($i=0;$i-le $names.length-1;$i++){ 
 
	$output = $names[$i]+".mp3"
 
	$Time1 = $timelength[$i]
	$Time2 = $timelength[$i+1]
 
	$TimeDiff = New-TimeSpan $Time1 $Time2
 
	$Hrs = $TimeDiff.Hours * 3600
	$Mins = $TimeDiff.Minutes * 60
	$Secs = $TimeDiff.Seconds
 
	$tot = $Hrs+$Mins+$Secs
 
	#replace input.mp3 with your audio file
	ffmpeg -i input.mp3 -ss $timelength[$i] -t $tot -acodec copy $output
}
“You might not know it, but chances are you use ffmpeg in some or the other way everyday”
-Rushi

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes:

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>