Reputation: 321
I read H.264 frames from Logitech C920 webcamera using v4l2. How can I get their PTS and DTS in my program? For example, I can determine frame type using this function:
// < 0 = error
// 0 = I-Frame
// 1 = P-Frame
// 2 = B-Frame
// 3 = S-Frame
int VOutVideoStream::getVopType( const std::vector<uint8_t>& image )
{
if( image.size( ) < 6 )
return -1;
unsigned char *b = (unsigned char*)image.data( );
// Verify NAL marker
if( b[ 0 ] || b[ 1 ] || 0x01 != b[ 2 ] ) {
++b;
if ( b[ 0 ] || b[ 1 ] || 0x01 != b[ 2 ] )
return -1;
}
b += 3;
// Verify VOP id
if( 0xb6 == *b ) {
++b;
return ( *b & 0xc0 ) >> 6;
}
switch( *b ) {
case 0x65: return 0;
case 0x61: return 1;
case 0x01: return 2;
}
return -1;
}
Upvotes: 1
Views: 9123
Reputation: 9573
PTS and DTS are not part of the H.264 bitstream.
Generally a PTS is associated with a frame grabbed from the camera.
If your camera does not provide an API to get the PTS and DTS of the frame, you might be able to use something like gettimeofday()
as a pts for the frame.
In the case that camera already outputs H.264 encoded frames, you would also need to take into account the GOP structure used for encoding, though I'm guessing that if the camera already outputs H.264, there is likely an API to get hold that information.
Upvotes: 4