Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

DavidBlack

macrumors 6502a
Original poster
Jan 27, 2013
606
239
Somewhere In Apple's HQ ;)
I have been looking for a solution on Google but, I haven't found one. I even looked on GitHub no luck there. I want it convert an AAC file to a MP3 file. Can anyone offer any suggestions?
 
I have been looking for a solution on Google but, I haven't found one. I even looked on GitHub no luck there. I want it convert an AAC file to a MP3 file. Can anyone offer any suggestions?

iTunes will do that easily. In Preferences/General/Import Settings choose the mp3 format that you want, click on the song, and choose "Create New Version" in the File menu.
 
Core audio has an audio converter, there maybe an equivalent in AVFoundation as well, not sure. Both AAC and MP3 are lossy so if you convert from AAC to MP3 you will get artifacts from both compression methods in the file. Also, AAC is a newer better standard that supersedes mp3.
 
Core audio has an audio converter, there maybe an equivalent in AVFoundation as well, not sure. Both AAC and MP3 are lossy so if you convert from AAC to MP3 you will get artifacts from both compression methods in the file. Also, AAC is a newer better standard that supersedes mp3.

I was going to post the same thing.

Please be aware of the loss of quality when converting between the two and also note that AAC is actually the preferred format out of the two.
 
Oh man it'll sound horrible. Why do you need mp3's specifically?

I need the file because I am trying to download audio from YouTube. So I used this third party library https://github.com/0xced/XCDYouTubeKit
I don't want the video I just want the audio.

Code:
NSString *videoIdentifier = @"EdeVaT-zZt4"; // A 11 characters YouTube video identifier
[[XCDYouTubeClient defaultClient] getVideoWithIdentifier:videoIdentifier completionHandler:^(XCDYouTubeVideo *video, NSError *error) {
    if (video)
    {
        // Do something with the `video` object
    NSLog (@"Stream URLS Are: %@",video.streamURLs);

    }
    else
    {
        // Handle error
    }
}];

The NSLog will return the iTag URL for the YouTube Video. I am only interested in the iTag Value of 140.

According to Wikipedia. The default container is mp4, audio encoding is AAC and the bit-rate is 128.
Here is an example of a download url for a video with iTag = 140. You will notice if you add the mp4 extension to the file it will not play but, if you convert the file to mp3 it plays perfectly. That is why I want to know how to convert a AAC file to mp3. So far I have had not luck.


Here is the URL:
http://r2---sn-aphx-cbpe.googlevideo.com/videoplayback?source=youtube&dur=225.024&mws=yes&gir=yes&gcr=vg&ip=76.76.164.244&ms=au&ipbits=0&lmt=1403157879642657&itag=140&signature=432DE821C7593B11311B44FC671D2A52934B878F.965B24E03260180A1D162C08D3463CDDD4AE841E&sver=3&expire=1404349200&clen=3613192&fexp=900064%2C902408%2C924213%2C924217%2C924222%2C930008%2C934024%2C934030&mv=m&sparams=clen%2Cdur%2Cgcr%2Cgir%2Cid%2Cip%2Cipbits%2Citag%2Clmt%2Csource%2Cupn%2Cexpire&mt=1404325684&upn=eqn3riUoTvQ&key=yt5&id=o-AGZndG84UJiX-y4juow54gk3rr1hYDKKoUUwft6eJ_lr
 
Here is an example of a download url for a video with iTag = 140. You will notice if you add the mp4 extension to the file it will not play but, if you convert the file to mp3 it plays perfectly. That is why I want to know how to convert a AAC file to mp3. So far I have had not luck.

That's what you call an XY question. You want to do X and ask how to do Y. You don't want to convert AAC to MP3, you want to extract the audio track from a Quicktime file.
 
That's what you call an XY question. You want to do X and ask how to do Y. You don't want to convert AAC to MP3, you want to extract the audio track from a Quicktime file.

Hmm. The file that is downloaded is not a video file but a audio file. It needs to be converted to play property. Please correct me if I am wrong :D
 
Hmm. The file that is downloaded is not a video file but a audio file. It needs to be converted to play property. Please correct me if I am wrong :D

You are wrong. You want to extract audio from a video, you don't want to convert it.
 

Attachments

  • Screen Shot 2014-07-02 at 8.59.55 PM.png
    Screen Shot 2014-07-02 at 8.59.55 PM.png
    83.8 KB · Views: 200
Please go to this link: http://www.ytapi.com/?vid=9bZkp7q19f0
Try to download the file, then play it. Now try any converter than can handle AAC to Mp3 and then try to play that file.

Think about it: If you can't play it, and a converter that converts AAC to mp3 creates a playable file, then there _is_ AAC in the file, and all you need is extract it. AVFoundation should have everything you need. And for 128 Kbit, I would _really_ recommend extracting it without converting, because you can really do without any further quality loss.
 
Think about it: If you can't play it, and a converter that converts AAC to mp3 creates a playable file, then there _is_ AAC in the file, and all you need is extract it. AVFoundation should have everything you need. And for 128 Kbit, I would _really_ recommend extracting it without converting, because you can really do without any further quality loss.

You have a point. I will read the Docs on it. Thank you btw :)
 
Aac to mp3

Code:
    NSURL *inputAssetURL = [NSURL fileURLWithPath:@"/Users/john/Desktop/Encoding Tests/Input.m4a"];
    
    AVAsset *audioAsset = [AVURLAsset assetWithURL:inputAssetURL];
    
    AVAssetExportSession *session = [AVAssetExportSession exportSessionWithAsset:audioAsset presetName:AVAssetExportPresetAppleM4A];
    
    session.outputURL = [NSURL fileURLWithPath:@"/Users/john/Desktop/Encoding Tests/output.m4a"];
    session. outputFileType = AVFileTypeAppleM4A;
    [session exportAsynchronouslyWithCompletionHandler:^{
        NSLog(@"Done 1");
        NSLog(@"%ld",(long)session.status);
        switch (session.status) {
            case AVAssetWriterStatusCompleted:
                NSLog(@"Done");
                break;
                case AVAssetExportSessionStatusCancelled:
                NSLog(@"Cancel");
               
            case AVAssetExportSessionStatusFailed:
                NSLog(@"Failed");
                break;
                break;
                case AVAssetExportSessionStatusUnknown:
                NSLog(@"Unknown");
                break;
                case AVAssetExportSessionStatusWaiting:
                NSLog(@"Wating");
                break;
            default:
                break;
        }
        
        
        
        
    }];

It does not work. Any ideas?
 
Last edited:
Code:
    NSURL *inputAssetURL = [NSURL fileURLWithPath:@"/Users/soneejohn/Desktop/Encoding Tests/Input.m4a"];
    
    AVAsset *audioAsset = [AVURLAsset assetWithURL:inputAssetURL];
    
    AVAssetExportSession *session = [AVAssetExportSession exportSessionWithAsset:audioAsset presetName:AVAssetExportPresetAppleM4A];
    
    session.outputURL = [NSURL fileURLWithPath:@"/Users/soneejohn/Desktop/Encoding Tests/output.m4a"];
    session. outputFileType = AVFileTypeAppleM4A;
    [session exportAsynchronouslyWithCompletionHandler:^{
        NSLog(@"Done 1");
        NSLog(@"%ld",(long)session.status);
        switch (session.status) {
            case AVAssetWriterStatusCompleted:
                NSLog(@"Done");
                break;
                case AVAssetExportSessionStatusCancelled:
                NSLog(@"Cancel");
               
            case AVAssetExportSessionStatusFailed:
                NSLog(@"Failed");
                break;
                break;
                case AVAssetExportSessionStatusUnknown:
                NSLog(@"Unknown");
                break;
                case AVAssetExportSessionStatusWaiting:
                NSLog(@"Wating");
                break;
            default:
                break;
        }
        
        
        
        
    }];

It does not work. Any ideas?

What didn't work?

You said you wanted AAC to MP3 but all I see is "Input.m4a" and "output.m4a". How could that possibly achieve what you want?!
 
What didn't work?

You said you wanted AAC to MP3 but all I see is "Input.m4a" and "output.m4a". How could that possibly achieve what you want?!
Because when you download the file the extension is m4a, but it won't play until encode or convert it. So I was trying to see if I exported it to the same extension it might work. But It didn't, I am fairly new to programming so please bare with me.
 
Last edited:
In all multimedia formats, audio is encoded separately from video, and their frames are interleaved in the file. So removing the video from a multimedia file does not require any messing with encoders and decoders: you can write a file format parser that will drop the video track, without using the multimedia APIs on the phone.

To do this without using a 3rd party library, you need to write the parser from scratch, which could be simple or difficult depending on the file format you wish to use. For example, FLV is very simple so stripping a track out of it is very easy (just go over the stream, detect the frame beginnings and drop the '0x09'=video frames). MP4 a bit more complex, its header (MOOV) has a hierarchical structure in which you have headers for each of the tracks (TRAK atoms). You need to drop the video TRAK, and then copy the interleaved bitstream atom (MDAT) skipping all the video data clusters as you copy.

There are 3rd party libraries you can use, aside from ffmpeg. One that comes in mind is GPAC MP4BOX (LGPL license). If the LGPL is a problem, there are plenty of commercial SDKs that you can use.

I am sorry, but I can't think of an beginner friendly way to implement what you want.
 
Get download helper for your browser (I use Firefox).

Save the YouTube video in it's original format.

Download MP4 Tools.

Open the FLV/MP4 you downloaded with it.

Select the audio track.

Export as MP4. It will just pass through the audio without any recompression.

Then rename the file it creates as .m4a for iTunes use.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.