nvidia.dali.fn.experimental.inputs.video#
- nvidia.dali.fn.experimental.inputs.video(*, affine=True, blocking=False, bytes_per_sample_hint=[0], last_sequence_policy='partial', no_copy=False, preserve=False, sequence_length, device=None, name=None)#
从内存缓冲区流式传输和解码视频。用于处理长视频和高分辨率视频。
返回帧序列批次,布局为:
(F, H, W, C)
,其中F
- 序列中的帧数,H
- 帧的高度,W
- 帧的宽度,C
- 帧中的通道数。
当在 DALI Pipeline 中使用
fn.inputs.video
运算符时,用户需要使用Pipeline.feed_input()
提供数据。当运算符被馈送数据时,Pipeline 可以多次运行,并且fn.inputs.video
运算符将返回连续的序列,只要有足够的数据进行解码。当帧的来源(视频文件)耗尽时,用户需要再次调用feed_input
以向运算符提供下一个视频文件。此运算符具有用于数据的内部队列,因此可以多次调用feed_input
,并且当给定的视频文件结束时,运算符将自动从队列顶部获取下一个视频文件。在fn.inputs.video
没有数据运行时运行 pipeline 会导致错误。此运算符仅接受一个视频作为输入(即
input_batch_size=1
),并将返回序列批次。每个输出批次都将具有在 Pipeline 创建期间设置的max_batch_size
样本。当视频文件中的帧数不允许在批次之间均匀分割帧时,此运算符为给定视频返回的最后一个批次将是部分批次,并且此批次中的最后一个序列将使用last_sequence_policy
参数确定。例如This is a video that consists of 67 frames (every '-' is a frame): ------------------------------------------------------------------- User decided that there shall be 5 frames per sequence and the last_sequence_policy='partial': ------------------------------------------------------------------- [ ][ ][ ][ ][ ][ ][ ][ ][ ][ ][ ][ ][ ][] ------------------------------------------------------------------- Since there are not enough frames, the last sequence comprises 2 frames. The Pipeline has max_batch_size=3, therefore the operator will return 5 batches of sequences. First 4 batches comprise 3 sequences and the last batch is partial and comprises 2 sequences. --------------- --------------- --------------- --------------- ------- [ ][ ][ ] [ ][ ][ ] [ ][ ][ ] [ ][ ][ ] [ ][] --------------- --------------- --------------- --------------- ------- With the last_sequence_policy='pad', the last sequence of the last batch will be padded with 0: --------------- --------------- --------------- --------------- -------000 [ ][ ][ ] [ ][ ][ ] [ ][ ][ ] [ ][ ][ ] [ ][ ] --------------- --------------- --------------- --------------- -------000
fn.inputs.video
和fn.readers.video
之间的区别在于,前者从内存读取编码视频,而后者从磁盘读取编码视频。fn.inputs.video
和fn.decoders.video
之间的区别在于,前者不会一次性解码整个视频文件。对于较长的视频,这种行为是必需的。例如,5 分钟、4k、30fps 解码视频大约占用 1.7 TB 的内存。此运算符接受大多数视频容器和文件格式。FFmpeg 用于解析视频容器。在容器不包含所需元数据(例如帧大小、帧数等)的情况下,运算符需要自行查找,这可能会导致速度减慢。
- 支持的后端
‘cpu’
‘mixed’
- 关键字参数:
affine¶ (bool, optional, default = True) –
仅适用于混合后端类型。如果设置为 True,则内部线程池中的每个线程将绑定到特定的 CPU 核心。
否则,操作系统可以将线程重新分配给任何 CPU 核心。
blocking¶ (bool, optional, default = False) – 高级 如果
True
,则此运算符将阻塞,直到数据可用(例如,通过调用feed_input
)。如果False
,如果数据不可用,运算符将引发错误。bytes_per_sample_hint¶ (int or list of int, optional, default = [0]) –
每个样本的输出大小提示(以字节为单位)。
如果指定,则位于 GPU 或页锁定主机内存中的运算符输出将被预先分配,以容纳一批此大小的样本。
last_sequence_policy¶ (str, optional, default = ‘partial’) –
指定如何处理视频文件中的最后一个序列。
对于视频文件中的给定帧数和
frames_per_sequence
参数,可能会发生视频无法在序列之间均匀分割的情况。如果last_sequence_policy='partial'
,则最后一个序列可能具有少于指定的frames_per_sequence
值的帧数。如果last_sequence_policy='partial'
,则最后一个序列将始终具有frames_per_sequence
帧,并将填充空帧。允许的值为
'partial'
和'pad'
。no_copy¶ (bool, optional, default = False) –
确定在调用
feed_input
时 DALI 是否应复制缓冲区。如果设置为 True,DALI 会将用户的内存直接传递到 pipeline,而不是复制它。用户有责任保持缓冲区处于活动状态且未修改,直到 pipeline 使用它为止。
在相关迭代的输出被使用后,可以再次修改或释放缓冲区。实际上,它发生在
prefetch_queue_depth
或cpu_queue_depth * gpu_queue_depth
(当它们不相等时)迭代之后,紧随feed_input
调用之后。内存位置必须与运算符的指定
device
参数匹配。对于 CPU,提供的内存可以是一个连续的缓冲区或连续张量列表。对于 GPU,为避免额外的复制,提供的缓冲区必须是连续的。如果提供单独张量的列表,则会在内部进行额外的复制,从而消耗内存和带宽。preserve¶ (bool, optional, default = False) – 即使运算符的输出未使用,也阻止从图中删除该运算符。
sequence_length¶ (int) – 每个序列中的帧数。