I'm trying to allow selection of words (mp3 audio samples) and add to a sentence which upon pressing play plays them all in sequence and optionally save that one combined file.
MP3 is a stream format, meaning it doesn't have a bunch of metadata at the front or end of the file. While this has a lot of downsides, one of the upsides is that you can concatenate MP3 files together into a single file and it'll play.
This is pretty much what you're doing by concatenating into an NSMutableData, the downside of which is that you might run out of memory. Another option would be to build up the file on disk with NSFileHandle.
This doesn't work for most file formats (aac/m4a, aif, caf, etc.). MP3 is literally just a stream dumped to disk, with metadata in frame headers (or, in ID3, tucked between frames), so that's why it works.
Related
Which audio file format is best to use for large audio files? I have many large audio files to be used in my app but their current mp3 size is of hundred of MB's
If you want to save more storage on audio files, file format may not change too much on the file size, reducing the bit rate(for example 320Kbps to 128Kbps) can reduce the file size significantly.
:how to do it using microsofts audio compression manager?(practically its not well documented in m.s.d.n.
Windows provide codecs that compress specifically audio files. The audio files tipically are PCM format (WAVE_FORMAT_PCM) and get played by using the simplest directsound method (check msdn it`s at hand and it works)
To play a file using directsound, thus PCM format you first create a directsound object, create a directsoundbuffer, and then pump the PCM data directly to the buffer using a keep-fill-buffer algorithm.
If you wish to use codecs, u try and write a procedure that opens a stream file and passes it through a acm driver object, thus (de)compressing it.
The driver for ACM (audio compression manager) finds a codecs that suits the input source and decompresses it yet again to WAVE_FORMAT_PCM for your app be able to play it.
I'm trying to implement, more or less, lstat (to get filesize and extention) and fseek workalikes for the music files in the ipod-library and assets-library. I'm then streaming these files to players (might be on this device, might not).
I've come up with three approaches, but neither is particularly satisfying:
1) to mimic lstat to tell the size of the file, use AVAssetReader to read additional chunks of the file, adding the length of these chunks to a variable until done. At the end of the loop, the variable now contains the length of the file.
To 'fseek', using an AVAssetReader, you start from the beginning of the file, and read until you get to the desired point. Then you cache the bit of the file you might have left, and save it for when the fread happens.
2) Using AVAssetExportSession, you copy the given file to your Documents directory, and then you can do whatever you need to do with it (real lstat, fseek, etc). The downside is the 5-20 second pause depending on the size of the file.
So, it seems I have my app do a lot of extra work (#1), or a force the user to wait 5-20 seconds between each song. Just seems wasteful.
3) With ALAsset, you can get the size of the representation...(but that doesn't work for audio files), and certainly doesn't address fseek.
I'm currently using #2. It definitely feels slow, but then again, it does work, after a fashion.
Can anyone else tell me a better approach?
Thanks,
-Ken
I would like to write an iphone app that continuously capture video, h.264 encode them in 10 seconds interval and upload to a storage server. This can be done with avassetwriter, and I can keep on deleting the old files as I create new ones. However, as flash memory have a limited write cycles, this scheme will destroy the flash after a few thousand write cycles through the flash. Is there a way to redirect avassetwriter to memory, or create a ram drive on the iphone?
Thanks!
Yes avassetwriter is the only way to get to the hardware decoder. and simply reading back the file while its written doesn't give you the moov atoms so avfoundation or mpmediaplayer based players won't be able to read it back. you only have a couple choices , periodically stop the asassetwriter and write to the file on a background thread, effectively segmenting your movie into smaller complete files. or you could deal with the incomplete mp4 on the server side, you will have to decode the raw nalu's and recreate the missing moov atoms. If your using ffmpeg mov.c is source to look at. This is also were an incomplete mp4 file would fail.
I've got videos ( FLV ) set to split once they reach a certain filesize/length due to storage constraints, but I can't find a simple way to concatenate these files on the fly to upload them.
Currently it's looking like I'll have to concatenate the files using something like ffmpeg into an intermediary file and then uploading that, however that is rather intensive on resources and it would be much simpler if I could just tweak data in the stream I'm sending to youtube so the first file never "ends" and the next file can just be read in ( modified as it's read so it doesn't break ), and then youtube would "solidify" it when it processes the video.
So the question remains, is there any way to do this, or is the FLV file format ( wowza / flash video ) a bane to my plans?
No, there's no way to do that. You need to concatenate them first, and you need to specify the length of the entire video at the start of the upload (i.e. you can't just stream video bytes without knowing in advance the total upload size).
I need to create a mp3 file with certain number of seconds of silence?
What would be way to do it programatically?
Edit:
It doesn't need to be re inserted in mp3, just a single mp3 file that contain silence x seconds long.
Do you just want an MP3 of X seconds long that is just silence, or do you want to inject silence into an existing MP3?
This is a bit more complicated. Windows XP by default has a low quality MPEG encoding codec installed. You can find some informant about encoding to an MP3 with Delphi on that same page if you scroll to the bottom there is information on Wave files. Some of the links are broken though.
It is a two step process, you need to generate a waveform and then encode that waveform to an MP3 file. MP3 files have a header and blocks, so you can't just loop a 40ms mp3 a few times.
Encode a very short (~40ms) wave file of silence and put the resulting mp3 block as array in your source code. That block may be encoded at 32kbit (which is the least possible bitrate iirc).
Alternatively you would have to link against any mp3 encoding library (i.e. LAME) and feed silence to that to output the result.