处理线性 DAI 视频流中的定时元数据
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
互动式媒体广告 (IMA) 动态广告插播 SDK (DAI) 依赖于
流的媒体片段中嵌入的元数据信息(带内元数据);
也可以在流式传输清单文件(清单中元数据)中跟踪观看者
位置和客户端广告事件。可从 DAI 视频流中获取元数据
采用不同的格式,具体取决于正在播放的直播类型。IMA DAI
SDK 通过一个 API 处理所有元数据格式。
您的应用负责捕获元数据并将其转发到 IMA DAI SDK。SDK 提供了
StreamManager.onMessage()
方法来传递此信息。此方法以
roVideo 端口提供的 msg
对象。然后,系统会通过
使用 IMA DAI SDK 确定广告事件的时间安排。只需要一个
参数:
以下示例展示了如何处理来自 roVideo 端口和
通过 StreamManager.onMessage()
将其传递给 IMA DAI SDK。
Sub runLoop()
' Forward all timed metadata events to IMA.
m.top.video.timedMetaDataSelectionKeys = ["*"]
' Cycle through all the fields and set listeners.
' IMPORTANT: Failure to listen to the position and timedmetadata fields could
' result in ad impressions not being reported.
m.port = CreateObject("roMessagePort")
fields = m.top.video.getFields()
for each field in fields
m.top.video.observeField(field, m.port)
end for
while True
msg = wait(1000, m.port)
if m.top.video = invalid
print "exiting"
exit while
end if
m.streamManager.onMessage(msg)
currentTime = m.top.video.position
If currentTime > 3 And not m.top.adPlaying
m.top.video.enableTrickPlay = true
End If
end while
End Sub
详细了解如何整合循环处理数据流元数据
进入应用后,请查看
IMA Roku 入门指南。通过
事件监听器和数据流开始部分
包含元数据处理循环。
HLS CMAF 视频流
使用通用媒体应用框架 (CMAF) 遍历的线性 DAI HLS 视频流
通过带内 eMSGv1 框进入 ID3 到
CMAF 标准。这些 eMSG 箱
嵌入在每个媒体段开头,其中每个 ID3 eMSG 包含
相对于视频流中最后一次不连续性的 PTS。
对于 IMA Roku,所有 HLS CMAF 视频流都使用 eMSGv0 格式发送带内 ID3 数据。
IMA 会将 eMSGv0 格式提供的信息与
从视频对象请求广告
为了正确解析 HLS CMAF 数据流 ID3 事件,您必须将
来请求视频流对象
StreamRequest.videoObject
。
如未另行说明,那么本页面中的内容已根据知识共享署名 4.0 许可获得了许可,并且代码示例已根据 Apache 2.0 许可获得了许可。有关详情,请参阅 Google 开发者网站政策。Java 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-08-21。
[null,null,["最后更新时间 (UTC):2025-08-21。"],[[["\u003cp\u003eThe IMA DAI SDK uses metadata embedded within media segments or streaming manifests to track viewer positions and ad events, simplifying ad insertion in live and on-demand content.\u003c/p\u003e\n"],["\u003cp\u003eYour app needs to capture metadata from the roVideo port and forward it to the IMA DAI SDK using the \u003ccode\u003eStreamManager.onMessage()\u003c/code\u003e method for proper ad tracking.\u003c/p\u003e\n"],["\u003cp\u003eHLS CMAF streams utilize in-band eMSGv1 boxes following the ID3 through CMAF standard to pass timed metadata for ad cue points.\u003c/p\u003e\n"],["\u003cp\u003eTo ensure accurate parsing of HLS CMAF stream ID3 events, include the video object in the stream request using \u003ccode\u003eStreamRequest.videoObject\u003c/code\u003e.\u003c/p\u003e\n"]]],["The Interactive Media Ads (IMA) Dynamic Ad Insertion SDK uses in-band or in-manifest metadata to track viewer positions and ad events. Apps capture this metadata and use the `StreamManager.onMessage()` method to forward it to the SDK. This method processes `msg` objects from the roVideo port to time ad events. The example shows a loop that observes video fields, forwards timed metadata to IMA via `onMessage()`, and monitors the video's current position. HLS CMAF streams pass timed metadata via in-band eMSGv1 boxes.\n"],null,["# Handle timed metadata in linear DAI streams\n\nThe Interactive Media Ads (IMA) Dynamic Ad Insertion SDK (DAI) relies on\nmetadata information embedded in the stream's media segments (in-band metadata),\nor in the streaming manifest file (in-manifest metadata) to track viewers'\npositions and client-side ad events. Metadata is available from the DAI stream\nin different formats, depending on the type of stream being played. The IMA DAI\nSDK handles all metadata formats through a single API.\n\nYour app is responsible for capturing metadata and forwarding it to the IMA DAI SDK. The SDK offers the\n[`StreamManager.onMessage()`](/ad-manager/dynamic-ad-insertion/sdk/roku/apis#ima.StreamManager.onMessage)\nmethod to pass this information. This method forwards metadata in the form of a\n`msg` object provided by the roVideo port. These objects are then processed by\nthe IMA DAI SDK to establish the timing for ad events. It takes a single\nargument:\n\n- `msg`: a msg type object provided by the roVideo port.\n\nMetadata sample code\n--------------------\n\nHere's an example of how to handle the metadata from the roVideo port and\npass it to the IMA DAI SDK through `StreamManager.onMessage()`. \n\n Sub runLoop()\n ' Forward all timed metadata events to IMA.\n m.top.video.timedMetaDataSelectionKeys = [\"*\"]\n\n ' Cycle through all the fields and set listeners.\n ' IMPORTANT: Failure to listen to the position and timedmetadata fields could\n ' result in ad impressions not being reported.\n m.port = CreateObject(\"roMessagePort\")\n fields = m.top.video.getFields()\n for each field in fields\n m.top.video.observeField(field, m.port)\n end for\n\n while True\n msg = wait(1000, m.port)\n if m.top.video = invalid\n print \"exiting\"\n exit while\n end if\n\n m.streamManager.onMessage(msg)\n currentTime = m.top.video.position\n If currentTime \u003e 3 And not m.top.adPlaying\n m.top.video.enableTrickPlay = true\n End If\n end while\n End Sub\n\nFor more information on how to incorporate the loop handling stream metadata\ninto your app, see the\n[IMA Roku getting started guide](/ad-manager/dynamic-ad-insertion/sdk/roku). The\n[event listener and stream start section](/ad-manager/dynamic-ad-insertion/sdk/roku#add-event-listeners-and-start-the-stream)\nof the guide contains the metadata handling loop.\n\nHLS CMAF streams\n----------------\n\nLinear DAI HLS streams using the Common Media Application Framework (CMAF) pass\ntimed metadata through in-band eMSGv1 boxes following the [ID3 through\nCMAF](//aomediacodec.github.io/id3-emsg/) standard. These eMSG boxes are\nembedded at the beginning of each media segment, with each ID3 eMSG containing\na PTS relative to the last discontinuity in the stream.\n\nFor IMA Roku, all HLS CMAF streams send in-band ID3 data using the eMSGv0 format.\nIMA combines information provided by the eMSGv0 format with information\nfrom the video object.\n\nTo enable proper parsing of HLS CMAF stream ID3 events, you must send your\nvideo object in the stream request using\n[`StreamRequest.videoObject`](/ad-manager/dynamic-ad-insertion/sdk/roku/apis#ima.StreamRequest.videoObject)."]]