[PConline 資訊]如果你是一名音樂發(fā)燒友,那么應(yīng)該知道Flac這種常見的無損音樂格式。Flac音樂文件支持metadata,用戶可以編輯metadata,讓音樂文件帶有藝術(shù)家、所屬專輯、音軌等等信息。通常來說,metadata和音頻數(shù)據(jù)并不相關(guān),修改metadata并不會(huì)影響音頻本身。但是,近日微軟官方公布了Win10中存在一個(gè)Bug,在Win10中用資源管理器修改Flac文件的metadata,竟會(huì)導(dǎo)致音頻的損壞! 根據(jù)Windows Latest的報(bào)道,微軟最新發(fā)布的一份支持文件披露,如果在Win10的2004或者更高版本中,使用文件資源管理器修改Flac音樂文件的metadata,就會(huì)損耗Flac音頻文件。這個(gè)Bug在Win10專業(yè)版、家庭版、企業(yè)版、工作站版乃至其他版本的Win10中均有出現(xiàn)。 根據(jù)微軟本月早些時(shí)候發(fā)布的支持文件,Win10的文件資源管理器導(dǎo)致了這個(gè)錯(cuò)誤,它破壞了Flac文件頭包含的ID3框架也就是metadata,而這個(gè)ID3框架負(fù)責(zé)存儲(chǔ)音頻的注釋,例如音樂標(biāo)題、藝術(shù)家、專輯、曲目編號(hào)等。在Win10上,F(xiàn)lac的處理程序忽視了ID3框架,該程序認(rèn)為Flac文件在使用4字節(jié)的文件頭,當(dāng)Flac文件被Win10編輯的時(shí)候,ID3框架被覆蓋了,導(dǎo)致沒有了開始代碼,導(dǎo)致了音樂播放器無法識(shí)別被修改后的文件。 因此,在Win10中,如果你直接用文件資源管理器修改Flac音樂文件的標(biāo)題、藝術(shù)家等metadata,會(huì)導(dǎo)致該文件無法播放。 幸運(yùn)的是,微軟已經(jīng)確定了Bug的根本原因,用戶可以通過Windows Update升級(jí)KB5003214補(bǔ)丁進(jìn)行修復(fù)。 在KB5003214補(bǔ)丁中,微軟確認(rèn)了上文提到的錯(cuò)誤已經(jīng)被修復(fù),修改了Flac的標(biāo)題、藝術(shù)家等metadata后,F(xiàn)lac不會(huì)再變得無法播放。而對(duì)于已經(jīng)損壞了的Flac文件,微軟則發(fā)布了一個(gè)PowerShell腳本來進(jìn)行修復(fù),運(yùn)行該腳本后Flac文件即可重新播放,不過已經(jīng)從ID3框架中丟失了的metadata信息并不能恢復(fù)。 下面是利用PowerShell腳本修復(fù)Flac文件的具體方法。 1、開啟記事本; 2、復(fù)制以下字符,粘貼到記事本中: # 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、保存文件,在“另存為”對(duì)話框中,將目錄定位到你想要保存PowerShell腳本的位置; 4、在文件名輸入框中,輸入“FixFlacFiles.ps1”,將另存為文件的類型更改為Text Documents (*.txt); 5、進(jìn)入到你保存該P(yáng)owerShell腳本的目錄; 6、右鍵點(diǎn)擊剛剛保存的腳本,然后選擇“使用PowerShell運(yùn)行”; 7、出現(xiàn)提示時(shí),輸入無法播放的Flac文件的文件名,然后按下回車鍵。 微軟建議大家安裝本月推送的可選累積更新,以避免修改Flac文件metadata出現(xiàn)的問題。 |