Homebrew Gstreamer、Python 和视频

问题描述 投票:0回答:1

我正在尝试完成 Gstreamer 教程,但我已经卡在了前两个(1st2nd)。这是第二课代码的副本,供参考:

#!/usr/bin/env python3
import sys
import gi
import logging

gi.require_version("GLib", "2.0")
gi.require_version("GObject", "2.0")
gi.require_version("Gst", "1.0")

from gi.repository import Gst, GLib, GObject


logging.basicConfig(level=logging.DEBUG, format="[%(name)s] [%(levelname)8s] - %(message)s")
logger = logging.getLogger(__name__)

# Initialize GStreamer
Gst.init(sys.argv[1:])

# Create the elements
source = Gst.ElementFactory.make("videotestsrc", "source")
sink = Gst.ElementFactory.make("autovideosink", "sink")

# Create the empty pipeline
pipeline = Gst.Pipeline.new("test-pipeline")

if not pipeline or not source or not sink:
    logger.error("Not all elements could be created.")
    sys.exit(1)


# Build the pipeline
pipeline.add(source, sink)
if not source.link(sink):
    logger.error("Elements could not be linked.")
    sys.exit(1)

# Modify the source's properties
source.props.pattern = 0
# Can alternatively be done using `source.set_property("pattern",0)`
# or using `Gst.util_set_object_arg(source, "pattern", 0)`

# Start playing
ret = pipeline.set_state(Gst.State.PLAYING)
if ret == Gst.StateChangeReturn.FAILURE:
    logger.error("Unable to set the pipeline to the playing state.")
    sys.exit(1)

# Wait for EOS or error
bus = pipeline.get_bus()
msg = bus.timed_pop_filtered(Gst.CLOCK_TIME_NONE, Gst.MessageType.ERROR | Gst.MessageType.EOS)

# Parse message
if msg:
    if msg.type == Gst.MessageType.ERROR:
        err, debug_info = msg.parse_error()
        logger.error(f"Error received from element {msg.src.get_name()}: {err.message}")
        logger.error(f"Debugging information: {debug_info if debug_info else 'none'}")
    elif msg.type == Gst.MessageType.EOS:
        logger.info("End-Of-Stream reached.")
    else:
        # This should not happen as we only asked for ERRORs and EOS
        logger.error("Unexpected message received.")

pipeline.set_state(Gst.State.NULL)

如果我运行这段代码,Python 的火箭图标开始在 Dock 上跳跃,但没有显示视频。如果我用

GST_DEBUG=5 python3 02.py
启动它,我可以看到正在发生的事情和时间在流逝,只是没有视频输出。

当我运行第一节课的代码时,它创建了一个

playbin
,Dock 上没有Python 火箭;我听到音频在播放,但还是没有视频。

如果我更改第 2 课的代码(上面复制的)并将

videotestsrc
autovideosink
变成
audiotestsrc
autoaudiosink
(并注释掉
pattern
参数),它再次起作用——我可以听到哔哔

Gstreamer 命令行工具正常工作,显示等效管道的视频窗口:

gst-launch-1.0 playbin uri=https://gstreamer.freedesktop.org/data/media/sintel_trailer-480p.webm
gst-launch-1.0 videotestsrc pattern=0 ! autovideosink

知道为什么 Python 版本不能正常工作吗?


我在 Mac OS Ventura 13.2.1 (22D68) 上使用

brew install gstreamer
(版本:
stable 1.22.2 (bottled), HEAD
)和 Python 3.11.3 安装了 Gstreamer。

python macos gstreamer python-gstreamer
1个回答
1
投票

我相信你的python代码没有问题。

autovideosink
.

选择的元素可能有问题

我已经看到

vaapisink
发生这种情况,由于 GPU 驱动程序错误或任何不兼容,它无法显示窗口。您可以通过使用详细 (
autovideosink
) 选项运行管道来确定
-v
选择哪个接收器。

如果是 vaapisink,您可以卸载 gstreamer vaapi 元素 (

apt remove gstreamer1.0-vaapi
) 或尝试修复您的安装。如果它是另一个接收器元素,您将需要调试该特定元素安装或将其卸载。一旦修复或卸载
autovideosink
将使用固定版本或选择另一个可能适合您的接收器选项。

如果您只是对输出感兴趣并且不一定使

autiovideosink
工作,您可以将
autovideosink
替换为另一个您确定适用于您的系统的显式视频接收器,我建议您尝试
xvimagesink
ximagesink 
.那应该正确显示
videotestsrc

© www.soinside.com 2019 - 2024. All rights reserved.