3

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?

Thanks.

1
  • 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
    Commented Oct 7, 2013 at 17:37

2 Answers 2

2

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 \
"archive-20121107.mkv|[f=mpegts]udp://10.0.1.255:1234/"

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

Also see:

3
  • 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
    Commented Oct 9, 2013 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
    Commented Oct 9, 2013 at 19:40
  • Thanks for the link :) I saw Dranger tutorial, but your link is the most up-to-date source code.
    – vivienlwt
    Commented Oct 10, 2013 at 9:15
0

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:

avdevice_register_all();

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);

Finally:

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.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .