Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- param (
- [Parameter(Mandatory = $true)][string]$inputFolder
- )
- Get-ChildItem -File -Recurse $inputFolder | ForEach-Object {
- $fullName = $_.fullname
- $cmdOutput = ffmpeg -i "$fullName" 2>&1
- #if no video or no audio, skip
- $hasVideo = $cmdOutput|Select-String -Pattern "Video:"
- $hasAudio = $cmdOutput|Select-String -Pattern "Audio:"
- if ($hasVideo -and $hasAudio) {
- #Is already h264
- $VideoCodec = "copy"
- $AudioCodec = "copy"
- $Video = $cmdOutput|Select-String -Pattern "Video:"|Select-String -Pattern "h264"
- if (!$Video) {
- $VideoCodec = "libx264"
- }
- $Video = $cmdOutput|Select-String -Pattern "Video:"|Select-String -Pattern "High 10"
- if ($Video) {
- $VideoCodec = "libx264"
- }
- $Audio = $cmdOutput|Select-String -Pattern "Audio:"|Select-String -Pattern "aac"
- if (!$Audio) {
- $AudioCodec = "aac"
- }
- "$VideoCodec $AudioCodec $fullName"
- #is Already AAC
- if ($AudioCodec -ne "copy" -or $VideoCodec -ne "copy") {
- $newName = "$fullName.converted.avi"
- ffmpeg -i "$fullName" -y -f mp4 -acodec $AudioCodec -ab 192k -ac 2 -absf aac_adtstoasc -async 2 -vcodec $VideoCodec -vsync 0 -level 4.1 -qmax 22 -qmin 20 -x264opts no-cabac:ref=2 -threads 0 $newName
- Remove-Item -Path "$fullName"
- Rename-Item -Path $newName $fullName
- }
- }
- }
Add Comment
Please, Sign In to add comment