I found that in linux you can use video4linux2 and ffmpeg to read the data from /dev/video0 and grab the video from webcam. ffmpeg output the data to a video file, which has a limited length. My question is:

Can I pipe the the video stream both to remote viewer and to a local program so that I can keep processing the stream data in real time?


  • You should always include your ffmpeg command and the complete console output, or if you don't have a command then at least include some information about the input (including the complete console output): ffmpeg -f v4l2 -i /dev/video0 – llogan Oct 7 '13 at 17:37

This is possible with the tee muxer. Modified example from the documentation:

ffmpeg -f v4l2 -i /dev/video0 -c:v libx264 -c:a mp2 -f tee -map 0:v -map 0:a \

Note that the streams need to be explicitly mapped, so that is why -map is required.

Also see:

  • Thanks, that. I am thinking the other part of my question, if processing the video stream in real time can be solved by piping the stream to localhost and use ffmpeg libraries to process the stream by indicating the source. If this does not work, then I need to find other approaches. – vivienlwt Oct 9 '13 at 14:51
  • @vivienlwt I have no experience using the libraries, but you may also want to see the updated source code version of the Dranger tutorial and doc/examples. – llogan Oct 9 '13 at 19:40
  • Thanks for the link :) I saw Dranger tutorial, but your link is the most up-to-date source code. – vivienlwt Oct 10 '13 at 9:15

I found the answer from this link to get webcam as the input for video (using library). You just need to define the parameters in function avformat_open_input().

First, device registration is import:


Then define the input format:

AVInputFormat *inputFormat =av_find_input_format("v4l2");

Possible to set other options:

AVDictionary *options = NULL;

av_dict_set(&options, "framerate", "25", 0);


avformat_open_input(&pFormatCtx, "/dev/video0", inputFormat, &options);

After that, for each frame read and decoded from the input source, you can pass it either to the display or other customized function.

Hope this be helpful to the others.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.