Page 1 of 1

Error convert video to mp3, closing bracket at the end of the resulting file's name

Posted: 10 Nov 2020 08:45
by mymicrosoftmylife
Hi.
I have created a Powershell script to help me extract the audio of a video file and output it to a mp3 file. The script worked but there is problem. The resulting output file has a closing bracket at the end of the file's name, that is the file's name is not "example_output_file.mp3" but "example_output_file.mp3}". I hope somebody can give the help.
Here is the script:

Code: Select all

$currentScriptPath = $PSScriptRoot Write-Host "Please press enter and choose the video file you want to extract audio from below" Pause Add-Type -AssemblyName System.Windows.Forms $mediaFileBrowser = New-Object System.Windows.Forms.OpenFileDialog -Property @{ Multiselect = $false # Multiple files can be chosen Filter = 'Videos (*.mkv,*.mp4)|*.mkv;*.mp4' # Specified file types } [void]$mediaFileBrowser.ShowDialog() $mediaFilePath = $null; If($mediaFileBrowser.FileNames -like "*\*") { $mediaFilePath = $mediaFileBrowser.FileName; $mediaFileBrowser.FileName #Lists selected files (optional) } Else { Write-Host "Cancelled by user" Exit } $mediaFileName = Split-Path -Path $mediaFilePath -leaf $mediaFileLocation = Split-Path -Path $mediaFilePath $mediaFileBaseName = (Get-Item -literalPath $mediaFilePath).BaseName $newFileSaveDestination = "$mediaFileLocation" + "\" + "[audio] " + $mediaFileBaseName + ".mp3" $inputMediaFileURI = ([system.uri]$mediaFilePath).AbsoluteUri $bitrate = 0 Do{ #ask user to input an integer for the bitrate of the resulting mp3 file Write-Host "Please input the audio bitrate for the extracted mp3 file" $bitrate = Read-Host "Enter the bitrate for the audio of the output file" } #loop the above step until user input an integer greater than 0 Until (($bitrate -match "^\d+$") -and ([Int]$bitrate -gt 0)) $argumentList = "-vvv $inputMediaFileURI --sout=`"#transcode{vcodec=none,acodec=mp3,ab=$bitrate,channels=2,samplerate=44100,scodec=none}:std{access=file{no-overwrite},mux=raw,dst=$newFileSaveDestination}`" --sout-all --sout-keep vlc://quit" $currentTime = Get-Date -Format "dddd MM/dd/yyyy HH:mm:ss.fff K" Write-Host "Begin video audio extract on $currentTime" Start-Process -NoNewWindow -FilePath "C:\Program Files\VideoLAN\VLC\vlc.exe" -ArgumentList "$argumentList" $currentTime = Get-Date -Format "dddd MM/dd/yyyy HH:mm:ss.fff K" Write-Host "Done video audio extract on $currentTime" Write-Host "The new mp3 file can be found at $newFileSaveDestination" Write-Host "Done"
Thanks.

Re: Error convert video to mp3, closing bracket at the end of the resulting file's name

Posted: 10 Nov 2020 12:12
by Hitchhiker
No need to write scripts to extract audio from a video file. You can just use the default Convert menu. See this thread which contains a screenshot of the menu: https://forum.videolan.org/viewtopic.ph ... 65#p510665

Re: Error convert video to mp3, closing bracket at the end of the resulting file's name

Posted: 10 Nov 2020 13:27
by mymicrosoftmylife
No need to write scripts to extract audio from a video file. You can just use the default Convert menu. See this thread which contains a screenshot of the menu: https://forum.videolan.org/viewtopic.ph ... 65#p510665
Yeah, I know but I have the work of converting the video downloaded from the net to mp3 often and I don't want to select the thing every time to change the bit rate of the thing, the script helped me save efforts and time. But what I'm asking is what's wrong with these the command in the script so that it didn't output the file with a correct name. Is it a false of me or it's just a glitch in the VLC application. Hope someone know.

Re: Error convert video to mp3, closing bracket at the end of the resulting file's name

Posted: 10 Nov 2020 14:25
by mederi