Convert AAC to MP3

Discussion in 'Mac Programming' started by DavidBlack, Jul 1, 2014.

  1. DavidBlack macrumors 6502a

    DavidBlack

    Joined:
    Jan 27, 2013
    Location:
    Somewhere In Apple's HQ ;)
    #1
    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?
     
  2. gnasher729 macrumors P6

    gnasher729

    Joined:
    Nov 25, 2005
    #2
    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.
     
  3. DavidBlack thread starter macrumors 6502a

    DavidBlack

    Joined:
    Jan 27, 2013
    Location:
    Somewhere In Apple's HQ ;)
    #3
    Thanks for the advice but, that is not quite what I am looking for. I want to be able to do this in Objective-C
     
  4. superscape macrumors 6502a

    superscape

    Joined:
    Feb 12, 2008
    Location:
    East Riding of Yorkshire, UK
    #4
    I'm certainly no expert on audio, but I wonder whether a wrapper round ffmpeg might be of use?
     
  5. DavidBlack thread starter macrumors 6502a

    DavidBlack

    Joined:
    Jan 27, 2013
    Location:
    Somewhere In Apple's HQ ;)
    #5
  6. DavidBlack thread starter macrumors 6502a

    DavidBlack

    Joined:
    Jan 27, 2013
    Location:
    Somewhere In Apple's HQ ;)
  7. subsonix macrumors 68040

    Joined:
    Feb 2, 2008
    #7
    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.
     
  8. Cromulent macrumors 603

    Cromulent

    Joined:
    Oct 2, 2006
    Location:
    The Land of Hope and Glory
    #8
    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.
     
  9. strayts macrumors member

    Joined:
    Oct 5, 2011
    #9
    Oh man it'll sound horrible. Why do you need mp3's specifically?
     
  10. DavidBlack thread starter macrumors 6502a

    DavidBlack

    Joined:
    Jan 27, 2013
    Location:
    Somewhere In Apple's HQ ;)
    #10
    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
     
  11. gnasher729 macrumors P6

    gnasher729

    Joined:
    Nov 25, 2005
    #11
    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.
     
  12. DavidBlack thread starter macrumors 6502a

    DavidBlack

    Joined:
    Jan 27, 2013
    Location:
    Somewhere In Apple's HQ ;)
    #12
    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
     
  13. rei101 macrumors 6502a

    Joined:
    Dec 24, 2011
    #13
  14. JohnsonK macrumors regular

    Joined:
    Mar 6, 2014
    #14
    You are wrong. You want to extract audio from a video, you don't want to convert it.
     
  15. DavidBlack thread starter macrumors 6502a

    DavidBlack

    Joined:
    Jan 27, 2013
    Location:
    Somewhere In Apple's HQ ;)
    #15

    Attached Files:

  16. DavidBlack thread starter macrumors 6502a

    DavidBlack

    Joined:
    Jan 27, 2013
    Location:
    Somewhere In Apple's HQ ;)
    #16
    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.
     

    Attached Files:

  17. gnasher729 macrumors P6

    gnasher729

    Joined:
    Nov 25, 2005
    #17
    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.
     
  18. DavidBlack thread starter macrumors 6502a

    DavidBlack

    Joined:
    Jan 27, 2013
    Location:
    Somewhere In Apple's HQ ;)
    #18
    You have a point. I will read the Docs on it. Thank you btw :)
     
  19. DavidBlack, Jul 3, 2014
    Last edited: Jul 3, 2014

    DavidBlack thread starter macrumors 6502a

    DavidBlack

    Joined:
    Jan 27, 2013
    Location:
    Somewhere In Apple's HQ ;)
    #19
    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?
     
  20. JohnsonK macrumors regular

    Joined:
    Mar 6, 2014
    #20
    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?!
     
  21. DavidBlack, Jul 3, 2014
    Last edited: Jul 3, 2014

    DavidBlack thread starter macrumors 6502a

    DavidBlack

    Joined:
    Jan 27, 2013
    Location:
    Somewhere In Apple's HQ ;)
    #21
    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.
     
  22. JohnsonK macrumors regular

    Joined:
    Mar 6, 2014
    #22
    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.
     
  23. barkmonster macrumors 68020

    barkmonster

    Joined:
    Dec 3, 2001
    Location:
    Lancashire
    #23
    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.
     

Share This Page