6

Does anyone know if it is possible to separate the audio from a video file such as h.264 encode mpeg (or other such formats) and than save that audio data to a separate file such as an mp3 file? This relates to the iPhone SDK.

Any pointers in the right direction would be much appreciated. Thanks.

ageektrapped
  • 14,482
  • 7
  • 57
  • 72
Zigglzworth
  • 6,645
  • 9
  • 68
  • 107
  • See [my Swift 3 answer](http://stackoverflow.com/a/43599824/1966109) for a similar question. The provided code extracts an audio track from a _.mov_ file and exports it as an _.m4a_ file. – Imanou Petit Apr 25 '17 at 01:01

1 Answers1

3

Sounds like a job for AVFoundation. I can't tell you the details, but opening a video file into an AVURLAsset should give you access to its tracks. Identify the tracks whose mediaType is AVMediaTypeAudio.

Not sure about the output part, but I would try creating an AVMutableComposition object to which I'd then add the tracks you want to export. Then use AVAssetExportSession or AVAssetWriter to write the result to a new file.

Ole Begemann
  • 135,006
  • 31
  • 278
  • 256