[DirectShow] 022 - Time Stamps

The time stamp defines a media sample's start and finish times, measured in stream time. The time stamp is sometimes called the presentation time . When reading the rest of this article, it is important to remember that not all formats use time stamps in the same way. For example, not all MPEG samples are time stamped. In MPEG filter graphs, the time stamp is not applied to each frame until they are output from the decoder.

时间戳定义 media sample 的开始和结束时间,按流时间计量。时间戳有时被叫做显示时间。读这片文章剩下部分的时候,最重要的一点是记住不是所有格式按照同样的方式使用时间戳。例如,不是所有的 MFPE sample 都有时间戳。在 MPEG filter graph 中,时间戳没有被应用到每一帧知道它们从 decoder 输出。

When a renderer filter receives a sample, it schedules rendering based on the time stamp. If the sample arrives late, or has no time stamp, the filter renders the sample immediately. Otherwise, the filter waits until the sample's start time before it renders the sample. (It waits for the start time by calling the IReferenceClock::AdviseTime method.)

renderer filter 接收到一个 sample ,它按照时间戳播放。如果 sample 到达的时候晚了,或者没有时间戳, filter 就立即播放 sample 。否则, filter 等待,直到 sample 的开始时间在播放 sample 之前。(调用 IReferenceClock::AdviseTime 函数等待开始时间。)

Source filters and parser filters are responsible for setting the correct time stamps on the samples they process. Use the following guidelines.

source filter parser filter 负责在他们处理的 sample 上设置适当的时间戳。使用下列方法:

·         File playback: The first sample is time stamped with a start time of zero. Subsequent time stamps are determined by the sample length and the playback rate, which itself is determined by the file format. The filter that parses the file is responsible for calculating the correct time stamps (for example, the AVI Splitter ).

·         Video and audio capture: Every sample is time stamped with a start time equal to the stream time when it was captured, with the following caveats:

·         Video frames from a preview pin (as opposed to a capture pin) are not time stamped. Because of graph latency, a video frame that is stamped with the capture time will always arrive late at the video renderer. This may cause the renderer to drop frames, in an attempt at quality control. For information about quality control, see Quality-Control Management .

·         Audio capture: The audio capture filter uses its own set of buffers, which are separate from those used by the audio driver. The audio driver fills the capture filter's buffers at fixed intervals. The interval depends on the driver, but generally is not more than 10 milliseconds. The time stamps on the audio samples reflect the time when the driver filled the audio capture filter's buffers. These times can be slightly inaccurate, especially if the application is using a very small buffer size. However, the media times will accurately reflect the number audio samples in the buffer.

·         Mux filters: Depending on the output format, a mux filter may need to generate time stamps, or it may not. For example, the AVI file format uses a fixed frame rate with no time stamps, so the AVI Mux filter assumes that samples are arriving at approximately the right time. If the incoming time stamps show a gap larger than one frame, however, the AVI Mux writes an index entry with size zero, to indicate a dropped frame. On file playback, new time stamps are generated at run time, as described previously.

文件回放:第一个 sample 被标记 0 的开始时间。随后的时间戳由 sample 的长度和回放频率决定,由自身的格式决定。解析文件的 filter 负责计算适当的时间戳。

视频和音频采集:每一个 sample 标上的开始时间都是它被采集的时候的流时间。

preview pin 输出的视频帧没有时间戳。因为 graph 延时,被标上采集时间的视频帧到达时可能已经晚于 video renderer 。这可能导致 renderer 丢帧,在质量控制方面的尝试。

音频采集:音频采集 filter 使用自己的缓冲集合 . 音频驱动固定间隔填充采集 filter 的缓冲。间隔依赖驱动,但通常不超过 10 毫秒。音频 sample 上的时间戳反映了驱动填充音频采集 filter 缓冲时的时间。这个时间可能不准确,特别是应用程序使用非常小的缓冲。不过, media time 正确的反映了缓冲中的音频 sample 数量。

Mux filter mux filter 可能需要时间戳也可能不需要,这取决于输出格式。例如, AVI 文件格式使用固定帧率就不需要时间戳,所以 AVI Mux filter 假设 sample 按照近似正确的时间到达。如果到达的时间戳显示大于一帧的间隔, AVI Mux 写入一个 0 索引项标识这是丢掉的帧。在文件回放时,新的时间戳在运行时产生。

Optionally, the filter can also specify a media time for the sample. In a video stream, media time represents the frame number. In an audio stream, media time represents the sample number in the packet. For example, if each packet contains one second of 44.1 kilohertz (kHz) audio, the first packet has a media start time of zero and a media stop time of 44100. In a seekable stream, the media time is always relative to the start time of the stream. For example, suppose you seek to 2 seconds from the start of a 15-fps video stream. The first media sample after the seek has a time stamp of zero but a media time of 30.

filter 也可以给 sample 指定一个 media time 。在视频流中, media time 代表帧数,在音频流中, media time 代表包中的帧数。例如,如果每个包包含 44 1KHZ 之一秒的音频,那么第一个包的 media start time 0 media stop time 44100 。在可检索的流中, media time 与流的开始时间有关。例如,如果在每秒 15 帧的视频流中找到第二秒。第一个 media sample 的时间戳是 0 media time 30.

Renderer and mux filters can use the media time to determine whether frames or samples have been dropped, by checking for gaps. However, filters are not required to set the media time. To set the media time on a sample, call the IMediaSample::SetMediaTime method.

renderer filter mux filter 可以通过判断 media time 的差距决定是否丢弃帧或者 sample 。不过, filter 不一定需要设置 media time 。要设置 media time ,调用 IMediaSample::SetMediaTime 数。

 

 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值