我有一个Gstreamer
管道,当使用gst-launch
启动时可以工作,但我无法让它在python脚本中工作
gst-launch-1.0 v4l2src do-timestamp=true device=/dev/video0 ! image/jpeg,width=1920,height=1080,framerate=30/1 ! nvv4l2decoder mjpeg=1 ! nvvidconv flip-method=2 ! clockoverlay halignment=left valignment=bottom text="Dashcam" shaded-background=true font-desc="Sans, 12" ! omxh264enc ! 'video/x-h264, streamformat=(string)byte-stream' ! h264parse ! qtmux ! filesink location=video.mp4
我尝试在gst-launch
之后的所有内容上使用gst-parse
,尝试subprocess.popen,但无法确定gstreamer元素工厂的开头或结尾。有什么建议吗
我尝试过的事情:
import subprocess
dashcam = 'gst-launch-1.0 v4l2src do-timestamp=true device=/dev/video0 ! image/jpeg,width=1920,height=1080,framerate=30/1 ! nvv4l2decoder mjpeg=1 ! nvvidconv flip-method=2 ! clockoverlay halignment=left valignment=bottom text="Dashcam" shaded-background=true font-desc="Sans, 12" ! omxh264enc ! "video/x-h264, streamformat=(string)byte-stream" ! h264parse ! qtmux ! filesink location=video.mp4 -e'
dashcamPipe = subprocess.Popen(dashcam.split(), stdout=subprocess.PIPE)
output, error = dashcamPipe.communicate()
给了我这些错误
gst-launch-1.0:18562): GStreamer-CRITICAL **: 07:47:51.920: gst_element_make_from_uri: assertion 'gst_uri_is_valid (uri)' failed
(gst-launch-1.0:18562): GStreamer-CRITICAL **: 07:47:51.927: gst_element_link_pads_filtered: assertion 'GST_IS_BIN (parent)' failed
使用Gst.parse_启动
import gi
import sys
gi.require_version('Gst', '1.0')
from gi.repository import Gst, GObject
Gst.init(sys.argv)
pipeline = Gst.parse_launch('v4l2src do-timestamp=true device=/dev/video0 ! image/jpeg,width=1920,height=1080,framerate=30/1 ! nvv4l2decoder mjpeg=1 ! nvvidconv flip-method=2 ! clockoverlay halignment=left valignment=bottom text="Dashcam" shaded-background=true font-desc="Sans, 12" ! omxh264enc ! "video/x-h264, streamformat=(string)byte-stream" ! h264parse ! ! qtmux ! filesink location=video.mp4
给我
(record.py:18791): GStreamer-CRITICAL **: 07:53:00.456: gst_element_make_from_uri: assertion 'gst_uri_is_valid (uri)' failed
(record.py:18791): GStreamer-CRITICAL **: 07:53:00.463: gst_element_link_pads_filtered: assertion 'GST_IS_BIN (parent)' failed
Traceback (most recent call last):
File "record.py", line 8, in <module>
pipeline = Gst.parse_launch('v4l2src do-timestamp=true device=/dev/video0 ! image/jpeg,width=1920,height=1080,framerate=30/1 ! nvv4l2decoder mjpeg=1 ! nvvidconv flip-method=2 ! clockoverlay halignment=left valignment=bottom text="Dashcam" shaded-background=true font-desc="Sans, 12" ! omxh264enc ! "video/x-h264, streamformat=(string)byte-stream" ! h264parse ! qtmux ! filesink location=video.mp4')
GLib.Error: gst_parse_error: syntax error (0)
Furas把它钉在了their comment上。所有问题都是由主管道元素中的
" "
引起的。去掉它们可以修复popen
和解析新(和更新)代码:
这将开始录制,等待10秒钟,然后在其他人需要时优雅地结束
相关问题 更多 >
编程相关推荐