2017-09-06 24 views
0

在此先感谢。如何从appsink缓冲区中获取正确的视频帧数或时间位置

我想从rtsp摄像机录制视频,同时 处理通过新样本信号从appsink获得的视频帧。 然后,在一个单独的应用程序中,我读取录制的视频并显示与处理帧有关的信息。

文档说buffer-> offset有视频帧号,但不适用于我,它总是有相同的号码。

我有这样的管道:

rtspsrc location=rtsp://10.0.0.1:554/video.sdp latency=100 ! rtph264depay ! tee name=t 
! queue ! vaapidecodebin ! vaapipostproc format=rgba ! appsink name=appsink t. 
! queue ! h264parse ! mp4mux ! filesink sync=false name=filer location=/home/VideoDB/2017-09-04_16:33:46.mp4 

代码示例:

GstFlowReturn GstVideoSourcePrivate::newSample(GstAppSink* sink, gpointer user_data) 
{ 
.... 
    GstSample* sinkSample = gst_app_sink_pull_sample(GST_APP_SINK(sink)); 
    if (sinkSample) { 
     GstBuffer* buffer = gst_sample_get_buffer(sinkSample); 

     // I need this position to be the same as the recorded video 
     // or get the frame video sequence number, so that we 
     GstClockTime pos; 
     gst_element_query_position(self->pipeline(), GST_FORMAT_TIME, &pos); 
     ... 
    } 
    ... 
} 
+1

你好,你有没有试着用'GST_BUFFER_PTS(缓冲)'为了得到缓冲时间戳?你也可以将'rtspsrc'元素的'use-pipeline-clock'设置为'true'吗? – Ahresse

回答

0

谢谢您的回答。

我做了你告诉我的,但我无法得到预期的结果。

然后我发现当一个元素被插入流水线时,buffer-> offset开始显示正确的视频帧序列。但是,再次,我无法在几毫秒内获得良好的同步。

因此,我再次阅读了文档,并且为了获得更好的结果而编写了该代码。似乎有很少的延迟需要得到补偿。

https://gstreamer.freedesktop.org/documentation/application-development/advanced/clocks.html

https://gstreamer.freedesktop.org/documentation/plugin-development/advanced/clock.html

... 
int64_t timestam = GST_BUFFER_TIMESTAMP(buffer); 
GstSegment* segment = gst_sample_get_segment(sinkSample); 
gint64 pos = gst_segment_to_stream_time(segment, GST_FORMAT_TIME, timestam); 
GstQuery*q = gst_query_new_latency(); 
if (gst_element_query (self->m_pipeline, q)) { 
    gboolean live; 
    GstClockTime minlat, maxlat; 
    gst_query_parse_latency (q, &live, &minlat, &maxlat); 
    pos+= minlat; 
} 
gst_query_unref (q); 
... 
相关问题