Last active
September 8, 2019 17:30
-
-
Save jetsonhacks/4fcedcb00a3ca3389b76 to your computer and use it in GitHub Desktop.
Using Gstreamer, take a h264 stream from a Logitech c920, preview it on the display and save it to a file along with the webcam audio.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# Preview and save webcam video on NVIDIA Jetson TK1 | |
# Grab audio and video (in h264 format) from Logitech c920 @ 1920x1080 | |
# Preview @ 1280x720 on screen | |
# Store video to file named gEncode1080p.mp4 | |
# Logitech c920 is video1 on this machine | |
VELEM="v4l2src device=/dev/video1 do-timestamp=true" | |
# Video capability from the camera - get h264 1920x1080 | |
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 ON THE DISPLAY ; 1280x720 here | |
PREVIEW_SCALE="video/x-raw, width=1280, height=720" | |
# VIDEO_SINK is the preview window | |
VIDEO_SINK="videoconvert ! videoscale ! $PREVIEW_SCALE ! xvimagesink sync=false" | |
FILE_SINK="filesink location=gEncode1080p.mp4" | |
# ============ AUDIO =========================== | |
# Use $ pctl list | |
# to get the device ; | |
# alsasrc had issues, so pulsesrc was used instead | |
AELEM="pulsesrc device=alsa_input.usb-046d_HD_Pro_Webcam_C920_A116B66F-02-C920.iec958-stereo do-timestamp=true" | |
AUDIO_CAPS="audio/x-raw" | |
AUDIO_ENC="audioconvert ! voaacenc" | |
ASOURCE="$AELEM ! $AUDIO_CAPS" | |
#show the gst-launch command line; can be useful for debugging | |
echo gst-launch-1.0 -vvv -e \ | |
mp4mux name=filemux ! $FILE_SINK \ | |
$VSOURCE ! tee name=tsplit \ | |
! queue ! $VIDEO_DEC ! $VIDEO_SINK tsplit. \ | |
! queue ! h264parse ! filemux.video_0 \ | |
$ASOURCE ! queue ! $AUDIO_ENC ! filemux.audio_0 | |
# mp4mux filemux is the multiplexer for the file that's being written | |
# Video and Audio source go into the filemux | |
# Video also goes into the VIDEO_SINK, which is a window on the display | |
gst-launch-1.0 -vvv -e \ | |
mp4mux name=filemux ! $FILE_SINK \ | |
$VSOURCE ! tee name=tsplit \ | |
! queue ! $VIDEO_DEC ! $VIDEO_SINK tsplit. \ | |
! queue ! h264parse ! filemux.video_0 \ | |
$ASOURCE ! queue ! $AUDIO_ENC ! filemux.audio_0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hello chickenrun525,
I am trying to do the same. I have a logitech c920 and I am usung Ubuntu 14.04 but when I run your command I get a static image displayed (not a video stream) and nothing is saved into the file location. I see a lot of ways of doing this with gstreamer-0.10 and this example for gstreamer-1.0 is not working. I am interested only in the video, so I dont need the audio part.
My gstreamer version:
gst-launch-1.0 version 1.2.4
GStreamer 1.2.4