AVPlayer HLS实时流量计(显示FFT数据) [英] AVPlayer HLS live stream level meter (Display FFT Data)

查看:637
本文介绍了AVPlayer HLS实时流量计(显示FFT数据)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 AVPlayer 为使用HTTP直播的无线电应用程序。现在我想为该音频流实现一个电平表。最好的水平仪显示不同的频率,但简单的左/右解决方案将是一个很好的起点。

I'm using AVPlayer for a radio app using HTTP live streaming. Now I want to implement a level meter for that audio stream. The very best would a level meter showing the different frequencies, but a simple left / right solution would be a great starting point.

我发现了一些使用<$ c $的例子C> AVAudioPlayer 。但我无法找到解决方案来获取所需的信息 AVPlayer

I found several examples using AVAudioPlayer. But I cannot find a solution for getting the required informations off AVPlayer.

有人可以为我的解决方案考虑问题?

Can someone think of a solution for my problem?

编辑我想创建这样的东西(但更好)

EDIT I want to create something like this (but nicer)

EDIT II

一个建议是使用 MTAudioProcessingTap 来获取原始音频数据。我可以使用 [[[_ player currentItem] asset]跟踪] 数组找到的示例,在我的例子中,这是一个空数组。另一个建议是为我使用 [[_ player currentItem] audioMix] null

One suggestion was to use MTAudioProcessingTap to get the raw audio data. The examples I could find using the [[[_player currentItem] asset] tracks] array, which is, in my case, an empty array. Another suggestion was to use [[_player currentItem] audioMix] which is null for me.

编辑III

之后,似乎仍然没有一个办法。我确实取得了进展,所以我正在分享它。

After years already, there still not seems to be a solution. I did indeed make progress, so I'm sharing it.

在设置过程中,我正在向playerItem添加一个键值观察器:

During setup, I'm adding a key-value observer to the playerItem:

[[[self player] currentItem] addObserver:self forKeyPath:@"tracks" options:kNilOptions context:NULL];

//////////////////////////////////////////////////////

- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)changecontext:(void *)context
    if ([keyPath isEqualToString:@"tracks"] && [[object tracks] count] > 0) {
        for (AVPlayerItemTrack *itemTrack in [object tracks]) {
            AVAssetTrack *track = [itemTrack assetTrack];

            if ([[track mediaType] isEqualToString:AVMediaTypeAudio]) {
                [self addAudioProcessingTap:track];
                break;
            }
        }
}

- (void)addAudioProcessingTap:(AVAssetTrack *)track {
    MTAudioProcessingTapRef tap;
    MTAudioProcessingTapCallbacks callbacks;
    callbacks.version = kMTAudioProcessingTapCallbacksVersion_0;
    callbacks.clientInfo = (__bridge void *)(self);
    callbacks.init = init;
    callbacks.prepare = prepare;
    callbacks.process = process;
    callbacks.unprepare = unprepare;
    callbacks.finalize = finalise;

    // more tap setup...

    AVMutableAudioMix *audioMix = [AVMutableAudioMix audioMix];

    AVMutableAudioMixInputParameters *inputParams = [AVMutableAudioMixInputParameters audioMixInputParametersWithTrack:audioTrack];
    [inputParams setAudioTapProcessor:tap];
    [audioMix setInputParameters:@[inputParams]];

    [[[self player] currentItem] setAudioMix:audioMix];
}

到目前为止一切顺利。这一切都有效,我可以找到正确的轨道并设置inputParams和audioMix等。
但不幸的是,唯一的回调,被调用是init回调。其他任何人都不会在任何时候开火。

So far so good. This all works, I could find the right track and setup the inputParams and audioMix etc. But unfortunately the only callback, that gets called is the init callback. None of the others will fire at any point.

我尝试了不同的(种类)流源,其中一个是官方的Apple HLS流: http://devimages.apple.com/iphone/samples/bipbop/bipbopall.m3u8

I tried different (kinds of) stream sources, one of them an official Apple HLS stream: http://devimages.apple.com/iphone/samples/bipbop/bipbopall.m3u8

推荐答案

使用 AVPlayer 测量音频看起来仍然是一个问题。话虽这么说,我相信可以通过将 AVPlayer AVAudioRecorder 组合来达到解决方案。

Measuring audio using AVPlayer looks to be an issue that is still ongoing. That being said, I believe that the solution can be reached by combining AVPlayer with AVAudioRecorder.

虽然这两个类看似矛盾,但有一种方法可以让 AVAudioRecorder 访问 AVPlayer 的音频输出。

While the two classes have seemingly contradictory purposes, there is a work around that allows AVAudioRecorder to access the AVPlayer's audio output.

如此 Stack Overflow Answer ,录制AVPlayer的音频如果您使用 kAudioSessionProperty_AudioRouteChange 访问音频路线更改,则可以。

As described in this Stack Overflow Answer, recording the audio of a AVPlayer is possible if you access the audio route change using kAudioSessionProperty_AudioRouteChange.

请注意必须在 访问音频路径更改后启动录音。使用链接堆栈答案作为参考 - 它包含更多详细信息和必要的代码。

Notice that the audio recording must be started after accessing the audio route change. Use the linked stack answer as a reference - it includes more details and necessary code.

~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

一旦你有权访问 AVPlayer 的音频路线并进行录音,测量是相对简单的。

Once you have access to the AVPlayer's audio route and are recording, the measuring is relatively straightforward.

在我的回答关于测量麦克风输入的堆栈问题我描述了访问音频电平测量所需的步骤。使用 AVAudioRecorder 监视音量变化比人们想象的要复杂得多,所以我加入了一个GitHub 项目,作为录制时监听音频变化的模板。

In my answer to a stack question regarding measuring microphone input I describe the steps necessary to access the audio level measurements. Using AVAudioRecorder to monitor volume changes is more complex than one would think, so I included a GitHub project that acts as a template for monitoring audio changes while recording.

~~~~~~~~~~~~~~~~~~~~~~~~~~ 请注意 ~~~~~~~~~~~~~~~ ~~~~~~~~~~~

~~~~~~~~~~~~~~~~~~~~~~~~~~ Please Note ~~~~~~~~~~~~~~~~~~~~~~~~~~

在HLS直播流中这种组合不是我测试过的。这个答案完全是理论上的,因此可能需要对这两个类完全理解。

This combination during an HLS live stream is not something that I have tested. This answer is strictly theoretical, so it may take a sound understanding of both classes to work out completely.

这篇关于AVPlayer HLS实时流量计(显示FFT数据)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆