如何在 swift 中将 mp4 文件的前两位更改为 00、00?

How can I change the first two bits of an mp4 file to 00, 00 in swift?

我正在尝试将 mp4 文件的前两位更改为 00、00 以将其更改回正常/工作状态。从API下载了mp4文件后,发现不能播放,怪怪的,于是上网查了一下有人说是编码的,把前两位改成0就可以了! (确实如此,但是)我不知道如何在 swift 中做到这一点,我们将不胜感激!

我知道怎么做了!这是代码:

import UIKit
import AVFoundation



// URL to a mp4 file called videoFile located in the project's folder:
let videoURL = URL(string: Bundle.main.path(forResource: "videoFile", ofType: "mp4")!)



// Func for "decoding" (changing it's 2 first bytes to 0):
func changeFirstTwoBytesOfFile(fileURL: URL) {

    var fileData = fileURL.dataRepresentation

    // Printing first 4 bytes of the unchanged file for checking:
    print("Bytes before change:")

    print(fileData[0])
    print(fileData[1])
    print(fileData[2])
    print(fileData[3])

    print("")
    print("")



    // Changing it's 2 first bytes to 0
    fileData[0] = 0
    fileData[1] = 0



    // Printing the changed file's bytes to check if the change took place:
    print("Bytes after change:")

    print(fileData[0])
    print(fileData[1])
    print(fileData[2])
    print(fileData[3])
}


changeFirstTwoBytesOfFile(fileURL: videoURL!)