Mar 13 2022 03:34 PM
I have a number of video files with DTS audio, I need to convert to AC3 Audio, without reprocessing the video. I have been given 2 scripts, the first one A-worked perfectly yesterday but today is throwing up errors, cant see why. the second script allows the source and target directories to be different, but that hasn't worked at all.
Have the video in 7 folders, each have 8 files. it would be good to convert the audio and duplicate the folders in the `converted` folder the same as in the convert folder, but is not essential.
i have attached the two scripts, I hope someone can help me resolve these, thanks
A
$source = Get-ChildItem -path "D:\convert*" -Recurse -Include *.mkv
$ffpath = "C:\Windows\System32\ffmpeg.exe"$DirOut = "D:\converted"
$output = Join-Path $DirOut -ChildPath ((Get-Item $source).basename + "_out.mkv")& $ffpath -i $source -map 0 -vcodec copy -scodec copy -acodec ac3 -b:a 640k $output -loglevel 8 -stats
B
:: 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
Mar 14 2022 01:15 AM
Mar 14 2022 08:29 AM
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>
Mar 14 2022 08:50 AM
Mar 14 2022 09:02 AM - edited Mar 14 2022 09:04 AM
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
}
8)8)8)
Mar 14 2022 09:06 AM
Mar 14 2022 09:08 AM - edited Mar 14 2022 01:50 PM
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
Mar 14 2022 05:26 PM
Mar 15 2022 08:13 AM
Mar 15 2022 08:18 AM
Mar 15 2022 08:30 AM
Mar 15 2022 08:31 AM