sh Gstreamer示例预览,保存和流式传输视频

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了sh Gstreamer示例预览,保存和流式传输视频相关的知识,希望对你有一定的参考价值。

#!/bin/sh
# NVIDIA Jetson TK1
# Use Gstreamer to grab H.264 video and audio stream from Logitech c920 webcam
# Preview video on screen
# Save Video and Audio to a file
# Send video as RTSP stream over TCP
# IP Address of the this machine hosting the TCP stream
IP_ADDRESS=<ENTER IP ADDRESS HERE e.g 10.10.10.10>
# You can list devices:
# $ v4l2-ctl --list-devices
VELEM="v4l2src device=/dev/video0" #video0 is a Logitech c920 webcam with built-in H.264 compression
# Video capability from the camera - Choose One, this size will be sent out over the network
# VCAPS="video/x-h264, width=800, height=448, framerate=30/1"
# VCAPS="video/x-h264, width=1280, height=720, framerate=30/1"
VCAPS="video/x-h264, width=1920, height=1080, framerate=30/1"
# Video Source
VSOURCE="$VELEM ! $VCAPS"
# Decode the video - parse the h264 from the camera and then decode it
# Hardware accelerated by using omxh264dec
VIDEO_DEC="h264parse ! omxh264dec"
# SIZE OF THE PREVIEW WINDOW (Optional - you can remove this by modifying VIDEO_SINK)
# Here for demo purposes
PREVIEW_SCALE="video/x-raw, width=1280, height=720" 
# VIDEO_SINK is the preview window
VIDEO_SINK="videoconvert ! videoscale ! $PREVIEW_SCALE ! xvimagesink sync=false"

#AUDIO
AELEM="pulsesrc device=alsa_input.usb-046d_HD_Pro_Webcam_C920_A116B66F-02-C920.analog-stereo do-timestamp=true"
AUDIO_CAPS="audio/x-raw"
AUDIO_ENC="audioconvert ! voaacenc"
ASOURCE="$AELEM ! $AUDIO_CAPS"

# FILE_SINK is the name of the file that the video will be saved in
# File is a .mp4, Video is H.264 encoded, audio is aac encoded
FILE_SINK="filesink location=gtest1.mp4"
# Address and port to serve the video stream; check to make sure ports are available and firewalls don't block it!
TCP_SINK="tcpserversink host=$IP_ADDRESS port=5000"

#show gst-launch on the command line; can be useful for debugging
echo gst-launch-1.0 -vvv -e \
   mp4mux name=mux ! $FILE_SINK \
   $VSOURCE ! tee name=tsplit 							\
   ! queue ! $VIDEO_DEC ! $VIDEO_SINK tsplit.					\
   ! queue ! h264parse ! mux.video_0 tsplit.					\
   ! queue ! h264parse ! mpegtsmux ! $TCP_SINK					\
   $ASOURCE ! queue ! $AUDIO_ENC ! queue ! mux.audio_0
 
# first queue is for the preview
# second queue writes to the file gtest1.mp4
# third queue sends H.264 in MPEG container over TCP
gst-launch-1.0 -vvv -e \
   mp4mux name=mux ! $FILE_SINK \
   $VSOURCE ! tee name=tsplit 							\
   ! queue ! $VIDEO_DEC ! $VIDEO_SINK tsplit.					\
   ! queue ! h264parse ! mux.video_0 tsplit.					\
   ! queue ! h264parse ! mpegtsmux ! $TCP_SINK					\
   $ASOURCE ! queue ! $AUDIO_ENC ! queue ! mux.audio_0

以上是关于sh Gstreamer示例预览,保存和流式传输视频的主要内容,如果未能解决你的问题,请参考以下文章

如何在 qwidget 中使用 GstElement 和 udpsrc 进行 gstreamer 流式传输

使用 gstreamer 在 android 手机中流式传输网络内容

通过 gstreamer udpsink 流式传输 h.264 时如何解决图像问题

AR Drone 2.0、Gstreamer、C++ RTMP 服务器(无需 SDK 的流式传输)

gstreamer视频进入python中的窗口

如何使用 GStreamer 从 IP RTMP 摄像机流式传输到 v4l2loopback 摄像机?