How to detect if a file is encoded using mp3PRO? - audio

I have a folder which contains lot of MP3 files, some of them are encoded using mp3PRO.
Since this format is now obsolete, I'd like to convert them back to MP3 (converters can be found easily).
Is there is a way to detect programatically if a file is encoded using mp3PRO format ? (eg : by looking at file header or specific signatures using an hex editor)
The official player is able to detect if file is encoded using mp3PRO (the logo is highlighted or not) so I suppose this is technically possible.
What I found so far is that bitrate of mp3PRO file appears to be pretty low (50% of non encoded file) : eg : a 128 kbps file will appears as 64kbps. However a 320 kbps file will appears as 160 kpbs (which are pretty common) so it cannot be used as a rule.

Here is what I found out and how I fixed it. I wrote in here in case somebody would need it :
MP3Pro files does not contains any special flag in the mp3 header that would help to recognize them.
They are technically very similar to usual mp3 files, except they are encoded half the bit and sample rate (eg : a 128kpbs 44100hz file will be encoded as a 64kps 22050hz file, resulting in mp3pro file being approx half the size of original file).
This has been made for compatibility, so default players can play them without any change.
They also contains some SBR data, which allow to synthetically rebuild the lost audio part (high frequencies) and to play them it was before the mp3 pro conversion.
Detecting the SBR data seems very hard if not impossible : it would require to decode the actual mp3 frames. Also there is no documentation to be found about mp3pro format.
What I did (which works but required some manual effort) : I added all files to be checked to playlist of an mp3 player (foobar 2000 in my case) then sorted the files on the sample rate column : most 22050 hz mp3 files were indeed mp3 pro files.
They were converted back to mp3 using winamp + the mp3pro plugin made for it, available here : http://www.wav-mp3.com/mp3pro-to-mp3.htm

Related

Creating M4A file from MP4

I want to create an M4A file from an MP4, I want to attempt this from scratch without using other libraries but just the raw data.
So far I am able to locate the atom moov and parser it. And as a result I can pull the audio data from the mdat. So then I create my own M4A file with the right ftyp (M4A isomiso2) then add a new mdat with just the audio data I previously recovered, finally I add the moov with the same mvhd, and only the audio trak but with an updated stco to reflect the change in offsets of the chunks of audio data (as they are just one after each other now). I am sure I am doing all of this right.
However the M4A file just plays silence. I believe it is because I have to edit more in the moov but I am not sure what - I put it into FFmpeg corruption and I got:
"Sample rate index in program config element does not match the sample rate index configured by the container."
"Too large remapped id is not implemented."
So as a result I think it is something to do with the stsd atom but I am not sure how to change it.

AVFoundation cannot read wav file format

I'm trying to create a wav file from multiple other wav files.
I use AVAsset, AVAssestReader and AVAssetWriter.
The format setting used for the AVAssetWriterInput and AVAssetReaderAudioMixOutput is created like this:
AVAudioFormat(commonFormat: .pcmFormatInt16, sampleRate: 44100, channels: 2, interleaved: true)
And the AVAssetWriter is created like this: AVAssetWriter(url: outputURL, fileType: .wav)
Btw I noticed 2 weirds things:
1) When I create an AVAsset from a wav file I haven't any metadta.
The asset creation is:
let url = URL(fileURLWithPath: mWaveFilePath)
let asset = AVAsset(url: url)
I cannot do simpler, and when I look for metadata properties of this asset I get always empty array with wav file...
2) The most important is when I write a wave file I've the feelling that AVFoundation makes some errors in the wave header. Maybe it comes from me but I manage to create a wave file with audio, and followed some tutorial I've a bad time for finding where the error could come from.
Here is an example of good an and bad header:
The good header before importing the file.
We can see that the format tag is set to 1 which mean PCM. That's what we want.
Now the wrong header after the creation of my audio file:
-2... It's clearly wrong.
So did I miss something on using AVFoundation for creating a wav file, should I do something special?

iOS - Convert Audio Format (opus to mp3)

Recently I started to develop application that work with .opus file (Audio Format).
I am working with external SDK that can processor a mp3/wav file, unfortunately my local file is a .opus file and I need to convert it to mp3/wav format in order to process the file.
I read and research a lot around the network to find a solution,
I found the FFmpegWrapper library that can convert two type of Audio Format but when I try to convert .opus to .mp3/ , I get this error: opus codec not supported in WAVE format
I do not know what can be done, I'll be happy to help.
Any information about how to convert .Opus format to any other format will be appreciated.
Thanks
Have you tried using this pod: https://github.com/chrisballinger/Opus-iOS
You can use it to convert your Opus-encoded file to wav, then feed it into your SDK.

Determine whether an audio file is encoded in Apple Lossless (ALAC)

There are a number of audio files that have .m4a suffix and these are encoded in one of AAC or Apple Lossless (ALAC). I want to choose only audio files encoded in Apple Lossless of them. Is there any way to determine this? I tried FFmpeg, but it says all of them are encoded in AAC.
Edit: I am currently on Windows.
If you have the FFmpeg package, you should have ffprobe.
Give this a try:
ffprobe -v error -select_streams a:0 -show_entries stream=codec_name -of default=noprint_wrappers=1:nokey=1 file.m4a
-v error: to hide the startup text
-select_streams a:0: to select the first audio track
-show_entries stream=codec_name: to display only the codec type
-of default=noprint_wrappers=1:nokey=1: to remove extra formatting
This will print out just aac or alac. Perfect for scripting.
Here is a file that has a description of M4A (best I could find so far) on page 67:
http://iweb.dl.sourceforge.net/project/audiotools/audio%20formats%20reference/2.14/audioformats_2.14_letter.pdf
A typical M4A begins with an 'ftyp' atom indicating its file type...
10.2.1 the ftyp atom
[0 31] ftyp Length [32 63] 'ftyp' (0x66747970)
[64 95] Major Brand [96 127] Major Brand Version
[128 159] Compatible Brandā‚ ...
The 'Major Brand' and 'Compatible Brand' elds are ASCII strings.
'Major Brand Version' is an integer.
At first I figured 'ftyp' would be where format is determined, but judging by this list that is more like the file type itself (already known as m4a):
http://www.ftyps.com/index.html
http://www.ftyps.com/what.html Describes a bit more of the format.
If ftyp doesn't differentiate, then I think that the 'Major Brand' field might refer to the fourcc's on this page:
http://wiki.multimedia.cx/index.php?title=QuickTime_container
The one for Apple Lossless being 'alac' and AAC is probably 'mp4a'
Apple's Lossless format open source page indicates that the ftype is 'alac' (slightly contradictory to above)
http://alac.macosforge.org/trac/browser/trunk/ALACMagicCookieDescription.txt
So far what I can tell is that the 4 bytes following ftyp are always (in a smallish sample size) 'M4A '.
Somewhere in the first ~200 (hex) bytes or so there is an ascii 'mp4a' for AAC compression or an 'alac' for Apple Lossless. The 'alac' always seems to come in pairs ~30 bytes apart ('mp4a' only once).
Sorry that's not more specific, if I find the exact location or prefix I'll update again. (My guess is the earlier part of the header has a size specified somewhere.)
You can do it with Core Audio.
Something like:
CFStringRef pathToFile;
CFURLRef inputFileURL = CFURLCreateWithFileSystemPath(kCFAllocatorDefault, pathToFile, kCFURLPOSIXPathStyle, false);
ExtAudioFileRef inputFile;
ExtAudioFileOpenURL(inputFileURL, &inputFile);
AudioStreamBasicDescription fileDescription;
UInt32 propertySize = sizeof(fileDescription);
ExtAudioFileGetProperty(inputFile,
kExtAudioFileProperty_FileDataFormat,
&propertySize,
&fileDescription);
if(fileDescription.mFormatID == kAudioFormatAppleLossless){
// file is apple lossless
}
On a Mac, you select the file you want and then right click. Find "Get Info" and click that and a window will pop up with extra information about the file you selected. It should say next to "Codecs:" "AAC" or "Apple Lossless"
I hope I helped those Mac users out there that had the same question (and possibly Windows users in some way even though I am not familiar with the OS.)
try using http://sourceforge.net/projects/mediainfo/
"MediaInfo is a convenient unified display of the most relevant technical and tag data for video and audio files." - sourceforge project description
This is how info is displayed.
General
Complete name : C:\Downloads\recit24bit.m4a
Format : MPEG-4
Format profile : Apple audio with iTunes info
Codec ID : M4A
File size : 2.62 MiB
Duration : 9s 9ms
Overall bit rate : 2 441 Kbps
Track name : 24 bit recital ALAC Test File
Performer : N\A
Comment : Test File
Audio
ID : 1
Format : ALAC
Codec ID : alac
Codec ID/Info : Apple Lossless Format
Duration : 9s 9ms
Bit rate mode : Variable
Bit rate : 2 438 Kbps
Channel(s) : 2 channels
Sampling rate : 22.7 KHz
Bit depth : 24 bits
Stream size : 2.62 MiB (100%)
Language : English
Check audio section for codec/encoding details.

extract each frame from rtsp (mp4) stream

Im trying to extract each frame from a rtsp mp4 stream, and convert that into a jpeg/gif using ffmpeg. I'm getting the sdp header from 000001b0.....000001b5, and adding that into an byte array then capturing a frame starting from 000001b6 and appending it to the byte array.
When I flush it to a file (.mpg) and use ffmpeg it throws errors and not converting.
my header looks like 000001B008000001B58913000001000000012000C488BA98514043C1463F and after this I'm appending a frame (starting from 000001b6).
I did something similar with FFMPEG, and it seems that the frame data you get from FFMPEG already contains the frame header, which is all you need to transcode the data. Please make sure that you decode the mp4 data to a raw format (RGB24 for instance), then encode it to the pixelformat the JPEG/GIF encoder expects (probably a YUV format) using libswscale, before passing the data to the encoder.
Depending on the Codec you may not have to add anything or you may have to add a lot..
This is referred to as de-packetization and MPEG4-ES has no packetization model... H264 has many depending on the profile.
Check out the RFC..
Either 3016 or 3640 should help you.
https://www.rfc-editor.org/rfc/rfc3640
https://www.rfc-editor.org/rfc/rfc3016

Resources