Skip to content

Instantly share code, notes, and snippets.

@woehrl01
Last active January 28, 2022 16:32
Show Gist options
  • Save woehrl01/68b8908b3d160d982cf5bdae349a1499 to your computer and use it in GitHub Desktop.
Save woehrl01/68b8908b3d160d982cf5bdae349a1499 to your computer and use it in GitHub Desktop.
Convert Video to Mp3 with Powershell and VLC Player
#based on http://www.andrewconnell.com/blog/Converting-all-your-non-MP3-files-to-MP3s-with-VLC-PowerShell-and-TagLib
#don't worry if there are errors shown in VLC this is perfectly fine.
#there isn't any progress shown. Simply wait for completion.
function ConvertToMp3 ($inputObject, [switch]$isRemoveOldFile = $false)
{
$vlc = "C:\Program Files\VideoLAN\VLC\vlc.exe"
$codec = 'mp3';
$oldFile = $inputObject;
$newFile = $inputObject.FullName.Replace("'", "\'").Replace($inputObject.Extension, ".$codec")
write-host $newFile
&"$vlc" -I dummy "$oldFile" ":sout=#transcode{acodec=$codec,vcodec=dummy}:standard{access=file,mux=raw,dst='\$newFile'}" vlc://quit | out-null
if($isRemoveOldFile){
Remove-Item $oldFile;
}
}
function ConvertAllToMp3([string] $sourcePath, [switch] $isRemoveOldFile = $false) {
write-host $sourcePath
Get-ChildItem "$sourcePath\*" -recurse -include *.mp4 | %{ ConvertToMp3 $_ $isRemoveOldFile}
}
ConvertAllToMp3 [path];
@woehrl01
Copy link
Author

Yes, the $_ is the iterator variable of the powershell for-each. Which is expressed here by the % command.

@tik9
Copy link

tik9 commented Oct 23, 2020

It does not work, something is blocking, but no errors. If I do the conversion from the gui vlc, it just works. I am using version 3.0.11

Vielleicht hast du noch ne Idee?

If not, I can use ffmpeg.

@woehrl01
Copy link
Author

@tik9 there is no output, it "just takes a while", so it looks blocked. Does calling the command line without the script, work for you?

@tik9
Copy link

tik9 commented Nov 23, 2020

In Lin12: $newFile = $.FullName.Replace("'", "'").Replace($.Extension, ".$codec")
Where is the $_ from? I get null.

@woehrl01
Copy link
Author

@tik9 that's strange, looks like I uploaded a bad version. It should be $inputObject of course on both places. Thank you for the hint!

@lefaro00
Copy link

lefaro00 commented Jan 28, 2022

Hi, I should be able to see vlc in the taskmanager, shouldn't I?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment