Files
web/scripts/transcode-promotion-videos.ps1

41 lines
1.4 KiB
PowerShell
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# 将 web\promotion\social 下产品视频从 .mov 转为网页通用 .mp4H.264 + AACfaststart
# 依赖:已安装 ffmpeg 并在 PATH 中Windows: https://www.gyan.dev/ffmpeg/builds/ 或 winget install ffmpeg
$ErrorActionPreference = "Stop"
$Root = Split-Path -Parent $PSScriptRoot
$Dir = Join-Path $Root "web\promotion\social"
$ffmpeg = Get-Command ffmpeg -ErrorAction SilentlyContinue
if (-not $ffmpeg) {
Write-Host "未找到 ffmpeg。请安装并加入 PATHhttps://ffmpeg.org/download.html" -ForegroundColor Red
exit 1
}
$files = @(
"video-calc-demo-1.mov",
"video-calc-demo-2.mov",
"video-aiword.mov",
"video-voice-office.mov",
"video-invoice-ai.mov"
)
foreach ($f in $files) {
$src = Join-Path $Dir $f
$base = [System.IO.Path]::GetFileNameWithoutExtension($f)
$dst = Join-Path $Dir "$base.mp4"
if (-not (Test-Path -LiteralPath $src)) {
Write-Host "[跳过] 无源文件: $src" -ForegroundColor Yellow
continue
}
Write-Host "[转码] $src -> $dst"
& ffmpeg -y -i $src `
-c:v libx264 -profile:v high -pix_fmt yuv420p `
-c:a aac -b:a 128k `
-movflags +faststart `
$dst
if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }
Write-Host "[完成] $dst" -ForegroundColor Green
}
Write-Host "全部处理结束。请部署生成的 .mp4确认后可删除本地 .mov可选" -ForegroundColor Cyan