toradex的个人空间 https://blog.eetop.cn/1539194 [收藏] [复制] [分享] [RSS]

空间首页 动态 记录 日志 相册 主题 分享 留言板 个人资料

日志

ARM平台基于嵌入式Linux Gstreamer 使用

已有 4947 次阅读| 2016-5-5 16:50

By Toradex 秦海

1). 简介

随着ARM平台性能的日益强大和嵌入式设备的发展,对于多媒体处理如音视频播放,摄像头,流媒体处理等需求也日益增多,本文就通过几个基于嵌入式Linux下多媒体应用的示例来简单展示下使用Gstreamer框架进行多媒体处理的方法.

Gstreamer是一个基于Pipeline的多媒体框架,基于GObject,以C语言写成,目前是嵌入式Linux最为常用的处理多媒体应用框架. Element是Gstreamer最重要和基本的对象类,通过Plugin的形式提供,多个Elements可以组合为bin,并进一步聚合形成一个Pipeline完成一个多媒体应用处理.

2). 硬件准备

./ 本文测试所使用平台为Toradex Colibri i.MX6 ARM计算机核心板模块, 基于NXP i.MX6 SoC, 配合Colibri开发板.

./ 摄像头作为多媒体输入源使用Logitech 720P USB摄像头

3). 软件准备

./ OS为Toradex官方Ycoto project兼容嵌入式Linux发布 V2.5 beta3.

./ Gstreamer-0.10, 系统自带

./ 安装gstreamer相关插件包

----------------

root@colibri-imx6:~# opkg update

root@colibri-imx6:~# opkg install gst-plugins-base-meta. gst-plugins-good-meta


root@colibri-imx6:~# wget http://feeds.angstrom-distribution.org/feeds/v2015.06/ipk/glibc/armv7ahf-vfp-neon/base/libavcodec54_9.16-r0.9_armv7ahf-vfp-neon.ipk

root@colibri-imx6:~# wget http://feeds.angstrom-distribution.org/feeds/v2015.06/ipk/glibc/armv7ahf-vfp-neon/base/libswscale2_9.16-r0.9_armv7ahf-vfp-neon.ipk

root@colibri-imx6:~# wget http://feeds.angstrom-distribution.org/feeds/v2015.06/ipk/glibc/armv7ahf-vfp-neon/base/libavutil52_9.16-r0.9_armv7ahf-vfp-neon.ipk

root@colibri-imx6:~# wget http://feeds.angstrom-distribution.org/feeds/v2015.06/ipk/glibc/armv7ahf-vfp-neon/base/libavformat54_9.16-r0.9_armv7ahf-vfp-neon.ipk


root@colibri-imx6:~# opkg install libavutil52_9.16-r0.9_armv7ahf-vfp-neon.ipk

root@colibri-imx6:~# opkg install libavcodec54_9.16-r0.9_armv7ahf-vfp-neon.ipk

root@colibri-imx6:~# opkg install libswscale2_9.16-r0.9_armv7ahf-vfp-neon.ipk

root@colibri-imx6:~# opkg install libavformat54_9.16-r0.9_armv7ahf-vfp-neon.ipk


root@colibri-imx6:~# opkg install gst-ffmpeg

----------------

4). 测试gstreamer

Gstreamer提供了两个非常方便的工具gst-launch和gst-inspect,在真正将Gstreamer pipeline集成到你的程序里面前,可以使用这两个工具在命令行下面进行pipeline的准备和测试,本文也主要基于这种模式进行演示,而详细的关于Gstreamer在程序中使用方法请参考这里.

gst-inspect可以用来查看当前系统已经安装的plugin或者具体查看某个element的属性来判定pipeline中elements互联兼容性,详细说明请见这里.

gst-launch 用于编译和运行一个pipeline,可以方便的对pipeline进行不同组合尝试并测试,如下面用来显示一个视频测试图案.

----------------

root@colibri-imx6:~# gst-launch videotestsrc ! 'video/x-raw-rgb, width=(int)640,height=(int)480' ! ximagesink

----------------


 

5). 应用示例

a). 播放摄像头


使用v4l2src元件采集摄像头视频,视频格式为YUY2/帧率30/分辨率640x480; 使用imxv4l2sink元件利用GPU加速播放采集的视频; 如果使用ximagesink元件来播放则没有硬件加速.

----------------

root@colibri-imx6:~# gst-launch v4l2src device=/dev/video0 ! 'video/x-raw-yuv, framerate=30/1, width=(int)640, height=(int)480, format=(fourcc)YUY2' ! imxv4l2sink disp-width=640 disp-height=480

----------------

目标板CPU占用率: 37.5%


b). 采集摄像头保存为文件

同样使用v4l2src元件采集摄像头视频; ffmpegcolorspace元件转换颜色格式为I420; vpuenc元件调用硬件VPU进行H.264编码; matroskamux元件进行mkv mux;  filesink元件输出到文件

----------------

root@colibri-imx6:~# gst-launch -v v4l2src device=/dev/video0 ! ffmpegcolorspace ! 'video/x-raw-yuv, framerate=30/1, width=(int)640, height=(int)480, format=(fourcc)I420' ! queue max-size-buffers=2 ! vpuenc codec=6 ! matroskamux ! filesink location=output.mkv

----------------

目标板CPU占用率: 40%


c). 回放视频文件

使用filesrc元件读取视频文件; aiurdemux元件进行demux; vpudec元件通过硬件VPU进行H.264解码; imxv4l2sink元件播放.

----------------

root@colibri-imx6:~# gst-launch filesrc location=/home/root/output.mkv typefind=true ! aiurdemux ! queue ! vpudec ! imxv4l2sink disp-width=640 disp-height=480

----------------

目标板CPU占用率: 3.5%


d). RTP摄像头流媒体到远程主机

使用v4l2src元件采集摄像头; ffmpegcolorspace转换颜色格式; vpuenc元件调用硬件VPU进行H.264编码;rtph264pay元件进行h264流rtp封装; udpsink元件进行udp传输.

----------------

//Ubuntu主机IP: 10.20.1.116

//Colibri i.MX6目标板IP: 10.20.1.122


// Colibri i.MX6 //

gst-launch -v v4l2src device=/dev/video0 ! ffmpegcolorspace! 'video/x-raw-yuv, framerate=30/1, width=(int)640, height=(int)480, format=(fourcc)I420' ! vpuenc codec=6 ! rtph264pay ! udpsink host=10.20.1.116 port=5000


// Ubuntu 主机 //

//Ubuntu 14.04, 安装gstreamer-ffmpeg

wget http://ppa.launchpad.net/mc3man/gstffmpeg-keep/ubuntu/pool/main/g/gstreamer0.10-ffmpeg/gstreamer0.10-ffmpeg_0.10.13-5ubuntu1~trusty2.1_amd64.deb && sudo dpkg -i gstreamer0.10-ffmpeg_0.10.13-5ubuntu1~trusty2.1_amd64.deb

//播放流媒体, caps设置从目标板获得

gst-launch-0.10 udpsrc port=5000 caps="application/x-rtp, media=(string)video, clock-rate=(int)90000, encoding-name=(string)H264, sprop-parameter-sets=(string)\"Z0JAHqaAoD2QAA\\=\\=\\,aM44gAA\\=\", payload=(int)96, ssrc=(uint)1172839120, clock-base=(uint)784846202, seqnum-base=(uint)58343" ! rtph264depay ! ffdec_h264 ! ximagesink

----------------

目标板CPU占用率: 35%


6). Gstreamer1.0应用示例

Colibri i.MX6 最新Linux发布版本V2.6beta1已经支持gstreamer1.0,升级方法请见这里

./ 软件准备

安装相关插件包

----------------

opkg update

opkg install gstreamer1.0-plugins-base-meta

opkg install gstreamer1.0-plugins-good-meta

opkg remove --force-depends libgstimxcompositor0 //目前版本中需要移除否则无法使用gstreamer

----------------

./ 应用示例

a). 播放摄像头

----------------

root@colibri-imx6:~# gst-launch-1.0 imxv4l2src device=/dev/video0 ! 'video/x-raw, framerate=30/1, width=(int)640, height=(int)480, format=(string)YUY2' ! imxv4l2sink overlay-width=640 overlay-height=480

----------------

目标板CPU占用率: 30%


b).  采集摄像头保存为文件

----------------

root@colibri-imx6:~# gst-launch-1.0 imxv4l2src device=/dev/video0 ! videoconvert ! 'video/x-raw, framerate=30/1, width=(int)640, height=(int)480, format=(string)I420' ! queue max-size-buffers=2 ! vpuenc_h264 ! matroskamux ! filesink location=output.mkv

----------------

目标板CPU占用率: 16%


c). 回放视频文件

----------------

root@colibri-imx6:~# gst-launch-1.0 filesrc location=/home/root/output.mkv typefind=true ! matroskademux ! queue ! vpudec ! imxv4l2sink overlay-width=640 overlay-height=480

----------------

目标板CPU占用率: 4%


d). RTP摄像头流媒体到远程主机

----------------

//Ubuntu主机IP: 10.20.1.116

//Colibri i.MX6目标板IP: 10.20.1.122


// Colibri i.MX6 //

gst-launch-1.0 imxv4l2src device=/dev/video0 ! videoconvert ! 'video/x-raw, framerate=30/1, width=(int)640, height=(int)480, format=(string)I420' ! queue max-size-buffers=2 ! vpuenc_h264 ! rtph264pay ! udpsink host=10.20.1.116 port=5000

// Ubuntu 主机 //

//Ubuntu 14.04, 安装libav (同0.10 ffmpeg)

sudo apt-get install gstreamer1.0-libav


//播放流媒体

gst-launch-1.0 udpsrc port=5000 caps="application/x-rtp, media=(string)video, clock-rate=(int)90000,encoding-name=(string)H264, payload=(int)96" ! rtph264depay ! avdec_h264 ! videoconvert ! ximagesink

----------------

目标板CPU占用率: 13%


e). 摄像头连接到远程主机tcp视频流到目标版再rtp回远程主机播放

----------------

//Ubuntu主机IP: 10.20.1.116

//Colibri i.MX6目标板IP: 10.20.1.122


// Ubuntu 主机 //

//采集摄像头并建立tcp server

gst-launch-1.0 v4l2src device=/dev/video0 ! videoconvert ! 'video/x-raw, framerate=30/1, width=(int)640, height=(int)480, format=(string)I420' ! jpegenc ! tcpserversink host=10.20.1.116 port=5000


// Colibri i.MX6 //

//从tcp server获取摄像头视频流,并进行H.264压缩后rtp回远程主机

gst-launch-1.0 tcpclientsrc host=10.20.1.116 port=5000 ! jpegdec ! queue max-size-buffers=2 ! vpuenc_h264 ! rtph264pay ! udpsink host=10.20.1.116 port=5001


// Ubuntu 主机 //

//播放rtp视频流

gst-launch-1.0 udpsrc port=5001 caps="application/x-rtp, media=(string)video, clock-rate=(int)90000,encoding-name=(string)H264, payload=(int)96" ! rtph264depay ! avdec_h264 ! videoconvert ! ximagesink

----------------

目标板CPU占用率: 31%


7). 总结

由上面示例可见Gstreamer是一个非常强大且配置灵活的多媒体处理框架,并且配合相应的plugin,也可以充分调用硬件GPU/VPU加速,使其能够在嵌入式设备上面利用有限的资源高效的实现广泛的多媒体应用.


点赞

评论 (0 个评论)

facelist

您需要登录后才可以评论 登录 | 注册

  • 关注TA
  • 加好友
  • 联系TA
  • 0

    周排名
  • 0

    月排名
  • 0

    总排名
  • 0

    关注
  • 3

    粉丝
  • 0

    好友
  • 1

    获赞
  • 2

    评论
  • 13923

    访问数
关闭

站长推荐 上一条 /1 下一条

小黑屋| 关于我们| 联系我们| 在线咨询| 隐私声明| EETOP 创芯网
( 京ICP备:10050787号 京公网安备:11010502037710 )

GMT+8, 2024-4-25 20:30 , Processed in 0.018073 second(s), 6 queries , Gzip On, Redis On.

eetop公众号 创芯大讲堂 创芯人才网
返回顶部