本文使用ffmpeg批量获取哔哩哔哩视频截图
# 配置参数
$videoDir = "C:\Users\win10\Downloads" # 视频所在目录,根据实际修改
$outputRoot = "D:\定点数乘法运算实现\湖科大教书匠 计算机组成原理第二章" # 输出根目录,根据实际修改
$interval = 30 # 每30秒提取1帧
$resolution = "1920x1080" # 输出分辨率
$format = "png" # 输出格式
# 视频-子目录映射(按顺序对应,需手动维护,确保数量匹配)
$subDirs = @(
"3-3-1",
"3-3-2",
"3-3-3",
"3-3-4",
"3-3-5"
)
# 确保 FFmpeg 已添加到环境变量,或替换为完整路径,如 "C:\ffmpeg\bin\ffmpeg.exe"
$ffmpegPath = "ffmpeg"
# 遍历视频文件(按名称顺序匹配子目录)
$index = 0
Get-ChildItem -Path $videoDir -Filter "计算机组成原理微课堂 (*).mp4" | ForEach-Object {
$videoFile = $_.FullName
$subDir = $subDirs[$index]
if (-not $subDir) {
Write-Host "无匹配子目录: $videoFile" -ForegroundColor Yellow
$index++
return
}
# 拼接输出路径并创建目录
$outputDir = Join-Path -Path $outputRoot -ChildPath $subDir
if (-not (Test-Path $outputDir)) {
New-Item -ItemType Directory -Path $outputDir | Out-Null
}
# 构造 FFmpeg 命令参数
$ffmpegArgs = @(
"-i", "`"$videoFile`"",
"-vf", "select='not(mod(t,$interval))',setpts=N/FRAME_RATE/TB",
"-vsync", "vfr",
"-s", $resolution,
"-colorspace", "bt709",
"`"$outputDir\frame_%04d.$format`""
)
# 执行 FFmpeg 命令
Write-Host "开始处理: $videoFile → $outputDir" -ForegroundColor Cyan
& $ffmpegPath $ffmpegArgs 2>&1 | ForEach-Object {
if ($_ -is [System.Management.Automation.ErrorRecord]) {
Write-Host "错误: $_" -ForegroundColor Red
} else {
Write-Host $_
}
}
Write-Host "处理完成: $videoFile → $outputDir" -ForegroundColor Green
$index++
}
Write-Host "全部视频处理完成!" -ForegroundColor Magenta
**方法:使用浏览器插件:快速bilibili下载助手
下载视频后再通过PowerShell 进入命令行 运行ffmpeg ffmpeg提前下载安装配置好了
**
**这个应该不算侵权 。。。。 整理下来方便复习 (和手动截图也差不了太多 哈哈》》》》》) **