A C++ application using GStreamer to capture webcam video with MJPEG input, apply various transformations, and encode/decode using NVIDIA hardware acceleration.
- MJPEG Input: Captures from
/dev/video0at 1280x720@30fps in MJPEG format - Video Processing Pipeline:
- Decode MJPEG stream
- Upscale to 1920x1080
- Apply color inversion filter (frei0r-filter-invert0r)
- Horizontal flip
- NV12 format optimization for NVIDIA hardware
- NVIDIA H.264 hardware encoding (10Mbps, low-latency)
- NVIDIA H.264 hardware decoding
- Auto Video Display: Automatically selects appropriate video sink
- Linux operating system
- Webcam device at
/dev/video0supporting MJPEG format - NVIDIA GPU with hardware encoding/decoding support (for nvh264enc/nvh264dec)
- GStreamer 1.0 or later
sudo apt-get update
sudo apt-get install -y \
build-essential \
pkg-config \
libgstreamer1.0-dev \
libgstreamer-plugins-base1.0-dev \
gstreamer1.0-plugins-base \
gstreamer1.0-plugins-good \
gstreamer1.0-plugins-bad \
gstreamer1.0-tools \
gstreamer1.0-plugins-ugly \
frei0r-plugins \
gstreamer1.0-plugins-nvcodecOr use the Makefile target:
make install-deps
make install-nvidia-depsmakemake clean./webcam_captureOr use the Makefile:
make runThe application will:
- Initialize the GStreamer pipeline
- Start capturing from the webcam
- Apply transformations and display the video
- Run for 10,000 seconds (configurable in source)
- Press Ctrl+C to stop early
The GStreamer pipeline performs the following steps:
- Capture:
v4l2src device=/dev/video0- Captures from webcam - Input Format: MJPEG 1280x720@30fps
- Decode:
jpegdec- Decodes MJPEG - Convert:
videoconvert- Converts to raw video - Upscale:
videoscale- Scales to 1920x1080 - Invert:
frei0r-filter-invert0r- Inverts colors - Flip:
videoflip method=horizontal-flip- Mirrors horizontally - Format:
video/x-raw,format=NV12- Optimized format for NVIDIA hardware - Encode:
nvh264enc- NVIDIA H.264 encoding at 10Mbps (low-latency, CBR) - Parse:
h264parse- Parses H.264 stream - Decode:
nvh264dec- NVIDIA H.264 decoding - Display:
autovideosink- Displays video
NV12 is the native format for NVIDIA NVENC/NVDEC hardware, providing:
- Zero-copy operations between videoconvert and nvh264enc
- Optimal GPU performance
- Lower CPU overhead compared to I420 format
Edit main.cpp to customize:
- Input device path
- Resolution and framerate
- Bitrate and encoding settings
- Video filters and effects
- Display duration
Then rebuild with make.