给定一些时间戳(可能是秒或毫秒精度),我需要提取最近的帧 在每帧具有假定相机时间戳(捕获时间,不是 pts 或 dts)的 mp4 文件中,什么是更合适的管道来提取捕获时间戳中的每个帧(就像从缓冲区中使用 GetReferenceTimestampMeta 一样)?鉴于我通过 gstreamer-sharp 工作,我希望使用 appsink 事件,例如:
private static void AppSink_NewSample(object o, NewSampleArgs args)
{
if (o is AppSink aps)
{
var sample = aps.PullSample();
var buf = sample.Buffer;
buf.Map(out var info, MapFlags.Read);
//application/x-rtp
var tsMeta = buf.GetReferenceTimestampMeta();
//NOTE tsMeta shouldn't be null there...
//TODO some timestamps compare logic
buf.Unmap(info);
}
Counter++;
}
简单地说——我需要迭代帧并根据某种条件选择一个帧(实际上,最接近给定的时间戳)。
提前致谢。
我找到了方法,就像:
var appSink = (AppSink) readerPipe.GetByName("my_appsink");
readerPipe.SetName($"frame_stepper");
var q = readerPipe.SetState(State.Playing);
var step = 1;
while (step < frameNumber)
{
appSink.PullSample();
step++;
}