关于使用音频队列服务同步音频的建议?

发布于 2024-10-06 00:21:32 字数 441 浏览 2 评论 0原文

我正在解码一种视频格式,该格式在单独的文件中具有随附的音轨。根据规范,我每 1/75 秒渲染一帧视频。并且视频文件的长度与音轨的长度相同。

我正在使用音频队列服务播放音频(我选择它是因为我认为在某些情况下我需要精确的时序控制 - 这正是我遇到的情况!)。这是一个很大的 API,我在 Apple 编程指南中的示例代码方面还没有取得太大进展(尽管我已经将其封装在一个更好的 ObjC API 中)。

在理想情况下,基本播放设置可以正常工作。视频和音频保持同步,并且同时结束(在我自己的能力范围内区分)。然而,如果性能出现问题(或者我附加了泄漏仪器或其他东西),它们很快就会失去同步。

这是我第一次写这种性质的东西:我以前没有声音或视频方面的经验。我当然没有音频队列服务的经验。所以我不知道从这里该去哪里。

你做过这样的事吗?您有什么建议、提示或技巧可以提供吗?我需要阅读一些基本文档吗?任何帮助将不胜感激。

I'm decoding a video format that has an accompanying audio track in a separate file. Per the specs, I render a frame of video every 1/75th second. And the length of the video file is the same as the length of the audio track.

I'm playing the audio with Audio Queue Services (which I chose because I figured there would be situations where I needed precise timing control -- just the sort of situation I'm encountering!). It's a big API and I haven't progressed much past the sample code in Apple's programming guide (though I have wrapped things up in a nicer ObjC API).

In ideal situations, things work fine with the basic playback setup. The video and audio stays synced and both end at the same time (within my own ability to tell the difference). However, if performance hiccups (or I attach the Leaks Instrument or something), they quickly get out of sync.

This is the first time I've ever written something of this nature: I have no prior experience with sound or video. I certainly have no experience with Audio Queue Services. So I'm not sure where to go from here.

Have you done something like this? Do you have some advice or tips or tricks to offer? Is there some fundamental piece of documentation I need to read? Any help would be greatly appreciated.

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

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

发布评论

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

评论(1

独行侠 2024-10-13 00:21:32

首先,我从来没有真正编写过这样的代码,所以我只是凭空猜测。另外,我已经使用 HAL 和 AUHAL 进行了大量编程,但从未使用 AudioQueue,因此我的方法可能不是使用 AQ 的最佳方法。

显然,首先要决定的是是将音频同步到视频还是将视频同步到音频。从这个问题来看,您似乎已经决定视频将成为主视频,并且音频应该与其同步。

我会通过跟踪渲染的视频帧数以及帧速率来解决这个问题。然后,在对音频缓冲区进行排队时,不要为 startTime 传递单调递增的值,而是调整缓冲区的开始时间以匹配视频中观察到的任何不连续性。这有点模糊,因为我不知道您的音频到底来自哪里,也不知道您如何将其排队,但希望原理很清楚。

First off, I've never actually coded anything like this so I'm shooting from the hip. Also, I've done a decent amount of programming with the HAL and AUHAL but never with AudioQueue so my approach might not be the best way to use AQ.

Obviously the first thing to decide is whether to sync the audio to the video or the video to the audio. From the question it seems you've decided the video will be the master and the audio should sync to it.

I would approach this by keeping track of the number of frames of video rendered, along with the frame rate. Then, when enqueuing your audio buffers, rather than passing a monotonically increasing value for the startTime adjust the buffer's start time to match any discontinuities observed in the video. This is a bit vague because I don't know exactly where your audio is coming from or how you are enqueuing it, but hopefully the principle is clear.

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