Skip to content

leonardsfetcu/vision

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 

Repository files navigation

GStreamer Webcam Capture

A C++ application using GStreamer to capture webcam video with MJPEG input, apply various transformations, and encode/decode using NVIDIA hardware acceleration.

Features

  • MJPEG Input: Captures from /dev/video0 at 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

Prerequisites

System Requirements

  • Linux operating system
  • Webcam device at /dev/video0 supporting MJPEG format
  • NVIDIA GPU with hardware encoding/decoding support (for nvh264enc/nvh264dec)
  • GStreamer 1.0 or later

Dependencies

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-nvcodec

Or use the Makefile target:

make install-deps
make install-nvidia-deps

Building

Compile the application:

make

Clean build artifacts:

make clean

Usage

Run the application:

./webcam_capture

Or use the Makefile:

make run

The application will:

  1. Initialize the GStreamer pipeline
  2. Start capturing from the webcam
  3. Apply transformations and display the video
  4. Run for 10,000 seconds (configurable in source)
  5. Press Ctrl+C to stop early

Pipeline Details

The GStreamer pipeline performs the following steps:

  1. Capture: v4l2src device=/dev/video0 - Captures from webcam
  2. Input Format: MJPEG 1280x720@30fps
  3. Decode: jpegdec - Decodes MJPEG
  4. Convert: videoconvert - Converts to raw video
  5. Upscale: videoscale - Scales to 1920x1080
  6. Invert: frei0r-filter-invert0r - Inverts colors
  7. Flip: videoflip method=horizontal-flip - Mirrors horizontally
  8. Format: video/x-raw,format=NV12 - Optimized format for NVIDIA hardware
  9. Encode: nvh264enc - NVIDIA H.264 encoding at 10Mbps (low-latency, CBR)
  10. Parse: h264parse - Parses H.264 stream
  11. Decode: nvh264dec - NVIDIA H.264 decoding
  12. Display: autovideosink - Displays video

Why NV12?

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

Customization

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.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors