Created
May 4, 2021 08:16
-
-
Save Alistair1231/e6fa9a6e06ed294c8a5f5b60a9c3f0f9 to your computer and use it in GitHub Desktop.
split audio files into same length parts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Split MP3/M4A/M4B files into 5 min parts | |
# Known Issues: | |
# recursive folders don't work. seperate files I also screwed up. Just give it 1 folder, or use _splitAll.ps1 for multiple folders. | |
# afterwards you can search in the folder with everything (https://www.voidtools.com/support/everything/) | |
# like this : "D:\!!Downloads\!audiobook\" !_ to find everything without an underscore (_) which should most likely only be the | |
# original files and delete them | |
# if windows refuses to execute the scripts try something like this in an admin powershell (Win+X A): | |
# Set-ExecutionPolicy Unrestricted | |
for ($i = 0; $i -lt $args.Count; $i++) { | |
# iterate through all given parameters | |
if (Test-Path -Path $args[$i] -PathType Container) { | |
# check if fodler | |
$folderFiles = Get-ChildItem $args[$i] | |
for ($j = 0; $j -lt $folderFiles.Count; $j++) { | |
$path = Get-Location # save current fodler | |
Set-Location $args[$i] # change to working dir | |
$base = (Get-Item $folderFiles[$j]).BaseName # filename w/o extension | |
$ext = (Get-Item $folderFiles[$j]).Extension # extension with period i.e. .mp3 | |
# m4b is for single file audio books, m4a for single files both use aac codec | |
if ($ext -eq ".m4b") { | |
$ext = ".m4a" | |
} | |
ffmpeg -i $folderFiles[$j] -f segment -segment_time 300 -c copy "$base""_%03d$ext" # split into 5 minute parts | |
Set-Location $path # go to starting folder | |
} | |
} | |
else { | |
# for files instead of folders | |
$path = Get-Location # save current fodler | |
Set-Location $args[$i] # change to working dir | |
$base = (Get-Item $folderFiles[$j]).BaseName # filename w/o extension | |
$ext = (Get-Item $folderFiles[$j]).Extension # extension with period i.e. .mp3 | |
# m4b is for single file audio books, m4a for single files both use aac codec | |
if ($ext -eq ".m4b") { | |
$ext = ".m4a" | |
} | |
ffmpeg -i $args[$i] -f segment -segment_time 300 -c copy "$base""_%03d$ext" # split into 5 minute parts | |
Set-Location $path # go to starting folder | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# use Everything (https://www.voidtools.com/support/everything/) to copy list of folder names | |
$vals = @( | |
"D:\!!Downloads\!audio\The Witcher\Andrzej Sapkowski - Baptism of Fire The Witcher, Book 3 (Unabridged)" | |
"D:\!!Downloads\!audio\The Witcher\Andrzej Sapkowski - Blood of Elves The Witcher, Book 1 (Unabridged)" | |
"D:\!!Downloads\!audio\The Witcher\Andrzej Sapkowski - Lady of the Lake The Witcher, Book 5 (Unabridged)" | |
"D:\!!Downloads\!audio\The Witcher\Andrzej Sapkowski - Season of Storms (Unabridged)" | |
"D:\!!Downloads\!audio\The Witcher\Andrzej Sapkowski - Sword of Destiny (Unabridged)" | |
"D:\!!Downloads\!audio\The Witcher\Andrzej Sapkowski - The Last Wish (Unabridged)" | |
"D:\!!Downloads\!audio\The Witcher\Andrzej Sapkowski - The Tower of the Swallow The Witcher, Book 4 (Unabridged)" | |
"D:\!!Downloads\!audio\The Witcher\Andrzej Sapkowski - Time of Contempt The Witcher, Book 2 (Unabridged)" | |
"D:\!!Downloads\!audio\Robert Jordan - The Wheel of Time Series\Book 0 - New Spring (Unabridged)" | |
"D:\!!Downloads\!audio\Robert Jordan - The Wheel of Time Series\Book 1 - The Eye of the World (Unabridged)" | |
"D:\!!Downloads\!audio\Robert Jordan - The Wheel of Time Series\Book 10 - Crossroads of Twilight (Unabridged)" | |
"D:\!!Downloads\!audio\Robert Jordan - The Wheel of Time Series\Book 11 - Knife of Dreams (Unabridged)" | |
"D:\!!Downloads\!audio\Robert Jordan - The Wheel of Time Series\Book 12 - The Gathering Storm (Unabridged)" | |
"D:\!!Downloads\!audio\Robert Jordan - The Wheel of Time Series\Book 13 - Towers of Midnight (Unabridged)" | |
"D:\!!Downloads\!audio\Robert Jordan - The Wheel of Time Series\Book 14 - A Memory of Light (Unabridged)" | |
"D:\!!Downloads\!audio\Robert Jordan - The Wheel of Time Series\Book 2 - The Great Hunt (Unabridged)" | |
"D:\!!Downloads\!audio\Robert Jordan - The Wheel of Time Series\Book 3 - The Dragon Reborn (Unabridged)" | |
"D:\!!Downloads\!audio\Robert Jordan - The Wheel of Time Series\Book 4 - The Shadow Rising (Unabridged)" | |
"D:\!!Downloads\!audio\Robert Jordan - The Wheel of Time Series\Book 5 - The Fires of Heaven (Unabridged)" | |
"D:\!!Downloads\!audio\Robert Jordan - The Wheel of Time Series\Book 6 - Lord of Chaos (Unabridged)" | |
"D:\!!Downloads\!audio\Robert Jordan - The Wheel of Time Series\Book 7 - A Crown of Swords (Unabridged)" | |
"D:\!!Downloads\!audio\Robert Jordan - The Wheel of Time Series\Book 8 - The Path of Daggers (Unabridged)" | |
"D:\!!Downloads\!audio\Robert Jordan - The Wheel of Time Series\Book 9 - Winter's Heart (Unabridged)" | |
"D:\!!Downloads\!audio\Mistborn\Brandon Sanderson - The Final Empire Mistborn, Book 1 (Unabridged)" | |
"D:\!!Downloads\!audio\Mistborn\Brandon Sanderson - The Hero of Ages Mistborn, Book 3 (Unabridged)" | |
"D:\!!Downloads\!audio\Mistborn\Brandon Sanderson - The Well of Ascension Mistborn, Book 2 (Unabridged)" | |
) | |
foreach ($val in $vals) { | |
Invoke-Expression -Command ".\_split.ps1 '$val'" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment