# Get a list of MKV files in the current directory $mkvFiles = Get-ChildItem -Filter *.mkv # Loop through each MKV file foreach ($mkvFile in $mkvFiles) { # Extract the episode information from the MKV filename $episodeInfo = [regex]::match($mkvFile.Name, 's\d{2}e\d{2}').Value # Check if we found episode information if ($episodeInfo -ne "") { # Get the subtitle file associated with the MKV $subtitleFile = Get-ChildItem -Filter "*$episodeInfo*.srt" -Recurse # Check if the subtitle file exists if ($subtitleFile -ne $null) { # Construct the new subtitle file name $newSubtitleName = "$($mkvFile.BaseName).srt" # Rename the subtitle file Rename-Item -Path $subtitleFile.FullName -NewName $newSubtitleName Write-Host "Renamed $($subtitleFile.Name) to $newSubtitleName" } else { Write-Host "Subtitle file not found for $mkvFile" } } else { Write-Host "Episode information not found in the filename: $($mkvFile.Name)" } } # Convert all 265 mkvs to 264 Get-ChildItem .\ -Filter *.mkv | ForEach-Object { Write-Host "Converting $($_.Name)" ffmpeg -i $_.Name -map 0 -c:v libx264 -crf 18 -vf format=yuv420p -c:a copy "x264-$($_.Name)" }