我目前正在使用 VP8 和 V4L2 开发视频流软件,但我正在努力解决帧评级的关键概念。
我有一个基本的工作实现,它在循环中获取帧,对其进行编码并通过 RTP 发送(尽可能快)。
但是,我不明白如何控制视频的帧率或调节采样。
基本上可以总结如下:
while (true) {
ioctl(fd, VIDIOC_DQBUF, buf); // Get the V4L buffer
vpx_codec_encode(...); // VP8 encode using pts and timebase
sendto(); // Send through RTP with the correct timestamp
}
特别是,我不知道如何正确设置:
最佳答案
The V4L2 capture loop (does it need a timer to fetch frames on a regular basis ?)
要么,要么找到一种方法来阻止线程直到新数据到达(例如使用
select()
)The FRAME INTERVAL setting from V4L2 (is it mandatory ?)
这不是强制性的。设置 FRAME_INTERVAL 时,您告诉设备以指定的时间间隔对数据进行采样。
设备可能会简单地忽略该请求(例如,因为它无法以给定的采样率进行捕获)。
另请注意,设备的内部时钟可能不准确和/或与系统上的其他时钟不同。
The libvpx timebase (should I use 1/fps ? 1001/30000 ?)
显然这取决于你的帧率。
vpx 文档在这里很清楚:
Indicates the smallest interval of time, in seconds, used by the stream. For fixed frame rate material, or variable frame rate material where frames are timed at a multiple of a given clock (ex: video capture), the RECOMMENDED method is to set the timebase to the reciprocal of the frame rate (ex: 1001/30000 for 29.970 Hz NTSC). This allows the pts to correspond to the frame number, which can be handy. For re-encoding video from containers with absolute time timestamps, the RECOMMENDED method is to set the timebase to that of the parent container or multimedia framework (ex: 1/1000 for ms, as in FLV).
因为时基的类型是
vpx_rational
,您需要将其表示为两个整数之间的比率。例如您不能使用 1/fps
对于 NTSC 的怪人率。The pts value (Does it need to be frame num * (1/fps) * 90000 ?)
不是真的(见上文)。它可以像
frame_num
一样简单.The RTP timestamp (Can I use the pts here ?)
是的。
关于video-streaming - 视频流捕捉和帧率控制,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17741112/