M
M
Maxim Gabelkov2016-12-06 14:19:55
Raspberry Pi
Maxim Gabelkov, 2016-12-06 14:19:55

How to fix problems recording webcam video in Gstreamer?

Hello!
I use an old webcam to make video surveillance of the front door. The camera with a microphone is connected to the Raspberry Pi via USB, on which video is recorded with sound using the following Gstreamer pipeline:

gst-launch-1.0 -e v4l2src do-timestamp=true \
  ! video/x-raw,format=YV12,width=640,height=480,framerate=5/1 \
  ! videoconvert ! queue ! videorate ! videoflip method=clockwise \
  ! clockoverlay halignment=left valignment=bottom time-format="%Y/%m/%d %H:%M:%S" font-desc="Sans 24" \
  ! omxh264enc target-bitrate=400000 control-rate=variable \
  ! video/x-h264,stream-format=byte-stream,framerate=5/1 ! h264parse \
  ! queue ! mux. alsasrc device=plughw:0,0 do-timestamp=true \
  ! lamemp3enc target=0 bitrate=128 mono=true \
  ! queue leaky=2 max-size-buffers=0 max-size-time=0 max-size-bytes=0 \
  ! mux. matroskamux name=mux ! queue \
  ! filesink location=camera`date -Iseconds`.mkv >> recorder.log 2>&1

I use Gstreamer because of the hardware encoding (omxh264enc) so as not to overload the raspberry processor. I just started to understand Gstreamer, advice on the pipeline is welcome. Pipeline is running in an endless loop, I restart it once an hour by cron to start a new file. Everything works, but there are the following problems, on which I want to ask for advice.
Container issues. I still couldn't choose the right container for the video. Now the video is saved in mkv, the problem is that the first frame is always green, and the green continues for the first 10 seconds of the video, WHAT? Also, the video is rather slow to play, when rewinding to the middle of the file, the sound first turns on, and then the video "catches up" after a few seconds. How to fix it? It probably has something to do with keyframes, but I'm not good at it.
I tried to write to mp4 , but in this container the index is at the end of the file, that is, if the recording fails, we get a damaged file that cannot be played.
I also tried to write in avi, but again there is a problem with the first frame (the image seems to be shifted half up) and there is a strong desynchronization of audio and video, after the end of the hour-long video, there are 20 seconds of sound that is played on the frozen last frame. I haven't figured out how to fix it.
Intermittent hiss instead of sound. On the recordings, there is periodically hiss that overlaps the sound, which itself disappears at random intervals, and the normal sound returns. How to fix it? Is it because of the leaky queue?
Strange errors in dmesg. They appear in different combinations when writing, they repeat a lot cannot get freq at ep 0x86 . I could not understand why they are, and whether they are related to the above problems.
usb 1-1.5: 1:1: cannot get freq at ep 0x5
usb 1-1.5: 1:1: cannot set freq 48000 to ep 0x5
usb 1-1.5: 2:1: cannot get freq at ep 0x86
usb 1-1.5: 2:1: cannot set freq 48000 to ep 0x86
uvcvideo: Failed to resubmit video URB (-1).

PS: GStreamer 1.4.4 from the repositories, Raspbian Jessie.
PPS: Tried to use motion and write only when motion is detected, but Raspberry Pi only gets acceptable framerate at low resolutions, and in addition Raspberry Pi overheats during long periods of motion.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Roman Mindlin, 2016-12-15
@kgbplus

How is the first frame green? Just a green field or a normal image, but with a strong admixture of greenery? If the second - then this camera does not have time to adjust, the first frames must be discarded. The container has nothing to do with it. raspistill with a built-in camera generally gives the camera 5 seconds to set up by default, and I experimented - in 3 seconds the camera really does not have time to set up in some conditions and gives just a green picture.
The error in dmesg is easy to google.

This is a known bug, unfortunately not fully resolved.
For more details and possible workarounds see
https://bugs.launchpad.net/ubuntu/+source/linux/+b...
https://bugs.launchpad.net/ubuntu/+source/linux/+b.. .

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question