How to record only video from V4L2 input device and encode it to a file using H.264 while seeing a live preview of the input at the same time?
Using GStreamer GStreamer 0.10.36
Commandgst-launch-1.0
Using v4l-utils 1.6.3-3
Commandv4l2-ctl
Determine available resolutions and formats:
v4l2-ctl -d /dev/video0 --list-formats-ext
Preview, record & encode at the same time:
"format", "width", "height" and "framerate" need to be filled in.
"keyframe_period" specifies how often a keyframe appears in the video, which is used for reconstruction of a video frame and (to my understanding) seeking.
"min-qp" specifies compression quality where lower means better quality.
:
gst-launch-1.0 v4l2src device=/dev/video0 ! \
video/x-raw,format=YV12,width=960,height=544,framerate=30/1 ! \
tee name=t ! \
queue ! \
autovideosink sync=false t. ! \
videorate ! \
queue ! \
vaapiencode_h264 keyframe_period=5 tune=high-compression min-qp=50 ! \
queue ! \
mpegtsmux ! \
filesink location=FIRST.mp4
(For some reason the resulting FIRST.mp4 cannot be seeked. Something about invalid timestamps.)
Rebuilding the mp4 container without re-encoding produces a seekable mp4 file:
ffmpeg -i FIRST.mp4 -c:v copy SECOND.mp4