Dear Psychtoolbox Community,
I am trying to record and display video from a webcam at the same time with Psychtoolbox.
With the Logitech C920 webcams I have, for good resolution and frame rate (e.g. 1280 x 720 at 30 fps) I need to query the device for MJPG format (as verified with v4l2-ctl). I can do so using ffmpeg or gstreamer directly (see example code later). With default Psychtoolbox video capture behavior (using e.g. VideoRecordingDemo) the device returns lower fps, seemingly corresponding to its limits with its default YUYV format.
I can plug in a custom Gstreamer pipe for Screen which gives me the expected quality and frame rate (example code below) but then I am unable to save the video, I can only display it. A file with the specified name is opened, but it always remains 0 bytes. What am I doing wrong?
System
Ubuntu 18.04.5 LTS
Intel Core i5-6500 CPU
Intel HD Graphics 530 (SKL GT2)
Gnome 3.28.2
GStreamer 1.14.5
Matlab 2017a
PsychtoolboxVersion
3.0.16 - Flavor: Debian package - psychtoolbox-3 (3.0.16.20200326.dfsg1-1~nd18.04+1)
Minimal code to reproduce:
Insert the following lines to VideoRecordingDemo.m instead of line 227:
% Custom Gstreamer pipeline definition:
capturebinspec = 'v4l2src device=/dev/video0 ! jpegdec ! videoconvert';
Screen('SetVideoCaptureParameter', -1, sprintf('SetNextCaptureBinSpec=%s', capturebinspec));
grabber = Screen('OpenVideoCapture', win, -9, [0 0 640 480], [], [], [], codec, withsound, [], 8);
The demo seemingly works as expected but does not save out the video, leaves a 0 bytes file.
The output of VideoRecordingDemo.m with the custom Gstreamer pipe at debug verbosity is here:
customDemo_output
A more involved, but still minimal example to reproduce the problem is here:
minExample.m
Gstreamer code that both displays and saves the video (I would like to achieve similar behavior with Psychtoolbox):
gst-launch-1.0 -v v4l2src device=/dev/video0 \
! jpegdec \
! video/x-raw,width=1280,height=720,framerate=30/1 \
! tee name=t t. \
! queue ! xvimagesink sync=false t. \
! queue ! videoconvert ! x264enc tune=zerolatency ! h264parse \
! matroskamux ! filesink location='test.mkv' sync=false
What I tried and did not work:
- Including / leaving out the
! videoconvert
part from the gstreamer specification - Playing around with pixel depth values, recording flags, resolutions
Thank you for any advice,
adam boncz