BradLarson / GPUImage

An open source iOS framework for GPU-based image and video processing
http://www.sunsetlakesoftware.com/2012/02/12/introducing-gpuimage-framework
BSD 3-Clause "New" or "Revised" License
20.25k stars 4.61k forks source link

trying to play audio during record freezes #1000

Open mikeconte opened 11 years ago

mikeconte commented 11 years ago

Hello, Brad and thanks for the awesome work.

I have a project where I play audio and record a movie at the same time...karaoke-ish. I was using a separate AV record session for the audio and GPUImage for the video but the a/v ends up a bit out of synch. So I figured I would just use the audio record of GPUImage. That's where I discovered this crash.

if I include [audioPlayer play], the video image will freeze and nothing is recorded (actually a fraction of a second of video is recorded but fails when i try to mix it all together).

I can post code but would take a bit of faffing around to make it a manageable size. I thought I'd post here to see if this is a known limitation or if there was some general knowledge or advice.

Thanks

mikeconte commented 11 years ago

OK, I've reproduced this in SimpleVideoFilter. I added an small audio file, Astral.mp3, to the bundle, and those lines of code to SimpleVideoFilterViewController.m at line 80:

    NSError *error = [[NSError alloc] init];
    NSString *soundFilePath = [[NSBundle mainBundle] pathForResource: @"Astral" ofType: @"mp3"];
    NSURL *fileURL = [[NSURL alloc] initFileURLWithPath: soundFilePath];

    AVAudioPlayer *audioPlayer = [[AVAudioPlayer alloc]initWithContentsOfURL:fileURL  error:&error];
    [audioPlayer play];

This causes the video to freeze and recording to fail. The audio file plays correctly and the NSLog statements are displayed on the console for start and end.

Any advice appreciated.

Thanks

jtoly commented 11 years ago

Mike,

Last night I was doing some animation and added an AVAudioPlayer to play MP3 (created in GarageBand and shared to iTunes using mp3).

The animation was inconsistently stuttering.

I spent time reading about AVAudioPlayer and decided to try the AAC codec instead. So now I play an mp4 file (medium quality) and the stuttering is gone.

Just a thought for your consideration.

Sent from my iPhone

On May 28, 2013, at 10:41 PM, Mike Conte notifications@github.com wrote:

OK, I've reproduced this in SimpleVideoFilter. I added an small audio file, Astral.mp3, to the bundle, and those lines of code to SimpleVideoFilterViewController.m at line 80:

NSError *error = [[NSError alloc] init];
NSString *soundFilePath = [[NSBundle mainBundle] pathForResource: @"Astral" ofType: @"mp3"];
NSURL *fileURL = [[NSURL alloc] initFileURLWithPath: soundFilePath];

AVAudioPlayer *audioPlayer = [[AVAudioPlayer alloc]initWithContentsOfURL:fileURL  error:&error];
[audioPlayer play];

This causes the video to freeze and recording to fail. The audio file plays correctly and the NSLog statements are displayed on the console for start and end.

Any advice appreciated.

Thanks

— Reply to this email directly or view it on GitHub.

mikeconte commented 11 years ago

thanks. Interesting that AAC is more efficient than MP3 tho perhaps not surprising as that was the intent.

my problem is not with stuttering however; its complete freeze of the video if audio is played while recording.

i can play audio and record without using GPU image for both so it is not an iOS limitation.

cheers

mikeconte commented 11 years ago

Any ideas, Brad? Or is this a known limitation?

I tried some poking around. If I comment line 882 of GPUImageVideoCamera.m, like so:

//                [_captureSession addOutput:audioOutput];

there is no freeze of the video. However, no sound is recorded. Does that help point to any clues?

thanks again.

mikeconte commented 11 years ago

well, Brad's silence on this can mean only one thing...he is working day and night to finish the code for the WWDC keynote - good luck, Brad! We'll be watching.

;)

BradLarson commented 11 years ago

You do realize I get emails with each one of these updates? "Bumping" issues is more than a little annoying, and makes me less motivated to work on them.

Quite frankly, I don't spend any time working on the audio side of AV Foundation, so this is going to be up to someone else to solve. It may be a fundamental limitation of AV Foundation, for all I know.

mikeconte commented 11 years ago

Just tried the SimpleVideoFilter code again with Xcode 5.0 and the latest build of GPUImage...and the crash is gone! Thanks to whoever fixed it.

ghost commented 11 years ago

hi mikeconte, i have the problem as you , how to solve it ?