WelcomeWelcome | FAQFAQ | DownloadsDownloads | WikiWiki

Author Topic: webcam extension  (Read 4316 times)

Offline ashfame

  • Full Member
  • ***
  • Posts: 112
webcam extension
« on: August 04, 2020, 04:56:52 AM »
Hi, what extension should I load for using webcam?

I tried `rpi-vc` but that didn't work. Trying to use the webcam from browser triggered an error, can't find video stream (notfound error). Its a webcam connected directly via CSI interface & works in raspbian os (so no fault with hardware).

Is there anything else that I need to do or load?

Online Juanito

  • Administrator
  • Hero Member
  • *****
  • Posts: 14225
Re: webcam extension
« Reply #1 on: August 04, 2020, 05:02:08 AM »
What version of piCore are you using?

The RPi camera works for me with piCore-9.x and piCore-11.x with both rpi-vc and libv4l2

See: http://forum.tinycorelinux.net/index.php/topic,23923.msg150583.html#msg150583

Offline ashfame

  • Full Member
  • ***
  • Posts: 112
Re: webcam extension
« Reply #2 on: August 04, 2020, 05:07:15 AM »
What version of piCore are you using?

The RPi camera works for me with piCore-9.x and piCore-11.x with both rpi-vc and libv4l2

See: http://forum.tinycorelinux.net/index.php/topic,23923.msg150583.html#msg150583

Using piCore-11.x, I only loaded `rpi-vc` and not `libv4l2`. Will give that a try.

Offline ashfame

  • Full Member
  • ***
  • Posts: 112
Re: webcam extension
« Reply #3 on: August 04, 2020, 08:04:15 AM »
What version of piCore are you using?

The RPi camera works for me with piCore-9.x and piCore-11.x with both rpi-vc and libv4l2

See: http://forum.tinycorelinux.net/index.php/topic,23923.msg150583.html#msg150583

I tried both of them loaded and either of them loaded, browser can't find the camera. Is there an extension that works as a standalone camera app that I can test?

From your linked topic, I also tried adding start_x=1 and gpu_mem=64 to config.txt but still same error.

Online Juanito

  • Administrator
  • Hero Member
  • *****
  • Posts: 14225
Re: webcam extension
« Reply #4 on: August 04, 2020, 09:24:21 AM »
Did you reboot after changing config.txt?

You can use ffmpeg, gstreamer or motion to view the camera image/video
« Last Edit: August 04, 2020, 09:25:52 AM by Juanito »

Offline ashfame

  • Full Member
  • ***
  • Posts: 112
Re: webcam extension
« Reply #5 on: August 04, 2020, 01:04:16 PM »
Did you reboot after changing config.txt?

You can use ffmpeg, gstreamer or motion to view the camera image/video

Yeah! I did reboot.

I tried downloading ffmpeg & gstreamer from repo, but I found atleast this dependency is missing: http://tinycorelinux.net/11.x/armv7/tcz/v4l-dvb-4.9.22-piCore-v7.tcz.info

There was another missing related to alsa, but I have no use for audio, so I am ignoring that one.

After loading both extensions, ffmpeg and gstreamer / gst-launch threw "not found" error. Not sure how to invoke them? If you can provide the full command to try grabbing a picture from camera, that would be helpful :)

None of those 3 are available, what extension do I load for it? I don't have networking, so I have to write files to a SD card and then boot from it.

Offline ashfame

  • Full Member
  • ***
  • Posts: 112
Re: webcam extension
« Reply #6 on: August 04, 2020, 02:10:27 PM »
None of those 3 are available, what extension do I load for it?

Ignore this pls.

Online Juanito

  • Administrator
  • Hero Member
  • *****
  • Posts: 14225
Re: webcam extension
« Reply #7 on: August 05, 2020, 01:28:57 AM »
For the purposes of testing, you should either usr rpi-vc or libv4l2, but not both together.

Using libv4l2.

The link I posted earlier gave two ways to test the camera, did you try them?

To take a photo:
Code: [Select]
$ v4l2-ctl --overlay=1 [enable viewfinder]
$ v4l2-ctl --set-fmt-video=width=2592,height=1944,pixelformat=3
$ v4l2-ctl --stream-mmap=3 --stream-count=1 --stream-to=photo.jpg

To record a video:
Code: [Select]
$ v4l2-ctl --overlay=1 [enable viewfinder]
$ v4l2-ctl --set-fmt-video=width=1920,height=1088,pixelformat=4
$ v4l2-ctl --stream-mmap=3 --stream-count=100 --stream-to=video.264
..adjust stream count for a longer video

Something like this would probably also work:
Code: [Select]
$ ffmpeg -f v4l2 -video_size 640x480 -framerate 5 -i /dev/video0
..and perhaps this:
Code: [Select]
$ gst-launch-1.0 -q v4l2src ! glimagesink
You also stream the camera image using the motion extension.

First edit /usr/local/etc/motion/motion.conf

webcontrol_localhost off
stream_localhost off

Then:
Code: [Select]
$ motion -n
[and from another machine on the lan]
$ ffplay http://192.168.1.111:8081

Offline ashfame

  • Full Member
  • ***
  • Posts: 112
Re: webcam extension
« Reply #8 on: August 05, 2020, 01:31:09 AM »
Thanks for the direct commands, but I indeed tried loading the extensions individually as well, only to find the executable isn't there. command not found error.
« Last Edit: August 05, 2020, 01:36:09 AM by Juanito »

Online Juanito

  • Administrator
  • Hero Member
  • *****
  • Posts: 14225
Re: webcam extension
« Reply #9 on: August 05, 2020, 01:41:26 AM »
When you are replying to the previous post there is no need to quote it.

How are you downloading the extensions? If you use "tce-load" or the apps gui it should ensure that all required dependencies are installed.

Using v4l2-utils what exact error do you get?

Offline ashfame

  • Full Member
  • ***
  • Posts: 112
Re: webcam extension
« Reply #10 on: August 05, 2020, 08:09:55 AM »
I was downloading extensions by using fetchExt.sh script that I got from a topic in forums. Rich pointed me towards that and it has been very helpful so far but I just realized that missing dependency is caused by that script only.

Also, I was trying to load just `libv4l2` but from your last response, I realized I should be using `v4l2-utils` instead.

This time, I loaded extensions via internet, using tce-load (long story, was earlier developing on Raspberry Pi Zero, so had no networking options but now using Raspberry Pi 2B) then I was able to download that missing dependency.

This resulted in atleast the browser prompting for granting access to camera, but it shows 3 cameras, and none of them works when I select one (I get abort error in browser console). Here's a screenshot with their names - https://imgur.com/a/URfh58k

When I try in terminal using v4l2-ctl or ffmpeg command, it says `cannot open device /dev/video0, exiting`

Offline ashfame

  • Full Member
  • ***
  • Posts: 112
Re: webcam extension
« Reply #11 on: August 05, 2020, 08:27:00 AM »
Forgot to add `start_x=1` in `config.txt` this time and upon adding it, a 4th camera showed up which works for good 10 seconds before eating up the free memory and tab crashes.

Any idea if just displaying the stream in a browser window is supposed to eat memory or I have a memory leak of some kind?

Online Juanito

  • Administrator
  • Hero Member
  • *****
  • Posts: 14225
Re: webcam extension
« Reply #12 on: August 05, 2020, 09:08:29 AM »
When I used the camera locally I either wrote the video to file or used ffmpeg/gstreamer to view the video in a gtk3 window.

I only used a browser on a laptop to view the camera remotely using motion.

On an RPi3 with 1gb ram I did not run out of memory.

Offline ashfame

  • Full Member
  • ***
  • Posts: 112
Re: webcam extension
« Reply #13 on: August 05, 2020, 09:18:54 AM »
About 230M of memory left on Raspberry Pi 2B (1GB RAM), the camera once its allowed access in browser and shown in <video> tag, it eats few MBs of memory every second until it runs out of memory at which point the browser tab crashes, freeing all the memory. In between, at times, it tries to release the memory and I see free memory jump but eventually it reaches single digit and tab crashes in the next few secs.

Offline ashfame

  • Full Member
  • ***
  • Posts: 112
Re: webcam extension
« Reply #14 on: August 05, 2020, 10:10:48 AM »
When I used the camera locally I either wrote the video to file or used ffmpeg/gstreamer to view the video in a gtk3 window.

Can you elaborate your setup of capturing video feed and how you show that in a gtk3 window? I am in the same boat, except I am using a full browser to be able to do that.

I am totally running based off ram fs, so I can't afford to write video feed anywhere, except stream for preview in UI & somehow parse QR code from each frame.