Video stream control and frame rate control

I am currently developing software for video streaming using VP8 and V4L2, but I am struggling with the key concepts of frame rate.

I have a basic working implementation that retrieves frames in a loop, encodes it and sends it over RTP (as fast as possible). However, I do not understand how to control the frame rate of a video or adjust the sampling.

Basically this can be summarized as follows:

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 } 

In particular, I do not understand how to correctly install:

  • V4L2 capture loop (do I need a timer to regularly sample frames?)
  • FRAME INTERVAL from V4L2 (required?)
  • Temporary libvpx base (should I use 1 / fps? 1001/30000?)
  • Pts value (is the number of frames required * (1 / fps) * 90,000?)
  • RTP timestamp (can I use dots here?)
  • Any other configuration options that may be taken into account ...
+4
source share
1 answer

V4L2 capture loop (do I need a timer to regularly sample frames?)

either, or find a way to block the stream until new data arrives (for example, using select() )

FRAME INTERVAL from V4L2 (required?)

it's not obligatory. when setting FRAME_INTERVAL, you tell the device to fetch data at a specified interval. the device can simply ignore the request (for example, because it cannot capture at a given selection). Also note that the internal clock of the device may be inaccurate and / or different from other clocks in your system.

Temporary libvpx base (should I use 1 / fps? 1001/30000?)

obviously, it depends on the frame rate.

the vpx documentation here is pretty clear:

Indicates the smallest time interval, in seconds, used by the stream. For material with a fixed frame rate or material with a variable frame rate where the frames are synchronized with a multiple of the specified hours (for example: video capture), the RECOMMENDED method is to set the inverse frame rate (for example: 1001/30000 for 29.970 Hz NTSC). This allows the dots to match the frame number, which can be convenient. To re-encode videos from containers with absolute timestamps, the RECOMMENDED method is to set up a temporary database for the parent container database or multimedia infrastructure (for example: 1/1000 for ms, as in FLV).

since the temporary base is of type vpx_rational , you need to express it as the relationship between two integers. for example, you cannot use 1/fps for NTSC weirdo speed.

Pts value (is the number of frames required * (1 / fps) * 90,000?)

no, not really (see above). it can be as simple as frame_num .

RTP timestamp (can I use dots here?)

Yes.

+1
source

Source: https://habr.com/ru/post/1492244/


All Articles