问题
I want to create a script that converts .mkv-files from x264 to x265 using ffmpeg-windows. To generate a list of all files in the directory I created a .ps1-script generate-list.ps1, you might want to use it. What must my powershell script be to execute the code stated below for each item in the folder video_old and move it to video_new after conversion?
del .\list.txt
cd .\video_old\
foreach ($i in Get-ChildItem .\*.mkv) {echo "file '$i'" >> "list.txt"}
move .\list.txt ..\
cd ..
The directory looks like this:
Application-folder
└ video_new
└ *the converted files should go here*
└ video_old
└ *the video files that need to be converted*
└ ffmpeg.exe
└ generate-list.ps1
and the code that should be executed for conversion is the following
ffmpeg -i input -c:v libx265 -x265-params lossless=1 FILENAME.mkv
回答1:
I don't think you need an intermediate list with filenames; instead, use a single pipeline in which the Get-ChildItem output (input files) is processed one by one, using the ForEach-Object cmdlet:
Get-ChildItem .\video_old -Filter *.mkv | ForEach-Object {
ffmpeg -i $_.FullName -c:v libx265 -x265-params lossless=1 ".\video_new\$($_.Name)"
}
来源:https://stackoverflow.com/questions/60907612/convert-all-files-in-a-directory-using-ffmpeg-and-then-move-them-using-powershel