使用ffmpeg转换目录中的所有文件,然后使用PowerShell移动它们 [英] Convert all files in a directory using ffmpeg and then move them using PowerShell

查看:70
本文介绍了使用ffmpeg转换目录中的所有文件,然后使用PowerShell移动它们的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想创建一个脚本,该脚本使用 ffmpeg-windows .为了生成目录中所有文件的列表,我创建了一个.ps1-script generate-list.ps1 ,您可能想使用它.我的powershell脚本必须执行什么操作才能对文件夹video_old中的每个项目执行以下代码,并在转换后将其移至video_new?

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 .. 

目录如下:

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

推荐答案

我认为您不需要带有文件名的中间列表;相反,使用单个管道,其中 Get-ChildItem ForEach-Object cmdlet:

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)"
}

这篇关于使用ffmpeg转换目录中的所有文件,然后使用PowerShell移动它们的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆