Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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.

share|improve this question
    
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 –  LordNeckbeard Oct 7 '13 at 17:37

2 Answers 2

up vote 2 down vote accepted

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:

share|improve this answer
    
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. –  LordNeckbeard 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:

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.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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