本文介绍了MPEG2演示时间戳(PTS)计算的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个MPEG2 TS文件,现在我有兴趣从每个图片框提取PTS信息。我知道PTS被描述在33位,包括3个标记位。但我不知道这个位域如何转换为更容易理解的形式(秒,毫秒)。任何人都可以帮助我

I have an MPEG2 TS file and now I am interested in extracting PTS information from each picture frame. I know that PTS is described in 33 bits including 3 marker bits. But I don't know how this bitfield can be converted to more understandable form (seconds, milliseconds). Can anybody help me please

推荐答案

MPEG2传输流时钟(PCR,PTS,DTS)都有1/90000秒。 PTS和DTS有三个标记位,您需要跳过。模式总是(从最高有效位到最低有效位)3位,标记,15位,标记,15位,标记。标记必须等于1.在C中,删除标记将工作如下:

The MPEG2 transport stream clocks (PCR, PTS, DTS) all have units of 1/90000 second. The PTS and DTS have three marker bits which you need to skip over. The pattern is always (from most to least significant bit) 3 bits, marker, 15 bits, marker, 15 bits, marker. The markers must be equal to 1. In C, removing the markers would work like this:

uint64_t v; // this is a 64bit integer, lowest 36 bits contain a timestamp with markers
uint64_t pts = 0;
pts |= (v >> 3) & (0x0007 << 30); // top 3 bits, shifted left by 3, other bits zeroed out
pts |= (v >> 2) & (0x7fff << 15); // middle 15 bits
pts |= (v >> 1) & (0x7fff <<  0); // bottom 15 bits
// pts now has correct timestamp without markers in lowest 33 bits 

它们还具有9bits的扩展字段,形成42位整数,其中扩展是最低有效位。基本+扩展的单位为1/27000000秒。许多实现将扩展名全部留为零。

They also have an extension field of 9bits, forming a 42bit integer in which the extension is the least significant bits. The units for the base+extension are 1/27000000 second. Many implementations leave the extension as all zeros.

这篇关于MPEG2演示时间戳(PTS)计算的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-27 10:25