gstreamer 记录
参考
https://gstreamer.freedesktop.org/documentation/tools/gst-launch.html?gi-language=c
动态控制文件是否保存 & 分割多个文件保存视频
gst-launch-1.0 videotestsrc do-timestamp="TRUE" ! tee name=t t. ! queue ! videoconvert ! autovideosink async="FALSE" t. ! queue ! identity drop-probability=1 ! videoconvert name=conv2 ! x264enc ! h264parse ! avimux ! multifilesink async="FALSE" post-messages=true next-file=4 max-file-size=2097152 location=/home/xlr/Videos/aaaa%d
https://baijiahao.baidu.com/s?id=1706698344883340147&wfr=spider&for=pc
将生成的 result.avi 拷贝到 windows,使用格式工厂查看,如下所示,已经转化成了 H263 格式
- 摄像头预览时视频编码H264
root@OK8MP:~# gst-launch-1.0 -e v4l2src device=/dev/video0 io-mode=4 ! video/x-raw,
format=YUY2, width=1280,height=960, framerate=30/1 ! tee name=t ! queue ! vpuenc_h264 !
queue ! h264parse ! qtmux ! filesink location=5645_h264.mp4 t. ! queue ! waylandsink
上面这条命令会开启摄像头的预览和录像,录像文件的格式为H264.
播放编码后的H264视频:
root@OK8MP:~# gst-launch-1.0 filesrc location=5645_h264.mp4 ! qtdemux ! queue !
h264parse ! vpudec ! waylandsink
指令1
gst-launch-1.0 -e v4l2src device=/dev/video0 io-mode=4 ! video/x-raw, format=YUY2, width=1280,height=960, framerate=30/1 ! tee name=t ! queue ! vpuenc_h264 ! queue ! h264parse ! filesink location=5645_h264.mp4
可用指令2
gst-launch-1.0 -e v4l2src device=/dev/video0 io-mode=4 ! video/x-raw, format=YUY2, width=1280,height=960, framerate=30/1 ! tee name=t ! queue ! vpuenc_h264 ! queue ! h264parse ! multifilesink async="FALSE" post-messages=true next-file=4 max-file-size=2097152 location=5645_h264_%d.mp4
可用指令3
gst-launch-1.0 -e v4l2src device=/dev/video0 io-mode=4 ! video/x-raw, format=YUY2, width=1280,height=960, framerate=15/1 ! tee name=t ! queue ! vpuenc_h264 ! queue ! h264parse ! filesink location=5645_h264.mp4
可用指令4
gst-launch-1.0 -e v4l2src device=/dev/video0 io-mode=2 ! waylandsink
可用指令5
雪花
gst-launch-1.0 -e videotestsrc pattern=snow ! waylandsink
可用指令6
gst-launch-1.0 -e v4l2src device=/dev/video0 io-mode=4 ! video/x-raw, format=YUY2, width=1280,height=960, framerate=15/1 ! waylandsink
可用指令7
gst-inspect-1.0 videoconvert
可用指令8
gst-launch-1.0 v4l2src ! waylandsink
https://gstreamer.freedesktop.org/documentation/video4linux2/v4l2src.html?gi-language=c
GstV4l2DeviceTypeFlags
Members
capture (0x00000001) – Device supports video capture
output (0x00000002) – Device supports video playback
overlay (0x00000004) – Device supports video overlay
vbi-capture (0x00000010) – Device supports the VBI capture
vbi-output (0x00000020) – Device supports the VBI output
tuner (0x00010000) – Device has a tuner or modulator
audio (0x00020000) – Device has audio inputs or outputs
[video4linux2,v4l2 @ 0xaaaae665b650] Not a video capture device.
/dev/video0: No such device
参考指令1
gst-launch-1.0 v4l2src ! video/x-raw,format=YUY2,width=640,height=480,framerate=15/1 ! queue2 ! videorate ! videoscale ! videoconvert ! xvimagesink
参考指令2
gst-launch-1.0 v4l2src ! video/x-raw,format=YUY2,width=640,height=480,framerate=15/1 ! videorate ! videoscale ! videoconvert ! xvimagesink
将摄像头比例设为16:9
gst-launch-1.0 v4l2src ! video/x-raw,width=640,height=480,framerate=15/1 ! aspectratiocrop aspect-ratio=16/9 ! videoconvert ! xvimagesink
http://www.pcfreetime.com/formatfactory/index.php?language=en
我终于找到了。如果您使用默认参数运行v4l2rtspserver,则动态调整视频大小的gstreamer 1.0管道为:
gst-launch-1.0 -e rtspsrc location="rtsp://127.0.0.1:8554/unicast" ! capsfilter caps="application/x-rtp, media=(string)video, payload=(int)96, encoding-name=(string)H264" ! queue ! rtph264depay ! h264parse ! avdec_h264 ! queue ! videoconvert ! videoscale ! video/x-raw,width=160,height=120 ! avenc_h264_omx ! h264parse ! matroskamux ! filesink location=./video.mkv
https://gstreamer.freedesktop.org/documentation/ximagesink/index.html?gi-language=c
另外,H.265视频编码,更有效的压缩视频,在高分辨率录制下也是一个优点。
gst-launch-1.0 v4l2src ! xvimagesink
根据摄像头 ,有的可能不能显示图像
- gst-launch 构建通道
- v4l2src 采集视频 的插件
- xvimagesink 显示采集图像的sink插件
ximagesink和xvimagesink 两者都是用来x桌面用来显示视频图像的sink插件,但支持的格式不同。
ximagesink支持rgb格式,不支持yuv格式;xvimagesink支持yuv等多种格式
gst-launch-0.10 videotestsrc pattern=ball ! ffmpegcolorspace ! autovideosink
显示测试测试视频 一个滚动的雪球
注意版本
gst-launch v4l2src device=/dev/video0 ! ffmpegcolorspace ! ximagesink
显示video0采集的图像,并显示出来
ffmpegcolorspace 用于颜色转换的插件 转换多种颜色格式的过滤器,摄像头设备视频数据通常使用YUV颜色格式,而显示器通常使用RGB颜色格式
h264parse
avdec_h264
通过控制identity 的属性drop-probability来选择文件是否开始保存。=1,数据丢弃;=0,文件开始保存。
通过指定multifilesink的属性next-file=4 max-file-size=2097152设置每个文件的大小(Bytes),next-file=4表示以max-file-size为文件上限,到达该上限就重新保存文件。location=/home/xlr/Videos/aaaa%d表示存储文件的位置和名称,将会以aaaa0,aaaa1等形式存储,每个文件大小为max-file-size。
2.h264parse
官方解释:Parses H.264 streams
解析h264的流
3.avdec_h264
官方解释:libav h264 decoder
h264解码
方法1,和h264parse配合使用。
以前面文章里提到的例子,PIPE为:
appsrc - h264parse - avdec_h264 - videoconvert - jpegenc - multifilesink
avdec_h264一般连接在h264parse后面,用来解码H264数据。
向appsrc里面填充数据,参考前面的文章,直接把H264文件里读出来的数据不断放进去就可以了。
imxvideoconvert_g2d
注意:在视频颜色空间转换时,imxvideoconvert_g2d 仅支持其他格式的视频转换为RGB格式的视频。
1、视频颜色空间转换
将gstreamer自带的NV12格式的视频源转换为RGB16格式的视频:
root@OK8MP:~# gst-launch-1.0 videotestsrc ! video/x-raw,format=NV12 !
imxvideoconvert_g2d ! video/x-raw,format=RGB16 ! waylandsink
2、将h264视频解码后,再使用imxvideoconvert_g2d转换成RGB16格式的视频:
root@OK8MP:~# gst-launch-1.0 filesrc location=/media/forlinx/video/1080p_60fps_h264.mp4 !
qtdemux ! queue ! h264parse ! vpudec ! imxvideoconvert_g2d ! video/x-raw, format=RGB16,
width=1920, height=1080 ! waylandsink
其它格式视频解码后色彩空间转换的方式一样,不再赘述。
3、视频缩放(调节视频的分辨率)
将 gstreamer 自带的NV12格式1280720的视频源转换为RGB16格式640480的视频:
root@OK8MP:~# gst-launch-1.0 videotestsrc !
video/x-raw,format=NV12,width=1280,height=720 !
imxvideoconvert_g2d ! video/x-raw, format=RGB16, width=640, height=480 ! waylandsink