Forum Discussion
Converting video with DTS to AC3 using FFMpeg & PowerShell
Script A with Errors
PS C:\WINDOWS\system32> $source = Get-ChildItem -path "D:\convert*" -Recurse -Include *.mkv
PS C:\WINDOWS\system32>
PS C:\WINDOWS\system32>
PS C:\WINDOWS\system32> $ffpath = "C:\Windows\System32\ffmpeg.exe"
PS C:\WINDOWS\system32>
PS C:\WINDOWS\system32>
PS C:\WINDOWS\system32> $DirOut = "D:\converted"
PS C:\WINDOWS\system32> $output = Join-Path $DirOut -ChildPath ((Get-Item $source).basename + "_out.mkv")
Join-Path : Cannot convert 'System.Object[]' to the type 'System.String' required by parameter 'ChildPath'. Specified
method is not supported.
At line:1 char:40
+ ... in-Path $DirOut -ChildPath ((Get-Item $source).basename + "_out.mkv")
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (:) [Join-Path], ParameterBindingException
+ FullyQualifiedErrorId : CannotConvertArgument,Microsoft.PowerShell.Commands.JoinPathCommand
PS C:\WINDOWS\system32>
PS C:\WINDOWS\system32>
PS C:\WINDOWS\system32> & $ffpath -i $source -map 0 -vcodec copy -scodec copy -acodec ac3 -b:a 640k $output -loglevel 8 -stats
Script B with errors
PS C:\WINDOWS\system32> :: convert all mkv files in a source Folder to mkv with AC3 using ffmpeg
>> :: eg. source T:\Old mkvs and eg.destination D:\New mkvs
>>
>> :-----------------------------------------------------------------------------------------------------------------------------------
>> :: first edit the two Directory values for the Source and Destination "and" the path of ffmpeg
>> :-----------------------------------------------------------------------------------------------------------------------------------
>>
>> SET Source_Files_Dir=D:\convert
>> SET Converted_Files_Dir=R:\Sons.of.Anarchy
>> SET ffmpeg=C:\Windows\System32\ffmpeg.exe
>>
>> cd /d %Converted_Files_Dir%
>> for /F "delims=" %%a in ('dir /b /s "%Source_Files_Dir%"\*.mkv') do (
>> "%ffmpeg%" -i "%%a" -map 0 -an -vcodec copy -scodec copy -acodec ac3 -b:a 640k "%%~na_out.mkv" -loglevel 8 -stats
>> )
>> pause
>> exit
At line:13 char:4
+ for /F "delims=" %%a in ('dir /b /s "%Source_Files_Dir%"\*.mkv') do (
+ ~
Missing opening '(' after keyword 'for'.
At line:14 char:12
+ "%ffmpeg%" -i "%%a" -map 0 -an -vcodec copy -scodec copy -acodec ac3 ...
+ ~~
Unexpected token '-i' in expression or statement.
At line:14 char:15
+ "%ffmpeg%" -i "%%a" -map 0 -an -vcodec copy -scodec copy -acodec ac3 ...
+ ~~~~~
Unexpected token '"%%a"' in expression or statement.
At line:14 char:14
+ "%ffmpeg%" -i "%%a" -map 0 -an -vcodec copy -scodec copy -acodec ac3 ...
+ ~
Missing closing ')' in expression.
At line:15 char:1
+ )
+ ~
Unexpected token ')' in expression or statement.
+ CategoryInfo : ParserError: (:) [], ParentContainsErrorRecordException
+ FullyQualifiedErrorId : MissingOpenParenthesisAfterKeyword
PS C:\WINDOWS\system32>
$ffpath = "C:\Windows\System32\ffmpeg.exe"
$DirOut = "D:\converted"
foreach ($sourcefile in $source) {
$output = Join-Path $DirOut -ChildPath ((Get-Item $sourcefile).basename + "_out.mkv")
& $ffpath -i $sourcefile -map 0 -vcodec copy -scodec copy -acodec ac3 -b:a 640k $output -loglevel 8 -stats
}
The second script is not PowerShell but batch/cmd, you should save the script in a .cmd file and try to run that...
- Reddwarf4everMar 14, 2022Copper Contributor
thank you
How does script A know the source folder I.e. Convert ?
$ffpath = "C:\Windows\System32\ffmpeg.exe"
$DirOut = "D:\converted"
foreach ($sourcefile in $source) {
$output = Join-Path $DirOut -ChildPath ((Get-Item $sourcefile).basename + "_out.mkv")
& $ffpath -i $sourcefile -map 0 -vcodec copy -scodec copy -acodec ac3 -b:a 640k $output -loglevel 8 -stats
}πππ
- Mar 14, 2022Forgot to put this line in my post, it should be the first line
$source = Get-ChildItem -path "D:\convert*" -Recurse -Include *.mkv- Reddwarf4everMar 14, 2022Copper Contributor
Well, Script A worked perfectly Thanks
Script B in a CMD window did nothing, sat there with a flashing cursor ???
does it get too complicated to create folders in the converted folder the same as the convert folder, so the files are converted into like for like folders ?
if itβs complicated I wonβt trouble you, just a thought.
thanks again