ffplay can nicely open e.g. /dev/video0 and monitor the incoming video frames (e.g. you can watch TV on a TV card). Giving /dev/video to ffmpeg also makes it easy to encode the video.

Is it possible to do both: get video frames onto the screen while also encoding them at the same time?

1 Answer 1


There are many ways. I usually copy the raw video stream to a ffplay instance with the help of tee:

ffmpeg -hide_banner -loglevel error -f v4l2 -pixel_format yuyv422 -video_size 1280x960 -i /dev/video0 -c:v copy -f rawvideo - |\
tee >(ffplay -f rawvideo -pixel_format yuyv422 -video_size 1280x960 -) |\
ffmpeg -f rawvideo -pixel_format yuyv422 -video_size 1280x960 -i - -c:v libx264 -crf 21 -y /tmp/encoded.mp4

In case you want to see the raw input as well as the output, the example is a bit more convoluted:

ffmpeg -hide_banner -loglevel error -f v4l2 -pixel_format yuyv422 -video_size 640x480 -r 25 -i /dev/video0 -c:v copy -f rawvideo - | \
tee >(ffplay -hide_banner -loglevel error -window_title "Input" -f rawvideo -pixel_format yuyv422 -video_size 640x480 -) | \
ffmpeg -hide_banner -loglevel error -f rawvideo -pixel_format yuyv422 -video_size 640x480 -i - -c:v libx264 -crf 21 -f h264 - | \
tee >(ffplay -hide_banner -loglevel error -window_title "Encoded" -f h264 -) | \
ffmpeg -f h264 -r 25 -i - -y /tmp/encoded.mp4

Be sure to specify matching pixel formats, resolutions and frame-rates.

  • 1
    works great, thank you!!!
    – Latanius
    Jun 10, 2020 at 9:05

You must log in to answer this question.

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