gstreamer gst-launch 记录 原理

gstreamer 记录 原理

参考

v4l2-ctl -d /dev/video0 --all

GStreamer基础教程12 - 常用命令工具
https://copyfuture.com/blogs-details/20191104144204435k16mgagdirwlob4

https://gstreamer.freedesktop.org/documentation/video4linux2/v4l2src.html?gi-language=c

深入浅出,快速弄明白 gst-launch-1.0 PIPELINE-DESCRIPTION 管道描述语法
https://blog.csdn.net/quicmous/article/details/116916420

linux学习笔记——gst-launch-1.0
https://blog.csdn.net/qq_41561171/article/details/118488296

迅为i.MX8M开发板yocto系统使用Gstarwmr视频转换
https://blog.csdn.net/mucheni/article/details/125479651

NXP i.MX6 ARM-Linux多媒体音视频使用

https://blog.csdn.net/qq_33753562/article/details/120925535

https://community.nxp.com/t5/i-MX-Processors/I-MX8-GST-question/m-p/911786/highlight/true
I want to change the video size before video encode to H264 and after camera output image,how to use the imxvideoconvert command?

Please give some guide.
refer to the example:

Resize
gst-launch-1.0 videotestsrc ! video/x-raw,format=NV12,width=800,height=600 !
imxvideoconvert_{xxx} ! video/x-raw, width=640, height=480 ! ximagesink display=:0

There are three video conversion plugins, imxvideoconvert_ipu, imxvideoconvert_g2d, and imxvideoconvert_pxp. pls choose the correct plugin you need

GStreamer on Gateworks SBCs

http://trac.gateworks.com/wiki/Yocto/gstreamer

gstreamer经常使用命令

由于有好一段时间没做GStreamer相关项目了,早前的一些记录需要做下记录,以待需要的时候查阅。

还是分几个小节来介绍吧,这样思路清晰一点。(格式有点乱,没时间整理,读者自行脑补)

  1. 播放视频、音频

音频:gst-launch-1.0 filesrc loaction=123.mp3 ! mad ! autoaudiosink

//补充说明:autoaudiosink可换成pulsesink或alsasink,需要使用gst-inspect查询是否存在这些sink插件,其实autoaudiosink是个壳,最终还是选择使用后两者之一。

视频:gst-launch-1.0 filesrc location=320_240.mp4 ! qtdemux ! sprdavcdec ! autovideosink
其他:gst-launch-1.0 filesrc location=abc.mp4 ! qtdemux name=demux demux.video_0 ! queue ! decodebin ! videoconvert ! videoscale ! autovideosink //只分离视频并播放

gst-launch-1.0 filesrc location=3.mp4 ! decodebin ! autovideoconvert ! autovideosink //只解码和显示视频部分,音频过滤掉,decodebin使用着最简单方便
  //补充:gstreamer好像不能分离出可播的264裸码流,但是可以用ffmpeg转:ffmpeg.exe -i 320_240.mp4 -vcodec copy -an 320_240.h264

  1. 视频、音频编码

视频:gst-launch-1.0 v4l2src device=“/dev/video0” ! “video/x-raw, width=1920, height=1080” ! omxh264enc ! “video/x-h264, stream-format=byte-stream” ! h264parse ! qtmux ! filesink location=test.mp4

音频:gst-launch-1.0 audiotestsrc ! audioconvert ! “audio/x-raw,format=S16LE,channels=2,rate=8000” ! lamemp3enc ! filesink location=audio_conv.mp3

gst-launch-1.0 xxx.mp3 ! mad ! audioconvert ! lamemp3enc ! filesink location=xxx_mad_lame.mp3 //mad只解码出S32LE的格式,lame只支持S16LE的格式,因此必须通过audioconvert来转换

  1. 摄像头预览

gst-launch v4l2src ! video/x-raw-yuv,width=320,height=240,framerate=20/1 ! autovideosink

说明:v4l2src即图形源,如果不带此插件,可以用videotestsrc替代

  1. 转码(avc->yuv, mp3/aac->pcm)

avc->yuv:gst-launch-1.0 filesrc location=attachment.mkv ! matroskademux ! avdec_h264 ! filesink location=tmp.yuv //注意,生成的yuv的size会非常大,mkv中的视频为h264格式

avc->yuv->sink:gst-launch-1.0 filesrc location=dgld.mp4 ! qtdemux ! avdec_h264 ! videoconvert ! video/x-raw,format=I420 ! autovideosink
mp3->wav:gst-launch-1.0 filesrc location=1.mp3 ! mad ! wavenc ! filesink location=1.wav //mad解码出来是32bit的pcm数据,不是S16LE格式的,wavenc其实是对pcm数据编码+封装的过程,因为要有32->S16LE和加wave_header的过程

aac->wav->sink:gst-launch-1.0 filesrc location=out.aac ! aacparse ! avdec_aac ! audioconvert ! alsasink //aac文件到解码之间必须要有一个aacparse,而MP3没有,是因为AAC的ADTS、ADIF容器格式文件导致的吧

  1. 常用的一些插件介绍

h265解码,社区提供了两个插件:avdec_h265,de265,前者为ffmpeg项目提供的,后者为德国一家公司提供的插件+解码库

avdec_xxx为ffmpeg项目组提供的解码插件方案,例如avdec_h264、avdec_aac

xxmux为文件封装插件,如qtmux(不要理解为做UI库的QT公司,而是mp4封装,即苹果公司推出的QuickTime符合mp4规范的)

xxdemux为解封装插件

  1. filter相关

crop处理:gst-launch-1.0 -v videotestsrc ! videocrop top=42 left=1 right=4 bottom=0 ! ximagesink //videocrop——裁边,可以处理解码器将width/height强制32或64对齐而引入的右侧/底部的灰边,其值表示裁掉多少像素。

  1. 网络推流/拉流(两个终端下执行)

gst-launch-1.0 tcpserversrc host=“127.0.0.1” port=3000 ! decodebin ! autoaudiosink
  gst-launch-1.0 filesrc location=./1.mp3 ! tcpclientsink host=“127.0.0.1” port=3000

  1. jpeg相关

mjpeg文件解码+显示:gst-launch-1.0 filesrc location=test_mjpeg.mp4 ! qtdemux ! jpegdec ! videoconvert ! autovideosink
  mjpeg文件解码+多文件保存:gst-launch-1.0 filesrc location=test_mjpeg.mp4 ! qtdemux ! jpegdec ! multifilesink location=%02d.yuv

jpeg解码+显示:gst-launch-1.0 filesrc location=test.jpg ! jpegdec ! videoconvert ! imagefreeze ! ximagesink //解码后显示,必须用imagefreeze和videoconvert插件,在PC上验证结果。imagefreeze——将图像冻结,否则很快消失。

//yuv的显示
  //以下不知道为什么显示全黑色的图像——log中出现了error信息!
  //把pixel-aspect-ratio和interlace-mod这两个属性去掉,因为videoconvert的SinkPad不带这些属性
  gst-launch-1.0 filesrc location=xxx.yuv ! “video/x-raw,format=I420,width=1280,height=720,pixel-aspect-ratio=1/1,framerate=0/1,interlace-mod=progressive” ! videoconvert ! imagefreeze ! ximagesink //yuv图片的显示
  //最终答案是,filesrc 添加文件大小的属性:blocksize=xxx,表示数据源多大,来确定读多少数据来作为一帧。
  //videoconvert的sink_pad,有的gst版本要求带framerate的属性,否则报错
  gst-launch-1.0 filesrc blocksize=xxx location=xxx.yuv ! “video/x-raw,format=I420,width=1280,height=720” ! videoconvert ! imagefreeze ! ximagesink

//yuv的jpeg编码,前半部分一样,后半部分进行编码+写文件
  gst-launch-1.0 filesrc blocksize=xxx location=xxx.yuv ! “video/x-raw,format=I420,width=1280,height=720” ! videoconvert ! jpegenc ! filesink location=yyy.jpg

gst-launch-1.0 filesrc location=test.jpg ! jpegdec ! imagefreeze ! glimagesink //解码+显示
  gst-launch-1.0 filesrc location=test.jpg ! jpegdec ! filesink location=test.yuv //解码+存本地文件
  gst-launch-1.0 filesrc blocksize=1081600 location=test.yuv ! video/x-raw,width=900,height=800,format=I420,framerate=0/1 ! videoconvert ! imagefreeze ! glimagesink //yuv显示
  gst-launch-1.0 filesrc blocksize=1081600 location=test.yuv ! video/x-raw,width=900,height=800,format=I420,framerate=0/1 ! videoconvert ! jpegenc ! filesink location=test_enc.jpg //利用yuv文件编码

//解码+显示
  gst-launch-1.0 filesrc location=test.jpg ! jpegdec ! imagefreeze ! glimagesink //可以指定文件大小,使用blocksize=xxx

//解码+存本地文件
  gst-launch-1.0 filesrc location=test.jpg ! jpegdec ! filesink location=test.yuv

//yuv文件显示
  gst-launch-1.0 filesrc blocksize=1081600 location=test.yuv ! video/x-raw,width=900,height=800,format=I420,framerate=0/1 ! videoconvert ! imagefreeze ! glimagesink
  说明:blocksize指定test.yuv文件的大小,width=900,height=800指定yuv文件的实际宽高,必须填对!

//利用yuv文件jpeg编码
  gst-launch-1.0 filesrc blocksize=1081600 location=test.yuv ! video/x-raw,width=900,height=800,format=I420,framerate=0/1 ! videoconvert ! jpegenc ! filesink location=test_enc.jpg
  说明:blocksize指定test.yuv文件的大小

  1. 其他未归类命令

gst-launch-1.0 filesrc location=Capture001.png ! pngdec ! imagefreeze ! autovideosink
  gst-launch-1.0 filesrc location=Capture001.png ! pngdec ! filesink location=png.yuv

gst-launch-1.0 filesrc location=320_240_hevc.mp4 ! qtdemux ! filesink location=320_240_gst_naked.hevc //跟ffmpeg分流后得到的不太一样,start_code中包含size信息

gst-launch-1.0 filesrc location=320_240_hevc.mp4 ! qtdemux ! sprdhevcdec ! filesink location=320_240_hevc.yuv
  gst-launch-1.0 filesrc location=320_240_hevc.mp4 ! qtdemux ! sprdhevcdec ! fakevideosink
  gst-launch-1.0 filesrc location=bigbuckbunny_1080p_4mbps.mp4 ! qtdemux ! sprdhevcdec ! fakevideosink
  gst-launch-1.0 filesrc location=Movie_h265_NA.mp4 ! qtdemux ! sprdhevcdec ! fakevideosink
  gst-launch-1.0 filesrc location=02_Naturally_720p_x265.mp4 ! qtdemux ! sprdhevcdec ! fakevideosink
  gst-launch-1.0 filesrc location=bigbuckbunny_1080p_4mbps_ffmpeg.mp4 ! qtdemux ! sprdhevcdec ! fakevideosink

  1. 其他未归类命令

用gstreamer的管道命令,太麻烦了,真不如ffmpeg用着方便啊!

当然,其存在必然有其合理性,这是linux平台下通用的多媒体中间件系统,多种播放器都是使用它来做的,它的一个很大特点是软件分层、解耦、抽象做的非常好。

如果要做一些插件,需要有一些基础知识,例如gobjec,glib库。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值