Last active
January 22, 2024 17:51
-
-
Save santarinto/6f7301d7eaf25623a97695fb52d4e353 to your computer and use it in GitHub Desktop.
Convert webm -> mp4 , webp,jpg -> png
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$startTime = Get-Date | |
$webmConvertedCount = 0 | |
$jpgConvertedCount = 0 | |
$webpConvertedCount = 0 | |
$totalFilesConverted = 0 | |
$initialSizeMB = 0 | |
$finalSizeMB = 0 | |
$webmFiles = Get-ChildItem -Path .\ -Filter *.webm -Recurse | |
foreach ($file in $webmFiles) { | |
$initialSizeMB += ($file.Length / 1MB) | |
$outputFile = $file.FullName -replace "\.webm$", ".mp4" | |
& ffmpeg -i $file.FullName -c:v libx264 -c:a aac -strict experimental $outputFile | |
if (Test-Path $outputFile) { | |
$finalSizeMB += ((Get-Item $outputFile).Length / 1MB) | |
Remove-Item -Path $file.FullName -Force | |
$webmConvertedCount++ | |
} | |
} | |
$jpgFiles = Get-ChildItem -Path .\ -Include *.jpg, *.jpeg -Recurse | |
foreach ($file in $jpgFiles) { | |
$initialSizeMB += ($file.Length / 1MB) | |
$outputFile = $file.FullName -replace "\.jpg$", ".png" | |
& ffmpeg -i $file.FullName $outputFile | |
if (Test-Path $outputFile) { | |
$finalSizeMB += ((Get-Item $outputFile).Length / 1MB) | |
Remove-Item -Path $file.FullName -Force | |
$jpgConvertedCount++ | |
} | |
} | |
$webpFiles = Get-ChildItem -Path .\ -Filter *.webp -Recurse | |
foreach ($file in $webpFiles) { | |
$initialSizeMB += ($file.Length / 1MB) | |
$outputFile = $file.FullName -replace "\.webp$", ".png" | |
& ffmpeg -i $file.FullName -vframes 1 $outputFile | |
if (Test-Path $outputFile) { | |
$finalSizeMB += ((Get-Item $outputFile).Length / 1MB) | |
Remove-Item -Path $file.FullName -Force | |
$webpConvertedCount++ | |
} | |
} | |
$endTime = Get-Date | |
$duration = $endTime - $startTime | |
$totalFilesConverted = $webmConvertedCount + $jpgConvertedCount + $webpConvertedCount | |
$differenceMB = $finalSizeMB - $initialSizeMB | |
Write-Host "Conversion completed!" | |
Write-Host ".webm files converted to .mp4: $webmConvertedCount" | |
Write-Host ".jpg files converted to .png: $jpgConvertedCount" | |
Write-Host ".webp files converted to .png: $webpConvertedCount" | |
Write-Host ("Total files converted: {0}" -f $totalFilesConverted) | |
Write-Host ("Initial data processed: {0:N2} MB" -f $initialSizeMB) | |
Write-Host ("Final data size after conversion: {0:N2} MB" -f $finalSizeMB) | |
Write-Host ("Difference in size: {0:N2} MB" -f $differenceMB) | |
Write-Host ("Script execution time: {0:N2} seconds" -f $duration.TotalSeconds) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment