AVAssetReader 采样率

发布于 2024-12-17 15:43:23 字数 169 浏览 0 评论 0原文

如何使用 AVAssetReader 计算从 iPod 库获取的歌曲的采样率。我想我可以很容易地获得样本的数量(无论如何我已经成功地读取了样本..),但我不知道在哪里可以获得歌曲的长度(以秒为单位)。

请注意,MPMediaItem 没有媒体项长度的属性,也许还有另一种方法通过此 API 来获取项目的长度?

How do I calculate the samplerate of a song obtained from the iPod Library using AVAssetReader. I think I can pretty easily get the amount of samples, ( I am already successfully reading the samples anyways.. ), but I do not know where I can obtain the length ( in seconds ) of the song.

Note that MPMediaItem has no property for the length of the Media Item, maybe there is another way through this API to get the length of the item?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

幸福丶如此 2024-12-24 15:43:23

您可以使用 MPMediaItem 来获取长度。查看 MPMediaItemPropertyPlaybackDuration 属性键。文档指出:

媒体项目的播放持续时间。 Value 是一个 NSNumber 对象,表示 NSTimeInterval 的持续时间(以秒为单位)。

You can use MPMediaItem to get the length. Have a look at the MPMediaItemPropertyPlaybackDuration property key. The docs state:

The playback duration of the media item. Value is an NSNumber object representing a duration in seconds as an NSTimeInterval.

苍白女子 2024-12-24 15:43:23

如果您实际上仍然想知道采样率,那么可以这样做:
一旦您拥有了感兴趣的 AVAssetTrack,您就可以获取 AudioStreamBasicDescription 并检查它以找到原始采样率。

AVAssetTrack * track = ...;
CMAudioFormatDescriptionRef trackDescription = static_cast<CMAudioFormatDescriptionRef>([track.formatDescriptions firstObject]);
const AudioStreamBasicDescription * trackAsbd = CMAudioFormatDescriptionGetStreamBasicDescription(trackDescription);

double sampleRate = trackAsbd->mSampleRate;

错误检查省略...

if you are actually still wondering about the sample rate, it is done like so:
Once you have your AVAssetTrack you are interested in, you can get the AudioStreamBasicDescription and inspect that to find the original sample rate.

AVAssetTrack * track = ...;
CMAudioFormatDescriptionRef trackDescription = static_cast<CMAudioFormatDescriptionRef>([track.formatDescriptions firstObject]);
const AudioStreamBasicDescription * trackAsbd = CMAudioFormatDescriptionGetStreamBasicDescription(trackDescription);

double sampleRate = trackAsbd->mSampleRate;

error checking omitted...

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文