5

This command works perfectly for saving a webcam stream to a file:

ffmpeg -f alsa -i default -itsoffset 00:00:00 -f video4linux2 -s 1280x720 -r 25 -i /dev/video0  out.avi

How would I simultaneously display this captured stream on my computer screen?

norway-firemen
  • 315
  • 2
  • 5
  • 11

3 Answers3

5

I came here looking for the same command and the one from @llogan works, but with no audio. This is the command I started to use to capture with video in good quality and with audio.

ffmpeg -f v4l2 \
    -framerate 30 \
    -video_size 1024x768 \
    -input_format mjpeg \
    -i /dev/video0 \
    -f alsa \
    -i hw:2,0 \
    -c:a pcm_s16le \
    -c:v mjpeg \
    -b:v 64000k \
    output.avi \
    -map 0:v \
    -vf "format=yuv420p" \
    -f xv display

Maybe you want to see video as a mirror. If so, you have to add hflip to the video filter. Use -vf "format=yuv420p,hflip".

I prefer to use pulseaudio as audio input, so I can change it with pavucontrol on the fly. Instead of -f alsa -i hw:2,0, I use -f pulse -i alsa_input.usb-046d_HD_Pro_Webcam_C920_22F75AFF-02.analog-stereo that it is my webcam microphone. To know what your audio source input is, check here.

Source: Answer from @llogan and ffmpeg Documentation.

[EDIT]: I changed part of the code to get rip of the 1 second lag that -f tee generates. This method, instead of that option, directly encodes to file, changes format to yuv420p (accepted by display) and uses -f xv display to display video to screen.

Mario Mey
  • 151
2

Use the tee muxer:

ffmpeg -f v4l2 -i /dev/video0 -map 0 -c:v libx264 -f tee "output.mp4|[f=nut]pipe:" | ffplay pipe:
llogan
  • 63,280
0

Just pipe it with ffplay which comes bundled with the ffmpeg package.

As llogan mentioned, use the tee muxer/demuxer (aka) container!

# Redirect the 'ffmpeg' ouput to 'ffplay' input
ffmpeg -f alsa -i default -itsoffset 00:00:00 -f video4linux2 -s 1280x720 -r 25 -i /dev/video0 -f tee "out.avi|[f=nut]-" | ffplay -

tripulse
  • 264