Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/316.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
GStreamer Python录制和保存桌面视频_Python_Python 3.x_Gstreamer_Python Gstreamer - Fatal编程技术网

GStreamer Python录制和保存桌面视频

GStreamer Python录制和保存桌面视频,python,python-3.x,gstreamer,python-gstreamer,Python,Python 3.x,Gstreamer,Python Gstreamer,我有以下命令行代码: gst-launch-1.0 ximagesrc startx=0 use-damage=0 ! video/x-raw,framerate=30/1 ! videoscale method=0 ! video/x-raw,width=1280,height=1080 ! ximagesink 是否可以在python中使用gstreamer从桌面录制视频输出并将其保存到文件中。该命令打开一个窗口并正确显示桌面活动,但我想将此输出转换为python中的视频文件 提前感谢您

我有以下命令行代码:

gst-launch-1.0 ximagesrc startx=0 use-damage=0 ! video/x-raw,framerate=30/1 ! videoscale method=0 ! video/x-raw,width=1280,height=1080  ! ximagesink
是否可以在python中使用gstreamer从桌面录制视频输出并将其保存到文件中。该命令打开一个窗口并正确显示桌面活动,但我想将此输出转换为python中的视频文件


提前感谢您的帮助。

您可能会遇到问题,这取决于您的系统上有哪些编解码器和gstreamer的其他元素,但这对我很有用:

gst-launch-1.0 ximagesrc startx=0 use-damage=0 ! video/x-raw,framerate=30/1 ! videoscale method=0 ! video/x-raw,width=1280,height=1080  ! videoconvert ! x264enc ! avimux ! filesink location=output2.avi
因此需要videoconvert,因为x264enc与ximagesink的输入类型不同。x264enc本身就是编解码器,avimux将压缩视频放入avi容器中,FileLink用于写入文件

对于Python API,一个简单的MCVE是:

#!/usr/bin/python

import os
import gi
import sys
import time

gi.require_version('Gtk', '3.0')
gi.require_version('Gst', '1.0')
from gi.repository import Gst, GObject, Gtk

Gtk.init(sys.argv)

# initialize GStreamer
Gst.init(sys.argv)

pipeline = Gst.parse_launch ("ximagesrc startx=0 use-damage=0 ! video/x-raw,framerate=30/1 ! videoscale method=0 ! video/x-raw,width=1280,height=1080  ! videoconvert ! x264enc ! avimux ! filesink location=output4.avi")
pipeline.set_state(Gst.State.PLAYING)
time.sleep(15)
pipeline.set_state(Gst.State.NULL)

谢谢你的帮助。我想知道您是否知道如何将此命令转换为Python代码?这正是我所需要的,但我不确定用Python实现这一点的最佳方法。