[PConline 資訊]如果你是一名音樂發燒友,那么應該知道Flac這種常見的無損音樂格式。Flac音樂文件支持metadata,用戶可以編輯metadata,讓音樂文件帶有藝術家、所屬專輯、音軌等等信息。通常來說,metadata和音頻數據并不相關,修改metadata并不會影響音頻本身。但是,近日微軟官方公布了Win10中存在一個Bug,在Win10中用資源管理器修改Flac文件的metadata,竟會導致音頻的損壞! 根據Windows Latest的報道,微軟最新發布的一份支持文件披露,如果在Win10的2004或者更高版本中,使用文件資源管理器修改Flac音樂文件的metadata,就會損耗Flac音頻文件。這個Bug在Win10專業版、家庭版、企業版、工作站版乃至其他版本的Win10中均有出現。 根據微軟本月早些時候發布的支持文件,Win10的文件資源管理器導致了這個錯誤,它破壞了Flac文件頭包含的ID3框架也就是metadata,而這個ID3框架負責存儲音頻的注釋,例如音樂標題、藝術家、專輯、曲目編號等。在Win10上,Flac的處理程序忽視了ID3框架,該程序認為Flac文件在使用4字節的文件頭,當Flac文件被Win10編輯的時候,ID3框架被覆蓋了,導致沒有了開始代碼,導致了音樂播放器無法識別被修改后的文件。 因此,在Win10中,如果你直接用文件資源管理器修改Flac音樂文件的標題、藝術家等metadata,會導致該文件無法播放。 幸運的是,微軟已經確定了Bug的根本原因,用戶可以通過Windows Update升級KB5003214補丁進行修復。 在KB5003214補丁中,微軟確認了上文提到的錯誤已經被修復,修改了Flac的標題、藝術家等metadata后,Flac不會再變得無法播放。而對于已經損壞了的Flac文件,微軟則發布了一個PowerShell腳本來進行修復,運行該腳本后Flac文件即可重新播放,不過已經從ID3框架中丟失了的metadata信息并不能恢復。 下面是利用PowerShell腳本修復Flac文件的具體方法。 1、開啟記事本; 2、復制以下字符,粘貼到記事本中: # Copyright 2021 Microsoft # This script will repair a FLAC file that has been corrupted by Media Foundation in reference to KB5003430. # Refer to KB5003430 for further information param( [parameter(Mandatory=$true, HelpMessage="The path to the FLAC file that has been corrupted by Media Foundation", ValueFromRemainingArguments=$true)] [ValidateScript({ -not [String]::IsNullOrEmpty($_) -and (Test-Path $_) })] [String]$File ) # We need to back up the current file incase we have any errors $FileDirectory = Split-Path -Resolve $File $Filename = Split-Path -Leaf -Resolve $File $FullPath = Join-Path -Resolve $FileDirectory $Filename $Filename = [String]::Format("Backup_{0:yyyyMMdd_hhmmss}_{1}", [DateTime]::Now, $Filename) $BackupLocation = Join-Path $FileDirectory $Filename Write-Output "Microsoft FLAC Repair Tool. This tool will repair a FLAC audio file that was corrupted when editing its details." Write-Output "Affected File: $FullPath" Write-Output "A backup of the file will be made: $BackupLocation" Write-Output "Do you wish to continue?" $choice=$host.ui.PromptForChoice("Fixing FLAC Script", "Do you wish to continue", ('&Yes', '&No'), 1) function ParseStreamInfoMetadataBlock([System.IO.FileStream]$stream) { $blockType = $stream.ReadByte() $lastBlock = ($blockType -shr 7) -ne 0 $blockType = $blockType -band 0x7F if ($blockType -ne 0) { return $false } $blockSize = (($stream.ReadByte() -shl 16) -bor ($stream.ReadByte() -shl 8) -bor $stream.ReadByte()) if ($blockSize -lt 34) { return $false } $minAudioBlockSize = ($stream.ReadByte() -shl 8) -bor $stream.ReadByte() $maxAudioBlockSize = ($stream.ReadByte() -shl 8) -bor $stream.ReadByte() if ($minAudioBlockSize -lt 16 -or $maxAudioBlockSize -lt 16) { return $false } $minFrameSize = (($stream.ReadByte() -shl 16) -bor ($stream.ReadByte() -shl 8) -bor $stream.ReadByte()) $maxFrameSize = (($stream.ReadByte() -shl 16) -bor ($stream.ReadByte() -shl 8) -bor $stream.ReadByte()) $sampleInfo = (($stream.ReadByte() -shl 24) -bor ($stream.ReadByte() -shl 16) -bor ($stream.ReadByte() -shl 8) -bor $stream.ReadByte()) $sampleRate = $sampleInfo -shr 12 $channelCount = (($sampleInfo -shr 9) -band 0x7) + 1 $bitsPerSample = (($sampleInfo -shr 4) -band 0x1F) + 1 [UInt64]$sampleCount = (($stream.ReadByte() -shl 24) -bor ($stream.ReadByte() -shl 16) -bor ($stream.ReadByte() -shl 8) -bor $stream.ReadByte()) $sampleCount = (([UInt64]$sampleInfo -band 0xF) -shl 32) -bor $sampleCount $MD5HashBytes = New-Object byte[] 16 $stream.Read($MD5HashBytes, 0, $MD5HashBytes.Length) $MD5Hash = [Guid]($MD5HashBytes) if ($sampleRate -eq 0) { return $false } # Passing these checks means that we likely have a stream info header and can rebuild the file Write-Output "File Stream Information" Write-Output "Sample Rate: $sampleRate" Write-Output "Audio Channels: $channelCount" Write-Output "Sample Depth: $bitsPerSample" Write-Output "MD5 Audio Sample Hash: $MD5Hash" return $true } if ($choice -eq 0) { Copy-Item $FullPath -Destination $BackupLocation -Force $stream = [System.IO.File]::Open($FullPath, [System.IO.FileMode]::Open) $stream.Seek(4, [System.IO.SeekOrigin]::Begin) while ($stream.ReadByte() -eq 0) {} # We now need to figure out where a valid FLAC metadata frame begins # We are likely pointing to the last byte of the size member so we'll seek back 4 bytes and retry $flacDataStartPosition = $stream.Position - 4 $stream.Seek($flacDataStartPosition, [System.IO.SeekOrigin]::Begin) while (-not(ParseStreamInfoMetadataBlock($stream))) { $flacDataStartPosition = $flacDataStartPosition + 1 $stream.Seek($flacDataStartPosition, [System.IO.SeekOrigin]::Begin) } # Insert the start code $stream.Seek($flacDataStartPosition, [System.IO.SeekOrigin]::Begin) if (Test-Path "$FullPath.tmp") { Remove-Item "$FullPath.tmp" } $fixedStream = [System.IO.File]::Open("$FullPath.tmp", [System.IO.FileMode]::CreateNew) [byte[]]$startCode = [char[]]('f', 'L', 'a', 'C'); $fixedStream.Write($startCode, 0, $startCode.Length) $stream.CopyTo($fixedStream) $stream.Close() $fixedStream.Close() Move-Item -Force "$FullPath.tmp" $FullPath } 3、保存文件,在“另存為”對話框中,將目錄定位到你想要保存PowerShell腳本的位置; 4、在文件名輸入框中,輸入“FixFlacFiles.ps1”,將另存為文件的類型更改為Text Documents (*.txt); 5、進入到你保存該PowerShell腳本的目錄; 6、右鍵點擊剛剛保存的腳本,然后選擇“使用PowerShell運行”; 7、出現提示時,輸入無法播放的Flac文件的文件名,然后按下回車鍵。 微軟建議大家安裝本月推送的可選累積更新,以避免修改Flac文件metadata出現的問題。 |
正在閱讀:Win10竟會損壞用戶文件?教你解決這個BugWin10竟會損壞用戶文件?教你解決這個Bug
