gstearmer学习

极限性能

echo performance | tee $(find /sys |grep governor$) # 打开性能模式
export KMSSINK_DISABLE_VSYNC=1 #关闭vsync
echo 400000000 > sys/kernel/debug/clk/aclk_rkvdec/clk_rate # 提高解码频率
echo 0x100 > /sys/module/rk_vcodec/parameters/mpp_dev_debug # 打开mpp解码时间

sink方式

可以通过
gst-inspect-1.0 kmssink
查询sink方式 支持的命令

xvimagesink

xvimagesink 需要有硬件加速
实现多屏:

kmssink

使用AFBC格式播放:
export GST_MPP_VIDEODEC_DEFAULT_ARM_AFBC=1
GST_DEBUG=fpsdisplaysink:5 gst-play-1.0 GUGUDAN-Wonderland.2160p.UHDTV.H265.ts --flags=3 --use-playbin3 --videosink="fpsdisplaysink text-overlay=false video-sink=\"kmssink plane-id=71\" sync=false fps-update-interval=10000 "
注:plane-id使用对应的cluster层
fpsdisplaysink 打开帧率打印
text-overlay=false 关闭字幕

普通播放:
gst-play-1.0 1.mp4 --flags=3 --use-playbin3 --videosink=kmssink plane-id=65

gst-play-1.0 oem/SampleVideo_1280x720_5mb.mp4 --flags=3 --videosink="kmssink connector-id=154"
指定connector-id

GST_DEBUG=kmssink:5 gst-launch-1.0 v4l2src device=/dev/video20 ! queue ! kmssink

实现多屏:

waylandsink

防止丢帧:
配置文件增加 WAYLANDSINK_SYNC_FRAME
export GST_DEBUG=*wayland*:10
gst-play-1.0 /test.mp4 --videosink="waylandsink sync=false" --a udiosink=fakesink 2>&1|grep drop -i 0:00:00.724004250 1064 0x7f8c003060 LOG waylandsink gstwaylandsink.c:918:gst_wayland_sink_show_frame:<waylandsink0> buffer 0x7fa01b9890 dropped (redraw pending)
检查:源文件:buildroot/output/rockchip_px30_64/build/gst1-plugins-bad-1.14.4/ext/wayland# grep WAYLANDSINK_SYNC_FRAME * gstwaylandsink.c: if (g_getenv ("WAYLANDSINK_SYNC_FRAME")) { 库:[root@rk3399:/]# grep WAYLANDSINK_SYNC_FRAME /usr/lib/gstreamer-1.0/libgstwaylandsink.so WAYLANDSINK_SYNC_FRAME
实现多屏:

v4l2src

gst-launch-1.0 -v v4l2src ! 'video/x-raw,format=NV12' ! mpph264enc ! filesink location="bla.h264"

gst-launch-1.0 v4l2src ! video/x-raw,format=NV12,width=1920,height=1080 ! rkximagesink
gst-launch-1.0 v4l2src ! video/x-raw,format=RGB3,width=3840,height=2160 ! rkximagesink

gst-launch-1.0 v4l2src device=/dev/video17 ! video/x-raw,format=RGB3,width=1920, height=1080 ! rkximagesink

gst-launch-1.0 v4l2src device=/dev/video20 ! queue ! kmssink

零零碎碎

videoscale是硬件加速,videocrop是软件。较新的gstreamer-rockchip的解码插件支持硬件crop和缩放,比如:
gst-launch-1.0 videotestsrc ! mpph264enc ! h264parse ! mppvideodec crop-rectangle='<100,100,100,100>' width=400 height=400 ! waylandsink处理顺序是先缩放再裁减

gstreamer里面的crop是可以通过crop meta进行in place处理,即直接传递裁减区域信息给最终sink端,由sink端处理裁减(kmssink的话是设置drm的src显示区域)。但是in place处理也需求videocrop直连sink。此外kmssink也支持直接配置目标显示区域render-rectangle进行硬件缩放,但是会受到高宽比限制。所以也可以:
buildroot更新到:https://github.com/JeffyCN/rockchip_mirrors/commit/e7c6827a78434aac1aadf95d763bfc318c3b8e5c
gst-launch-1.0 filesrc location=/FPS_test_1080p60_L4.2.mkv ! matroskademux ! decodebin ! videocrop top=0 bottom=0 left=0 right=960 ! kmssink render-rectangle='<0,0,1920,1080>' force-aspect-ratio=false

jerkiness一般是指播放抖动(偶尔丢帧),卡顿是laggy,闪烁是blink和flick。

硬件加速也是存在耗时的,如其他issue回复,产生耗时的plugin前后最好是加上缓冲队列queue进行异步

确认硬件加速可以通过log开关:
export GST_DEBUG=videoflip:5,video-converter:5
gst-launch-1.0 ... ! videoscale ! video/x-raw, width=500, height=500 ! ...0:00:02.974151424 13319 0x3f640300 DEBUG video-converter video-converter.c:2862:video_converter_try_rga: converted with RGA

[root@RK356X:/]# GST_DEBUG=mppdec:5 gst-launch-1.0 filesrc location=/test.mp4 ! qtdemux ! h264parse ! mppvideodec crop-rectangle='<0,0,960,1080>' width=3840 height=1080 ! queue ! kmssink 2>&1|grep crop
0:00:01.271583086   778     0x3e9ebde0 DEBUG                 mppdec gstmppdec.c:688:gst_mpp_dec_get_gst_buffer:<mppvideodec0> cropping <0,0,960,1080> within <0,0,3840,1080>

[root@RK356X:/]# tail -10 /sys/kernel/debug/dri/0/summary
        win_id: 3
        format: NV12 little-endian (0x3231564e) SDR[0] color_space[0] glb_alpha[0xff
]
        rotate: xmirror: 0 ymirror: 0 rotate_90: 0 rotate_270: 0
        csc: y2r[1] r2y[0] csc mode[1]
        zpos: 3
        src: pos[0, 0] rect[960 x 1080] 《--- crop到960
        dst: pos[480, 0] rect[960 x 1080]
        buf[0]: addr: 0x00000000040b1000 pitch: 3840 offset: 0 《--- 3840
        buf[1]: addr: 0x00000000040b1000 pitch: 3840 offset: 4147200
Video Port1: DISABLED

[root@rk3399:/]# GST_DEBUG=mppdec:5 gst-launch-1.0 filesrc location=/test.mp4 !qtdemux ! h264parse ! mppvideodec crop-rectangle='<0,0,960,1080>' width=3840 height=1080 ! queue ! kmssink 2>&1|grep crop
0:00:01.085029657  1428      0x2fd6a40 DEBUG                 mppdec gstmppdec.c:678:gst_mpp_dec_get_gst_buffer:<mppvideodec0> cropping <0,0,960,1080> within <0,0,3840,1080>
[root@rk3399:/]# cat /sys/kernel/debug/dri/0/summary
VOP [ff900000.vop]: ACTIVE
    Connector: HDMI-A
        overlay_mode[0] bus_format[100a] output_mode[f] color_space[0]
    Display mode: 1920x1080p60
        clk[148500] real_clk[148500] type[48] flag[5]
        H: 1920 2008 2052 2200
        V: 1080 1084 1089 1125
    win0-0: ACTIVE
        format: XR24 little-endian (0x34325258) SDR[0] color_space[0] 《----- 主图层
        csc: y2r[0] r2r[0] r2y[0] csc mode[0]
        zpos: 0
        src: pos[0x0] rect[1920x1080]
        dst: pos[0x0] rect[1920x1080]
        buf[0]: addr: 0x0000000008c2f000 pitch: 7680 offset: 0
    win1-0: ACTIVE
        format: NV12 little-endian (0x3231564e) SDR[0] color_space[0] 《----- 视频图层
        csc: y2r[1] r2r[0] r2y[0] csc mode[1]
        zpos: 1
        src: pos[0x0] rect[960x1080]              《---裁减到960x1080
        dst: pos[480x0] rect[960x1080]           《-----显示到480,0
        buf[0]: addr: 0x000000007e774000 pitch: 3840 offset: 0 《---- 原图是缩放到3840宽
        buf[1]: addr: 0x000000007e774000 pitch: 3840 offset: 4147200

参考文档

参考文档:
博主文章 http://blog.iotwrt.com/media/2017/11/17/gstreamer-study/
官网 https://gstreamer.freedesktop.org/documentation/opengl/?gi-language=c
gstreamer官网教程学习 https://blog.csdn.net/u010168781/article/details/105750991
下载地址 git clone https://gitlab.freedesktop.org/gstreamer/gstreamer.git

posted @ 2023-05-13 17:10  随机漫步者  阅读(2290)  评论(0)    收藏  举报