我搜索了这个问题,但没有找到任何解决方案。
所以,我的问题是,
我正在使用GPUImage
将视频过滤器应用于视频文件。同时,该视频的声音没有播放。我知道在应用过滤器时GPUImage
不支持声音播放。
那么,我该怎么做呢?
答案 0 :(得分:7)
您可以通过添加GPUImageMovie.h
这样的支持来实现声音播放。
在@property(readwrite, nonatomic) BOOL playSound;
,
GPUImageMovie.m
在@interface GPUImageMovie ()
中,像这样更新@interface GPUImageMovie() <AVPlayerItemOutputPullDelegate>
{
// Add this
BOOL hasAudioTrack;
.........
........
// Add all below three lines
AVPlayer *theAudioPlayer;
CFAbsoluteTime startActualFrameTime;
CGFloat currentVideoTime;
}
。
-(void)startProcessing
之后,在- (void)startProcessing
{
// Add this
currentVideoTime = 0.0f;
.....
.....
// Add this
if (self.playSound)
{
[self setupSound];
}
GPUImageMovie __block *blockSelf = self;
[inputAsset loadValuesAsynchronouslyForKeys:[NSArray arrayWithObject:@"tracks"] completionHandler: ^{
runSynchronouslyOnVideoProcessingQueue(^{
.........
.........
// Add this
startActualFrameTime = CFAbsoluteTimeGetCurrent() - currentVideoTime;
.......
.......
});
}];
}
方法中添加以下行。
-(AVAssetReader*)createAssetReader
再次,在- (AVAssetReader*)createAssetReader
{
.......
.......
BOOL shouldRecordAudioTrack = (([audioTracks count] > 0) && (self.audioEncodingTarget != nil));
// Add this
hasAudioTrack = ([audioTracks count] > 0);
.........
}
更新它,
-(void)processAsset
在-(void)processAsset
{
.......
.......
if ([reader startReading] == NO)
{
NSLog(@"Error reading from file at URL: %@", self.url);
return;
}
// Add this
if (self.playSound && hasAudioTrack)
{
[theAudioPlayer seekToTime:kCMTimeZero];
[theAudioPlayer play];
}
.........
.........
}
,
-(void)endProcessing
在-(void) endProcessing
{
.........
.........
if (self.playerItem && (displayLink != nil))
{
[displayLink invalidate]; // remove from all run loops
displayLink = nil;
}
// Add this
if (theAudioPlayer != nil)
{
[theAudioPlayer pause];
[theAudioPlayer seekToTime:kCMTimeZero];
}
.........
.........
}
,
-(void) setupSound
最后添加新方法// Add this
- (void) setupSound
{
if (theAudioPlayer != nil)
{
[theAudioPlayer pause];
[theAudioPlayer seekToTime:kCMTimeZero];
theAudioPlayer = nil;
}
theAudioPlayer = [[AVPlayer alloc] initWithURL:self.url];
}
,
GPUImageMovie
最后,当您创建playSound
对象时,不要忘记将YES.
标记设置为movieFile.playSound = YES;
像这样:SELECT * FROM Table1
WHERE [name] IN
(SELECT name, Count(name)
FROM Table1
GROUP BY name
HAVING COUNT(name)>1)
希望这会有所帮助。
答案 1 :(得分:0)
如何在 GPUImage ?
应用的过滤器中暂停音频就像我暂停电影写作时我们可以暂停movieWriter.paused = YES;
的视频写作一样,我也需要暂停音频。