以下指令运行在PowerShell终端中
批量截图仅当前目录下的所有
.mov视频0.5s处原始图片(带透明)
Get-ChildItem -Filter *.mov | ForEach-Object { ffmpeg -ss 0.5 -i "$($_.FullName)" -vframes 1 -pix_fmt rgba -y "$($_.BaseName).png" }制指定文件转为
HAP编码并带透明通道
ffmpeg -i "filename.mov" -c:v hap -format hap_alpha "filename_HAP_Alpha.mov" 当前目录下的所有
.mp4保留视频编码,修改视频容器为.mov
Get-ChildItem *.mp4 | ForEach-Object { ffmpeg -i "$($_.FullName)" -c copy -y "$($_.BaseName).mov" }把指定文件转码为hap透明通道格式并自动覆盖源文
$n="xxx.mov"; ffmpeg -i "$n" -c:v hap -format hap_alpha "tmp_$n"; if($?) { Move-Item "tmp_$n" "$n" -Force }遍历当前文件夹下所有的
.mov文件,逐个转换并替换。
Get-ChildItem "*.mov" | ForEach-Object {
$original = $_.Name
$temp = "tmp_" + $_.Name
Write-Host "正在处理: $original ..." -ForegroundColor Cyan
# 执行转换 (隐藏冗余日志,只显示错误)
ffmpeg -i "$original" -c:v hap -format hap_alpha "$temp" -hide_banner -loglevel error
# 如果转换成功($?为真),则覆盖源文件
if ($?) {
Move-Item "$temp" "$original" -Force
Write-Host "-> 完成并替换: $original" -ForegroundColor Green
} else {
Write-Host "-> 转换失败,跳过: $original" -ForegroundColor Red
if (Test-Path "$temp") { Remove-Item "$temp" }
}
Write-Host "----------------------"
}自动计算每一段视频的中间时间点,并截取一张带透明通道的 PNG 图片。
# 确保能找到 ffprobe,通常它和 ffmpeg 在同一目录下
Get-ChildItem "*.mov" | ForEach-Object {
$videoPath = $_.FullName
$imageName = $_.BaseName + ".png"
Write-Host "正在分析: $($_.Name)..." -NoNewline -ForegroundColor Cyan
# 1. 获取视频时长(秒)
$duration = ffprobe -v error -show_entries format=duration -of default=noprint_wrappers=1:nokey=1 "$videoPath" 2>$null
if ($duration -and $duration -match "^[\d\.]+$") {
# 2. 计算中间时间点
$midPoint = [math]::Round([double]$duration / 2, 3)
# 3. 在中间点截图 (-ss 放在 -i 前面是为了加速定位)
ffmpeg -ss $midPoint -i "$videoPath" -frames:v 1 -c:v png "$imageName" -y -hide_banner -loglevel error
if ($?) {
Write-Host " -> 已截图 [$midPoint 秒]: $imageName" -ForegroundColor Green
} else {
Write-Host " -> 截图失败" -ForegroundColor Red
}
} else {
Write-Host " -> 无法获取时长,跳过" -ForegroundColor Red
}
}
评论