video-streaming - 视频流捕捉和帧率控制

标签 video-streaming video-capture rtp v4l2 vp8

我目前正在使用 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
}

特别是,我不知道如何正确设置:
  • V4L2 捕获循环(是否需要计时器来定期获取帧?)
  • V4L2 中的 FRAME INTERVAL 设置(它是强制性的吗?)
  • libvpx 时基(我应该使用 1/fps 吗?1001/30000 吗?)
  • pts 值(是否需要为帧数 * (1/fps) * 90000 ?)
  • RTP 时间戳(我可以在这里使用 pts 吗?)
  • 可以考虑的任何其他配置设置...
  • 最佳答案

    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/

    相关文章:

    FFMPEG 流式传输 RTP : time base not set

    javascript - 每个人都观看相同的嵌入式视频

    android - 在 native 可执行文件 (android) 中绑定(bind) TCP 端口失败

    python - 使用 python 和 opencv 保存视频时出错

    iPhone视频捕捉(最佳方法)

    uiimagepickercontroller - 带有mp4格式的IOS UIImagePicker

    c# - 如何使用 C# 创建视频流

    C++ ffmpeg实时视频传输

    android - 无法从 Android 将视频作为 rtp 流发送

    android - 从 Android 源代码构建/查找共享库