Wes*_*Wes 5 windows-7 windows-search
我知道我可以搜索文件(图片,视频),具有特定的尺寸,使用width:1920, height:1080。
但是如何在 Windows 7 中搜索具有 16:9 纵横比的文件?
Windows 7 资源管理器搜索无法做到这一点
然而,这里有一个依赖于集成 Windows 部件的替代方案
它从给定的根文件夹中读取每个图像,将图像的高度除以宽度,将结果与eg进行比较,16/10并在比率匹配时输出完整路径
Get-Childitem "D:\MyPictures" -include @("*.jpg","*.png") -recurse | Where {
$img = New-Object System.Drawing.Bitmap $_.FullName
if ($img.Width / $img.Height -eq 16/10 -or
$img.Height / $img.Width -eq 16/10) {
Write-Host $_.FullName
}
}
Run Code Online (Sandbox Code Playgroud)
对于图像 (PowerShell 2.0) - 裁剪/非标准长宽比的改进版本
$folder = "C:\Users\Public\Pictures\Sample Pictures"
$searchRatio = 4/3
$AllRatios = (16/10),(16/9),(4/3),(5/4),(21/10),(21/9)
$filetypes = @("*.jpg","*.png","*.bmp")
Clear-Host
Get-Childitem $folder -include $filetypes -recurse | foreach {
$img = New-Object System.Drawing.Bitmap $_.FullName
if ($img.Width -gt $img.Height){ $fileRatio = $img.Width / $img.Height }
else {$fileRatio = $img.Height / $img.Width}
$differences = $AllRatios | %{ [math]::abs($_ - $fileRatio) }
$bestmatch = $differences | measure -Minimum
$index = [array]::IndexOf($differences, $bestmatch.minimum)
$closestRatio = $($AllRatios[$index])
if ($closestRatio -eq $searchRatio) {
Write-Host $fileRatio `t`t $_.FullName
}
}
Run Code Online (Sandbox Code Playgroud)
假设您有一个包含图片的文件夹,其中大部分图片都被裁剪了。所以他们没有像 16:9 这样的标准宽高比。对于他们来说,这个脚本总是搜索最接近的标准宽高比匹配。$AllRatios = (16/10),(16/9),(4/3),(5/4),(21/10),(21/9)如果您愿意,您可以将它们扩展为
其他 3 个变量应该是不言自明的。$folder是您要搜索的文件夹。$searchRatio是您要查找的宽高比,$fileTypes定义您感兴趣的图片类型
$folder = "D:\My Videos\*"
$ffprobe = "D:\ffmpeg\ffprobe.exe"
$searchRatio = "13:7"
$filetypes = @{"*.avi","*.mp4"}
Clear-Host
Get-ChildItem $folder -include $filetypes -recurse | foreach {
$details = & $ffprobe -loglevel quiet -show_streams -print_format flat=h=0 $_.Fullname
$fileratio = $details | Select-String '(?<=stream.0.display_aspect_ratio=")\d+:\d+' |
Foreach {$_.Matches} | ForEach-Object {$_.Value}
if ($fileratio -eq $searchRatio ) {
Write-Host $fileratio `t`t $_.FullName
}
}
Run Code Online (Sandbox Code Playgroud)
您可以利用ffmpeg 的ffprobe 检索视频中的所有信息
ffprobe -loglevel quiet -show_streams -print_format flat=h=0 input.mp4
Run Code Online (Sandbox Code Playgroud)
stream.0.index=0
stream.0.codec_name="mpeg4"
stream.0.codec_long_name="MPEG-4 part 2"
stream.0.profile="Advanced Simple Profile"
stream.0.codec_type="video"
stream.0.codec_time_base="911/21845"
stream.0.codec_tag_string="XVID"
stream.0.codec_tag="0x44495658"
stream.0.width=624
stream.0.height=336
stream.0.has_b_frames=1
stream.0.sample_aspect_ratio="1:1"
stream.0.display_aspect_ratio="13:7"
stream.0.pix_fmt="yuv420p"
stream.0.level=5
Run Code Online (Sandbox Code Playgroud)接下来,我们使用正则表达式过滤掉长宽比(13:7在我们的示例中)
| 归档时间: |
|
| 查看次数: |
7677 次 |
| 最近记录: |