You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何用Raspberry Pi+VLC实现Logitech C920无转码H264音视频监控

Great question! Using the Logitech C920's native H264 output is exactly the right approach to skip CPU-heavy video transcoding on your Raspberry Pi. The only hurdle is muxing its separate audio and video streams into a single HTTP-accessible feed—and we can do this with minimal resource usage. Let's break it down:

Step 1: Confirm Your Device Parameters

First, make sure we're leveraging the C920's built-in H264 encoding and identify its audio device:

  • Check video formats: Run this command to list supported output formats for your camera:
    v4l2-ctl --list-formats-ext -d /dev/video0
    
    Look for entries labeled H.264—note the supported resolutions (like 1280x720 or 1920x1080) and frame rates (usually 30fps). Stick to these values later to avoid forcing the camera to transcode internally.
  • Locate the audio device: The C920's mic shows up as a separate ALSA device. Run:
    arecord -l
    
    You'll see something like:
    card 1: C920 [HD Pro Webcam C920], device 0: USB Audio [USB Audio]
    
    Jot down the hw:X,Y identifier (in this case, hw:1,0)—that's your audio input.
Step 2: Stream with FFmpeg (No Video Transcoding!)

We'll use FFmpeg to pull the raw H264 video stream directly from the camera, capture audio from the mic, mux them into a stream-friendly format, and host it over HTTP. This uses almost zero CPU for video (since we're just copying the stream) and minimal CPU for audio encoding (AAC is lightweight).

Run this command (adjust the video size, framerate, and audio device to match your findings):

ffmpeg -f v4l2 -input_format h264 -video_size 1280x720 -framerate 30 -i /dev/video0 \
-f alsa -i hw:1,0 -c:v copy -c:a aac -b:a 128k -f mpegts \
http://0.0.0.0:8080/stream.ts

Let's break down the key flags:

  • -input_format h264: Tells FFmpeg to accept the C920's native H264 output (no transcoding!)
  • -c:v copy: Directly copies the video stream—zero CPU overhead here
  • -c:a aac: Converts the mic's raw PCM audio to AAC (super low CPU usage on Pi)
  • -f mpegts: Uses MPEG-TS as the container, which is ideal for HTTP streaming (no buffering delays)
  • http://0.0.0.0:8080/stream.ts: Hosts the stream on all your Pi's network interfaces at port 8080
Step 3: Access the Stream

Once the command is running, you can view the stream from any device on your network:

  • Desktop: Use VLC, PotPlayer, or even Chrome/Firefox (just paste http://<your-pi-ip>:8080/stream.ts into the address bar)
  • Mobile: Use VLC for Android/iOS, or a dedicated IP camera app that supports HTTP TS streams
Step 4: Run the Stream Automatically on Boot

To make this a permanent setup, create a systemd service so the stream starts when your Pi boots:

  1. Create a service file:
    sudo nano /etc/systemd/system/cam-stream.service
    
  2. Paste this content (adjust the FFmpeg command to match your parameters):
    [Unit]
    Description=C920 Baby Monitor Stream
    After=network.target
    
    [Service]
    User=pi
    ExecStart=/usr/bin/ffmpeg -f v4l2 -input_format h264 -video_size 1280x720 -framerate 30 -i /dev/video0 -f alsa -i hw:1,0 -c:v copy -c:a aac -b:a 128k -f mpegts http://0.0.0.0:8080/stream.ts
    Restart=always
    RestartSec=5
    
    [Install]
    WantedBy=multi-user.target
    
  3. Enable and start the service:
    sudo systemctl enable cam-stream
    sudo systemctl start cam-stream
    

Now your stream will automatically start whenever your Pi powers on.

Step 5: Add Basic Security (Optional)

If you want to restrict access to the stream, set up an NGINX reverse proxy with password authentication:

  1. Install NGINX:
    sudo apt update && sudo apt install nginx apache2-utils
    
  2. Create a password file (replace pi with your desired username):
    sudo htpasswd -c /etc/nginx/.htpasswd pi
    
  3. Edit the NGINX default config:
    sudo nano /etc/nginx/sites-available/default
    
  4. Replace the location / block with this (replace <your-pi-ip> with your Pi's actual IP):
    server {
        listen 80;
        server_name <your-pi-ip>;
    
        location /stream.ts {
            proxy_pass http://localhost:8080/stream.ts;
            auth_basic "Baby Monitor Access";
            auth_basic_user_file /etc/nginx/.htpasswd;
        }
    }
    
  5. Restart NGINX:
    sudo systemctl restart nginx
    

Now you'll need to enter the username/password to access http://<your-pi-ip>/stream.ts.

Troubleshooting Tips
  • Camera disconnects: The C920 draws more power than some USB ports can handle. Use an externally powered USB hub, or ensure your Pi is using the official 5V/3A power supply.
  • No audio: Double-check your ALSA device ID with arecord -l—make sure you're using the correct hw:X,Y value in the FFmpeg command.
  • Choppy stream: Lower the resolution (e.g., 1280x720 instead of 1920x1080) or frame rate if your network bandwidth is limited.

内容的提问来源于stack exchange,提问作者LoneWanderer

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.25 04:05:07