title: Getting raw h264 packets from USB camera on Raspberry Pi
body: <p>I am trying to receive H264 frames from a USB webcamera connected to my Raspberry PI</p>
  
  <p>Using the RPi Camera Module I can run the following command to get H264 data outputted in stdin: <code>raspivid -t 0 -w 640 -h 320 -fps 15 -o -</code> with <strong>close to  zero latency</strong> </p>
  
  <p>Is there an equivalent function to do this with a USB camera? I have two USB cameras I would like to do this with.</p>
  
  <p>Using <code>ffprobe /dev/videoX</code> I get the following output: (shorted down to the important details):</p>
  
  <pre><code>$ ffprobe /dev/video0
  ...
  Input #0, video4linux2,v4l2, from '/dev/video0':
  Duration: N/A, start: 18876.273861, bitrate: 147456 kb/s
  Stream #0:0: Video: rawvideo (YUY2 / 0x32595559), yuyv422, 1280x720, 147456 kb/s, 10 fps, 10 tbr, 1000k tbn, 1000k tbc
  
  $ ffprobe /dev/video1
  ...
  Input #0, video4linux2,v4l2, from '/dev/video1':
  Duration: N/A, start: 18980.783228, bitrate: 115200 kb/s
  Stream #0:0: Video: rawvideo (YUY2 / 0x32595559), yuyv422, 800x600, 115200 kb/s, 15 fps, 15 tbr, 1000k tbn, 1000k tbc
  
  
  $ ffprobe /dev/video2
  ...
  Input #0, video4linux2,v4l2, from '/dev/video2':
  Duration: N/A, start: 18998.984143, bitrate: N/A
  Stream #0:0: Video: h264 (Main), yuv420p(progressive), 1920x1080, -5 kb/s, 30 fps, 30 tbr, 1000k tbn, 2000k tbc
  </code></pre>
  
  <p>As far as I can tell two of them are not H264, which will need to be "decoded" to H264 so I understand there is added a bit latency there. But the third one (video2) is H264 so I should be able to get data from it? I've tried to just pipe it out with CAT but it says I got invalid arguments.</p>
  
  <p>I've come as far as using FFMPEG might be the only option here. Would like to use software easily available for all RPi (apt install).</p>
  
  <p><strong>Bonus question regarding H264 packets:</strong> When I stream the data from raspivid command to my decoder it works perfectly. But if I decide to drop the 10 first packets then it never initializes the decoding process and just shows a black background. Anyone know what might be missing in the first packets that I might be able to recreate in my software so I dont have to restart the stream for every newly connected user?</p>
  
  <p><strong>EDIT: Bonus Question Answer:</strong> After googling around I see that the first two frames <code>raspivid</code> sends me are. So by ignoring the two first frames my decoder wont "decode" properly. So if I save those frames and send them first to all new users it works perfectly. Seems like these are used in some kind of initial process.</p>
  
  <pre><code>0x27 = 01 00111 = type 7    Sequence parameter set (B-frame)
  0x28 = 01 01000 = type 8    Picture parameter set (B-frame)
  </code></pre>