Encode Mic Audio CMSamplebuffer to AAC - ios

I used the code found at the link below. It doesn't work with iPhone 5 as no audio is processed(while the mic are ok). For iPhone 6s the audio quality is good Only when the headphone is connected but without it the audio has a gap for like every other second.
https://github.com/chrisballinger/FFmpeg-iOS-Encoder/blob/master/FFmpegEncoder/AACEncoder.m
Can you suggest a better approach on encoding audio from the mic? I am sending the data to a server and writing to file is NOT an option unless it is fast and I can grab the AAC data with timestamps.

Related

Video recorded in android cannot play in IOS Using HTML Video tag

Update:
I record VP8 video from Android that is saved as MP4 format, which should be supported by Safari. From some research I know Opus audio format is partially supported by Safari...
What else do I need to add while saving file (eg: output settings)?
Is it because of the Opus audio format that Safari is not playing VP8 video format?
Question:
In my application which records the video from any device and saving in AWS server, and admin can play recorded videos from any os/ device.
After the iOS updated on Dec 14 2022, my video component is messed up, I cannot record or play video from Apple devices.
As I cannot write entire project code, I have the code in the below link
video player code - Github
In the code the video src is from AWS S3 (storage) which is recorded from Android phone, from the link below you can play the video.
video player testing
This video can be played in Mac Chrome, but not in Mac Safari, Apple Safari and Apple Chrome.
I am looking for quick solution.
I don't use and don't have access to iOS or Mac Safari, so you must test this for us...
Looking at your MP4 file in a hex editor I see this:
It seems you have a WebM file that simply has .mp4 added to the file name. It is not an MP4 (there is no MPEG header/data inside these file bytes, etc). Your file here has webm in second line something which a real MP4 would never do. A valid MP4 usually has ftyp written in its first line.
Possible solutions:
(1) To avoid confusing some decoders (about file format) try renaming file as:
159_159_1652901854.webm
Some players will use the file .type extension to decide which decoder to use. If it is file.mp4 and some player uses the MPEG decoder on those VP8 bytes then you will get no picture or sound.
(2) Also try to set correct WEBM mime-type (ie: because it's not a video/mp4)
<video height="700" controls muted autoplay playsinline loop>
<source src="https://api.tenrol.com/uploads/videos/159_159_1652901854.webm" type="video/webm">
</video>
note: consider testing a WebM video with no sound, to answer if Opus audio is the problem.
See if the above <video> tag code works on Mac Safari and iPad Safari. I think Opus (usually audio for OGV files) and Vorbis (usually audio for webM files) are not supported on iPhone (unless you put the audio in an MOV format, but then you lose the video part). Basically iPhone has no WebM sound.
(3) If all else fails then just understand the following:
MP4 plays in all major browsers.
MP4 contains H.264 or H.265 picture codecs, and also AAC or MP3 audio codecs.
Browsers prefer to record in their own in-house/licensed codecs.(Google == WebM (VP8/9), Mozilla == OGV (Theora) and Apple == MP4 (H.264/H.265)).
Don't use Webm (Chrome/Firefox) if you want guaranteed Safari playback of video.
Don't use MP4/H265 (Safari) if you want guaranteed Chrome/Firefox video playback.
There is no easy solution. So your options are:
To guarantee that you get H264/MP4 encoded in Chrome/Firefox browsers, then try finding a Javascript based H.264 encoder. Here's a search example to start with. Then you also need an audio encoder for AAC or MP3 formats. Such a file would play in Safari.
Or else, push for getting WebM decoded by Safari browser (even if without sound). This means a lot of testing. Use a tool like FFmpeg to output short 10 second test videos of WebM (at different settings) until something displays. Then you can move onto dealing with sound.
The video you recorded is using the vp8 video codec which should be supported on Safari on Mac but also the opus audio codec which is not usually supported.
Video Info for https://api.tenrol.com/uploads/videos/159_159_1652901854.mp4
Input #0, matroska,webm, from 'test.mp4':
Metadata:
encoder : Chrome
Duration: N/A, start: 0.000000, bitrate: N/A>
Stream #0:0(eng): Audio: opus, 48000 Hz, mono, fltp (default)>
Stream #0:1(eng): Video: vp8, yuv420p(progressive), 1080x1920, SAR 1:1 >DAR 9:16, 1k tbr, 1k tbn, 1k tbc (default)>
You can check the video format using ffprobe (https://ffmpeg.org/ffprobe.html)
or online here (it will take a little while): https://getvideoinfo.westshoretechnology.com
You can check browser support for codecs in the browser release notes or at sites like this which are usually up to date: https://caniuse.com/opus
The Android video encoding recommendations are available online and the current recommendations at the time of writing are:
These are pretty good guides cross device at this time also - the link is here: https://developer.android.com/guide/topics/media/media-formats

How to record all audio generated from my app (might from AVPlayer or others) in iOS? (not mic)

There are many audio generated from my app, the sources could be AVPlayer, AudioUnit, etc. I want to record all the audio(not from mic because that would record user voice) into a single file. Is there any way to get the final mixed audio data before sent to the audio playback hardware?
I've tried AudioUnit, and The Amazing Audio Engine. However it could only record audio played by AudioUnit.
Also read the MTAudioProcessingTap, but it has to inject some code into AVPlayer, and seems complicated to mix all the audio.

IOS: Is it possible to record compressed video and uncompressed audio simultaneously

I'm writing an IOS-App which should record video, using front camera, and audio of the user working with the app. Later I want to analyse the user behavior offline. This App should run on an iPad 3.
Remark: The observed users will be people form my office. Code & data is only needed for the development process and won't be included in the final APP.
My requirements: Video and audio should be uncompressed, at least audio must be uncompressed. I think uncompressed video recording without skipping frames is not possible on an iPad (See: where can i find an uncompressed video recording from iPhone 3G/3GS/4 ), but uncompressed audio is possible.
Here are my questions:
Is it possible to record a video (compressed) and audio (uncompressed / kAudioFormatLinearPCM) simultaneously?
Is it possible to save video and audio in seperate files?
If one of the two questions is YES then what should I do in AVCam-Example http://developer.apple.com/library/ios/#samplecode/AVCam/Introduction/Intro.html to solve my problems :-)
Thank you all in advance!
The AVCam sample code isn't flexible enough to do what you want. You need to use AVAssetWriter to write out the media. I'm not 100% sure on the uncompressed audio bit but the VideoSnake sample code from WWDC 2012 session 520 is a great place to start with AVAssetWriter. I can't speak to performance but you could have 2 AVAssetWriters for video and audio, just modify that code to vend the samplebuffers to the appropriate writer.

How to play raw pcm data in iphone sdk

I am developing an application for voice chat. Now I want to play raw pcm audio data in iPhone. I could not achieve it. Can anyone help me to play pcm data?
You will need to read up on Audio Queue Services:
http://developer.apple.com/library/mac/#documentation/MusicAudio/Conceptual/AudioQueueProgrammingGuide/Introduction/Introduction.html

How to play stream audio in iPhone/iPad

I want to play sounds from an internet server in my own program. But the sample codes Apple supplied concerned about sound play are all open an audio file, and then play it.
I want to know how can I play PCM data from memory, which received from internet continuously. Either OpenAL or AudioQueue is OK.
Give this a look:
http://cocoawithlove.com/2008/09/streaming-and-playing-live-mp3-stream.html
http://developer.apple.com/iphone/library/documentation/iPhone/Conceptual/iPhoneOSProgrammingGuide/AudioandVideoTechnologies/AudioandVideoTechnologies.html#//apple_ref/doc/uid/TP40007072-CH19-SW8

Resources