Tiny Core Linux

Tiny Core Base => Raspberry Pi => Topic started by: ashfame on August 04, 2020, 04:56:52 AM

Title: webcam extension
Post by: ashfame 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?
Title: Re: webcam extension
Post by: Juanito 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
Title: Re: webcam extension
Post by: ashfame 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.
Title: Re: webcam extension
Post by: ashfame 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.
Title: Re: webcam extension
Post by: Juanito 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
Title: Re: webcam extension
Post by: ashfame 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.
Title: Re: webcam extension
Post by: ashfame on August 04, 2020, 02:10:27 PM
None of those 3 are available, what extension do I load for it?

Ignore this pls.
Title: Re: webcam extension
Post by: Juanito 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
Title: Re: webcam extension
Post by: ashfame 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.
Title: Re: webcam extension
Post by: Juanito 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?
Title: Re: webcam extension
Post by: ashfame 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`
Title: Re: webcam extension
Post by: ashfame 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?
Title: Re: webcam extension
Post by: Juanito 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.
Title: Re: webcam extension
Post by: ashfame 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.
Title: Re: webcam extension
Post by: ashfame 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.
Title: Re: webcam extension
Post by: Juanito on August 05, 2020, 10:44:28 AM
It's been a couple of months, but as I recall:
Code: [Select]
$ tce-load -i Xorg flwm aterm wbar gtk3 libv4l2
$ startx
$ ffmpeg -f v4l2 -video_size 640x480 -framerate 5 -i /dev/video0
Title: Re: webcam extension
Post by: ashfame on August 05, 2020, 11:56:47 AM
Really interested to know more on gtk3 window, how does that work? I am trying to see if how you are doing it, can replace my need of the browser? I essentially need to run a kiosk (full screen launched automatically) for personal use of whoever is using my project to build their air-gapped crypto vault.
Title: Re: webcam extension
Post by: Juanito on August 05, 2020, 11:13:11 PM
I'm not sure what you are asking - does it work for you (and if not, what error messages do you get)?
Title: Re: webcam extension
Post by: ashfame on August 06, 2020, 02:47:24 AM
Well, I am interested to know how you show the video stream in that gtk3 window.

ffmpeg lets you source the video stream from /dev/video0 but where does it stream to or make it available? How does gtk3 window, I am assuming <video> shows that stream?
Title: Re: webcam extension
Post by: Juanito on August 06, 2020, 03:22:38 AM
I don't recall having to do anything other than issuing the ffmpeg command given earlier, which opened a window to display the video locally.
Title: Re: webcam extension
Post by: ashfame on August 06, 2020, 05:16:53 AM
Gotcha! I couldn't imagine ffmpeg will invoke gtk3 window on its own to show the preview. I will give that a try. BTW, do you have any resources on using gtk3 window directly to render html files outside of a browser? I am trying to run the UI like a kiosk in my use-case & wondering if I can use a lightweight alternative than a full browser.
Title: Re: webcam extension
Post by: Juanito on August 06, 2020, 05:28:35 AM
I made a mistake with the command before, it should have been
Code: [Select]
$ ffplay -f v4l2 -video_size 640x480 -framerate 5 -i /dev/video0
There was a long thread where a user was trying to stream with ffmpeg, but I recall they gave up and used rpi-vc in the end.
Title: Re: webcam extension
Post by: curaga on August 06, 2020, 09:36:45 AM
Using webkit or blink (chrome) directly, instead of via a browser, will not help you much. Same deps, almost the same RAM usage, etc etc. The difference is you don't have menus, bookmarks, and other browser things outside the page.

You can probably build a native app instead of a web page, but it all depends on what you're doing. You've only mentioned you want to show webcam video. A native program is hugely more efficient than a web page in a browser (/engine), no matter what tech you use.
Title: Re: webcam extension
Post by: ashfame on August 06, 2020, 11:51:02 AM
Yeah! I understand native will be much better but web based UI gives me a lot of control over the UX & enables me to do more.

Regarding camera feed, eating up all my memory, its caused by the JS library I use (surprisingly doesn't happen on my desktop), but from my testing I found that if left alone for some time, all that memory is freed by GC so for now, I did a band-aid solution of only showing the webcam for 10secs before it turns the feed off.

I might switch the detection of QR in webcam feed to backend and free that from browser if more problems happen, but I really wanna ship the first iteration of the project (9 days left in 2 months of work)  ::)

I keep on exploring other options as firefox has not been playing nice to me in launching as kiosk mode, in hopes that a particular solution might kill two birds with one stone but that's probably best for a new topic.