Adding metadata to the generated audio file

I am creating an audio file programmatically, and I would like to add metadata to it, such as title and artist. I'm not particularly interested in the format in which the file is recorded, while AVPlayer reads it and sends it to the gaming device. (The goal is to send this generated sound and its track name to a Bluetooth device. I am pleased to learn simpler ways to achieve this on an iPhone that does not require writing a file or adding metadata directly to the file.)

So far, I have found that AVAssetWriter often simply deletes metadata that it does not understand without generating errors, so I stumble a bit to find which combinations of file formats and keys are acceptable. So far, I have not found a file format that I can automatically generate, that AVAssetWriter will add any metadata. For instance:

let writer = try AVAssetWriter(outputURL: output, fileType: .aiff) let title = AVMutableMetadataItem() title.identifier = .commonIdentifierTitle title.dataType = kCMMetadataBaseDataType_UTF8 as String title.value = "The Title" as NSString writer.metadata = [title] // setup the input and write the file. 

I did not find any combination of identifiers or fileTypes (which I can actually generate) that will include this metadata in the file.

My current approach is to create the file as AIFF and then use AVAssetExportSession to rewrite it as m4a. Using this, I was able to add enough metadata that iTunes will display the name. However, the Finder "File Info" cannot read the title (which it does for iTunes m4a files). My assumption is that if it does not even appear in the Info file, it will not be sent via Bluetooth (I will check it soon, but I don’t have the piece of hardware that I need).

Studying iTunes m4a files, I found some tags that I cannot recreate using AVMetadataItem. For example, the sort name (sonm). I do not know how to write tags that are not one of the known identifiers (and I tested all 263 AVMetadataIdentifiers).

Against this background, my main questions are:

  • What metadata tags are read by AVPlayer and sent to Bluetooth devices (i.e. AVRCP)?
  • Can I write metadata directly from AVAssetWriter to a file format that supports Linear PCM (or some other easy-to-create format)?
  • Given a known tag / value that does not match any of AVMetadataIdentifiers), is it possible to write it to AVAssetExportSession?

I will look at third-party id3 frameworks later, but if possible, I would like to achieve this using AVFoundation (or another built-in framework).

+5
source share

Source: https://habr.com/ru/post/1275668/


All Articles