Search code examples
ffmpegvideo-streamingwebcamh.264

How to get non-decoded h264 stream from the webcam using ffmpeg?


I want to get the file which is non-decoded h264 format to use in another client application. I know how to stream to disk using below command from the docs.

Example to encode video from /dev/video0:

ffmpeg -f v4l2 -framerate 25 -video_size 640x480 -i /dev/video0 output.mp4

High level Diagram

This is typical producer and consumer problem -

Webcam  =============> ffmpeg to  video stream into file. (producer)                                    
                                       ^
                                       |
                                       |
Client ________________________________|
(consumer)
// reads only Non-decoded h264 format from a file. 

Solution

  • I found this as solution

    ffmpeg  -pix_fmt yuv420p -y -f v4l2 -vcodec h264  -i /dev/video0 out.h264