如何使用 gstreamer 流式传输 H264?

How to stream H264 with gstreamer?

我需要使用 H264,通过 gstreamer 将我的全高清屏幕流式传输到我的 android phone。我在 Android 上使用 gst launch remote,在 linux 上使用 gst-launch

我从 gstreamer 开始,我设法在 this tutorial 之后做基本的流,但是任何与示例有点不同的东西都会以各种方式崩溃。

我的基本流程是:

ximagesrc use-damage=false xname=/usr/lib/torcs/torcs-bin ! videoconvert ! x264enc tune=zerolatency ! rtph264pay ! udpsink host=192.168.0.100 port=5000

并且:

udpsrc port=5000 caps=$CAPS ! rtph264depay ! avdec_h264 ! autovideosink

我试图将第一个管道(所有或多个独立参数的组合)的上限复制到 $CAPS,但没有成功。

caps="video/x-h264\,\ codec_data\=\(buffer\)01f40028ffe1001a67f400289196401e0089f89c0440000003004000000ca3c60c9201000668ebcc448440\,\ stream-format\=\(string\)avc\,\ alignment\=\(string\)au\,\ level\=\(string\)4\,\ profile\=\(string\)high-4:4:4\,\ width\=\(int\)1920\,\ height\=\(int\)1080\,\ pixel-aspect-ratio\=\(fraction\)1/1\,\ framerate\=\(fraction\)25/1"

管道没有构建,唯一的错误是:

WARNING: erroneous pipeline: could not link udpsrc0 to rtph264depay0

或大写

application/x-rtp\,\ media\=\(string\)video\,\ clock-rate\=\(int\)90000\,\ encoding-name\=\(string\)H264\,\ packetization-mode\=\(string\)1\,\ payload\=\(int\)96\,\ a-framerate\=\(string\)25

错误是:

ERROR: from element /GstPipeline:pipeline0/GstUDPSrc:udpsrc0: Internal data flow error.

不带大写字母的错误信息:

Setting pipeline to PAUSED ...
libva info: VA-API version 0.39.0
libva info: va_getDriverName() returns 0
libva info: Trying to open /usr/lib/x86_64-linux-gnu/dri/i965_drv_video.so
libva info: Found init function __vaDriverInit_0_39
libva info: va_openDriver() returns 0
Pipeline is live and does not need PREROLL ...
Got context from element 'autovideosink0': gst.vaapi.Display=context, gst.vaapi.Display=(GstVaapiDisplay)NULL;
Setting pipeline to PLAYING ...
New clock: GstSystemClock
ERROR: from element /GstPipeline:pipeline0/GstRtpH264Depay:rtph264depay0: No RTP format was negotiated.
Additional debug info:
gstrtpbasedepayload.c(484): gst_rtp_base_depayload_handle_buffer (): /GstPipeline:pipeline0/GstRtpH264Depay:rtph264depay0:
Input buffers need to have RTP caps set on them. This is usually achieved by setting the 'caps' property of the upstream source element (often udpsrc or appsrc), or by putting a capsfilter element before the depayloader and setting the 'caps' property on that. Also see http://cgit.freedesktop.org/gstreamer/gst-plugins-good/tree/gst/rtp/README
Execution ended after 0:00:00.006279687
Setting pipeline to PAUSED ...
Setting pipeline to READY ...
Setting pipeline to NULL ...
Freeing pipeline ...

从网络更改源视频解决了上限协商问题。最终管道是:

v4l2src ! videoscale ! video/x-raw,width=1600,height=1150 ! x264enc tune=zerolatency ! rtph264pay ! udpsink host=192.168.0.100 port=5000

并且:

udpsrc port=5000 caps = "application/x-rtp, media=video, clock-rate=90000, encoding-name=H264, payload=96" ! rtph264depay ! avdec_h264 ! autovideosink

我想,更大的分辨率会使应用程序崩溃。