GSteamer

  • mpph264enc 为硬件解码,不支持需更换对应解码

测试

参数

  • xxxsrc 输入
  • xxxsink 输出
gst-launch-1.0 videotestsrc name=a videotestsink name=b a.src ! b.sink

摄像头录视频

参数

  • video/x-raw ,image/jpeg 调用格式 (YUYV , MJPG)
  • format 色彩格式 (仅YUYV)
  • framerate 帧率
  • mpph264enc 硬件解码

YUYV

gst-launch-1.0 v4l2src device=/dev/video0 ! videoconvert ! video/x-raw,format=NV12,width=1920,height=1080,framerate=30/1 ! queue ! mpph264enc ! queue ! h264parse ! mpegtsmux ! filesink location=/path/out.mp4

MJPG

gst-launch-1.0 v4l2src device=/dev/video0 ! image/jpeg,width=1920,height=1080,framerate=30/1 ! jpegdec ! videoconvert ! queue ! mpph264enc ! queue ! h264parse ! mpegtsmux ! filesink location=/path/out.mp4

解决 MJPG 颜色异常

gst-launch-1.0 v4l2src device=/dev/video0 ! image/jpeg,width=1920,height=1080,framerate=30/1 ! jpegdec ! videoconvert ! video/x-raw,format=NV12 ! queue ! mpph264enc ! queue ! h264parse ! mpegtsmux ! filesink location=/path/out.mp4

推流

gst-launch-1.0 v4l2src device=/dev/video0 ! image/jpeg,width=1920,height=1080,framerate=25/1 ! jpegdec ! videoconvert ! queue ! mpph264enc ! queue ! h264parse ! flvmux ! rtmpsink location='rtmp://127.0.0.1:5002/live'

水印

静态水印

gst-launch-1.0 v4l2src device=/dev/video0 ! image/jpeg,width=1920,height=1080,framerate=25/1 ! jpegdec ! textoverlay text="静态水印" ! videoconvert ! queue ! mpph264enc ! queue ! h264parse ! flvmux ! rtmpsink location='rtmp://127.0.0.1:5002/live'
================
gst-launch-1.0 v4l2src device=/dev/video0 ! image/jpeg,width=1920,height=1080,framerate=25/1 ! jpegdec ! textoverlay text="<span foreground=\"blue\" background=\"green\" size=\"x-large\"> TEST </span> is <i>cool</i>"  ! videoconvert ! queue ! mpph264enc ! queue ! h264parse ! flvmux ! rtmpsink location='rtmp://127.0.0.1:5002/live'

动态时间水印

  • font-desc 字体大小
  • shaded-background 背景
    font-descshaded-background会占用cpu,低性能设备上会影响帧率
  • valignment 位置(上下)
  • halignment 位置(左右)
gst-launch-1.0 v4l2src device=/dev/video0 ! image/jpeg,width=1920,height=1080,framerate=30/1 ! jpegdec ! clockoverlay halignment=right valignment=top shaded-background=false font-desc='8' time-format="%Y-%m-%d %H:%M:%S" ! videoconvert ! video/x-raw,format=NV12,width=1920,height=1080,framerate=30/1 ! queue ! mpph264enc ! queue ! h264parse ! flvmux ! rtmpsink location='rtmp://127.0.0.1:5002/live'

多通道

gst-launch-1.0 -e v4l2src device=/dev/video0 ! image/jpeg,width=1280,height=960,framerate=30/1 ! jpegdec ! videoconvert ! video/x-raw,format=NV12,width=1280,height=960,framerate=30/1 ! queue ! mpph264enc ! queue ! h264parse ! tee name=t t. ! queue ! flvmux ! rtmpsink location='rtmp://127.0.0.1:5002/live' t. ! queue ! splitmuxsink location=/path/out.mp4

按时长录制视频 (动态命名)

gst-launch-1.0 -e v4l2src device=/dev/video0 ! image/jpeg,width=1280,height=960,framerate=30/1 ! jpegdec ! videoconvert ! video/x-raw,format=NV12,width=1280,height=960,framerate=30/1 ! queue ! mpph264enc ! queue ! h264parse ! queue ! splitmuxsink location=/psth/out_%d.mp4 max-size-time=11000000000 async-finalize=TRUE
================
out_0.mp4
out_1.mp4
out_2.mp4

参数

  • max-size-time 秒数*1000000000

爱称拍-推流并按时长录制

gst-launch-1.0 -e v4l2src device=/dev/video0 ! image/jpeg,width=1920,height=1080,framerate=25/1 ! jpegdec ! clockoverlay halignment=right shaded-background=false font-desc='8' time-format="%Y-%m-%d %H:%M:%S" ! videoconvert ! video/x-raw,format=NV12 ! queue ! mpph264enc ! h264parse ! tee name=t t. ! queue ! splitmuxsink location=/media/ztl/56BF-01281/Videos/out1_%d.mp4 max-size-time=11000000000 async-finalize=TRUE t. ! queue ! flvmux ! rtmpsink location='rtmp://127.0.0.1:5002/live'
# 每秒一个文件写入内存用于抓拍
gst-launch-1.0 -e v4l2src device=/dev/video0 ! image/jpeg,width=1920,height=1080t},framerate=25/1 ! jpegdec ! clockoverlay halignment=right shaded-background=false font-desc="12" time-format="%Y-%m-%d %H:%M:%S" ! videoconvert ! video/x-raw,format=NV12 ! queue ! mpph264enc ! queue ! h264parse ! tee name=t t. ! queue ! splitmuxsink location=/media/ztl/56BF-01281/Videos/out1_%d.mp4 max-size-time=60000000000 async-finalize=TRUE t. ! queue ! flvmux ! rtmpsink location='rtmp://127.0.0.1:5002/live' t. ! queue ! splitmuxsink location=/dev/shm/temp_video/out1_%d.mp4 max-size-time=1000000000 async-finalize=TRUE

拉取RTSP并保存为mp4

gst-launch-1.0 -e rtspsrc location=rtsp://admin:nova123456@192.168.2.99:554/h264/ch1/main/av_stream ! rtph264depay ! h264parse ! queue ! splitmuxsink location=/media/ztl/98EB-4938/video/out1_%d.mp4 max-size-time=10000000000 async-finalize=TRUE
最后修改:2023 年 02 月 08 日
如果想要赞赏,我绝不阻拦