我有一个用java编写的rtsp播放器应用程序,它构建在gstreamer之上。当我尝试在播放视频的顶部显示文本时,管道中只有一个textoverlay元素,它工作正常。但我需要在窗口的所有角落显示不同的文本。
首先想到的是我将链接元素链接到gst-launch-1.0的命令行,如下所示;
gst-launch-1.0 -v rtspsrc location=rtsp://10.0.5.41:8554 ! rtpjitterbuffer ! rtph264depay ! vaapiparse_h264 ! vaapidecodebin ! textoverlay text = "live video" halignment=left ! textoverlay text="action camera 1" ! xvimagesink
当我尝试使用java构建相同的管道时,如下所示;
this.sourceElement = ElementFactory.make(RTSP_SOURCE, RTSP_SOURCE);
final Element videoQueue = ElementFactory.make(QUEUE, QUEUE);
final Element videoDepay = ElementFactory.make(RTP_H264_DEPAY, RTP_H264_DEPAY);
final Element videoParser = ElementFactory.make(VAAPI_H264_PARSE, VAAPI_H264_PARSE);
final Element videoDecoder = ElementFactory.make(VAAPI_DECODE, VAAPI_DECODE);
videoTypeOverlay = ElementFactory.make(TEXT_OVERLAY, TEXT_OVERLAY);
videoSourceOverlay = ElementFactory.make(TEXT_OVERLAY, TEXT_OVERLAY);
sinkElement = ElementFactory.make(XV_IMAGE_SINK, XV_IMAGE_SINK);
pipe.addMany(sourceElement, videoQueue, videoDepay, videoParser, videoDecoder, videoSourceOverlay, videoTypeOverlay, sinkElement);
Element.linkMany(videoQueue, videoDepay, videoParser, videoDecoder, videoSourceOverlay, videoTypeOverlay, sinkElement);
sourceElement.connect((Element.PAD_ADDED) (element, pad) -> {
if (pad.isLinked()) {
return;
}
Caps caps = pad.getCaps();
if (caps.size() > 0) {
String mediaType = caps.getStructure(0).getString("media");
if ("video".equalsIgnoreCase(mediaType)) {
pad.link(videoQueue.getStaticPad("sink"));
}
}
});
@Override
public void play(PlaySettings playSettings) {
videoTimeOverlay.set("text", text);
videoTimeOverlay.set("valignment", valign);
videoTimeOverlay.set("halignment", halign);
...
}
我得到一张空白画布。 使应用程序至少工作的唯一方法是从linkMany和addMany行中删除其中一个叠加层,如下所示;
pipe.addMany(sourceElement, videoQueue, videoDepay, videoParser, videoDecoder, videoSourceOverlay, sinkElement);
Element.linkMany(videoQueue, videoDepay, videoParser, videoDecoder, videoSourceOverlay, sinkElement);
那么如何在视频画布上放置多个静态叠加字符串呢?