4
2
I know I can search for files (pictures, videos) having specific dimensions, using width:1920, height:1080
.
But how do I search for files having, say, 16:9 aspect ratio, in Windows 7?
4
2
I know I can search for files (pictures, videos) having specific dimensions, using width:1920, height:1080
.
But how do I search for files having, say, 16:9 aspect ratio, in Windows 7?
3
This is not possible with Windows 7 Explorer search
However, here is an alternative relying on integral Windows parts
It reads in every image from a given root folder, divides images height through width, compares the result with e.g 16/10
and outputs the full path when the ratio matches
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
}
}
For images (PowerShell 2.0) - Improved version for cropped / non-standard aspect ratios
$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
}
}
Say, you have a folder with pictures where most of them were cropped. So they don't have a standard aspect ratio like 16:9. For them, this script always searches the closest match of a standard aspect ratio. You can expand them at $AllRatios = (16/10),(16/9),(4/3),(5/4),(21/10),(21/9)
if you want
The other 3 variables should be self-explaining. $folder
is your folder where you want to search in. $searchRatio
is the aspect ratio you are looking for and $fileTypes
defines which picture types you are interested in
$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
}
}
You can utilize ffmpeg's ffprobe to retrieve all informations from videos
ffprobe -loglevel quiet -show_streams -print_format flat=h=0 input.mp4
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
Next, we use Regex to filter out the aspect ratio (13:7
in our example)
how does windows explorer read width/height values? because in the explorer.exe's column "width/height" i read the videos' width/height fine. maybe reading that does the trick – Wes – 2014-12-09T22:43:06.980
This is great for images stored in one of the standard sizes, which will always be an exact match for a standard aspect ratio. For images that have been manually cropped, they will often be close to a standard aspect ratio but not an exact match. Can this approach be modified to handle a "tolerance" range for aspect ratio? (e.g., rounding before comparison, testing the difference as LT X, or testing that the value falls between an upper and lower limit?) – fixer1234 – 2014-12-11T09:28:03.827
I'm not sure you can, I can also not find this aspect ratio in the property details of a picture. Those properties you can use as a search criteria, I don't know of any other way. – Yoh – 2014-12-09T21:42:39.060
You can ballpark it with Google. On the advanced image search page https://www.google.com/advanced_image_search, you can select an approximate aspect ratio (tall, square, wide, panoramic). Not sure if this applies to Google searches on your PC.
– fixer1234 – 2014-12-09T21:42:53.7032BTW: you can also look for dimensions using 'dimensions:1920x1080' instead of the width and height properties separately. – Yoh – 2014-12-09T21:53:40.503
According to http://msdn.microsoft.com/en-us/library/aa965711%28v=vs.85%29.aspx (which might be dated), aspect ratio is not one of the defined search parameters. Other than a third party utility, you would need to do a series of searches for specific image dimensions.
– fixer1234 – 2014-12-09T22:02:29.920