Something I noticed is that you’re building a Stretch image.
In the Picamera2 repo, they say “Picamera2 is only supported on Raspberry Pi OS Bullseye (or later) images, both 32 and 64-bit.”
Maybe changing your image to target a newer OS will help?
Also out of curiosity: why are you installing the module with python directly, instead of using pip?
In your Dockerfile.template, can you try changing FROM balenalib/%%BALENA_MACHINE_NAME%%-python:3-stretch-run
to FROM balenalib/%%BALENA_MACHINE_NAME%%-python:3-bullseye-run
It might also be an idea to first try the version of Picamera2 that’s included in the apt repos, instead of the GitHub version:
Instead of
# Clone and install picamera2 from GitHub
RUN git clone https://github.com/raspberrypi/picamera2.git /usr/src/picamera2 \
&& cd /usr/src/picamera2 \
&& python3 setup.py install
try
# Install picamera2 from apt
RUN install_packages python3-picamera2
Just revamped the entire code using AI and it works however the camera preview isn’t it just shows the picture icon. Their is no camera issues in the log which i find a bit confusing!
@Jake1 not sure if you tried the balenaCam project before! Actually I don’t have the pi camera module 3 but maybe you can give a try as you can do a live stream from it as well!
[balena-cam] W: The repository 'http://security.debian.org/debian-security stretch/updates Release' does not have a Release file.
[balena-cam] W: The repository 'http://deb.debian.org/debian stretch Release' does not have a Release file.
[balena-cam] W: The repository 'http://deb.debian.org/debian stretch-updates Release' does not have a Release file.
[balena-cam] W: The repository 'http://archive.raspbian.org/raspbian stretch Release' does not have a Release file.
[balena-cam] E: Failed to fetch http://security.debian.org/debian-security/dists/stretch/updates/main/binary-armhf/Packages 404 Not Found
[balena-cam] E: Failed to fetch http://deb.debian.org/debian/dists/stretch/main/binary-armhf/Packages 404 Not Found
[balena-cam] E: Failed to fetch http://deb.debian.org/debian/dists/stretch-updates/main/binary-armhf/Packages 404 Not Found
[balena-cam] E: Failed to fetch http://archive.raspbian.org/raspbian/dists/stretch/main/binary-armhf/Packages 404 Not Found
[balena-cam] E: Some index files failed to download. They have been ignored, or old ones used instead.
[balena-cam]
[balena-cam] Removing intermediate container 4a0aa83df3ab
[balena-cam] The command '/bin/sh -c apt-get update && apt-get install -yq python3 python3-dev python3-pip python3-setuptools gstreamer-1.0 v4l-utils libopus-dev libvpx-dev libsrtp2-dev libopencv-dev libatlas3-base libatlas-base-dev libjasper-dev libilmbase12 libopenexr22 libavformat-dev libswscale-dev libqtgui4 libqt4-test libavdevice-dev libavfilter-dev libavcodec-dev && apt-get clean && rm -rf /var/lib/apt/lists/*' returned a non-zero code: 100
your problem here is that you’re still trying to use Stretch.
That release is old enough that it was removed from the Debian and Raspbian main repositories.
If you REALLY want to use Stretch, you can try fixing the repository list by adding archive.debian.org and/or legacy.raspbian.org.
To do this, edit your Dockerfile.template, and add this right after the FROM balenalib/%%BALENA_MACHINE_NAME%%-python:3-stretch-run line:
RUN sed -ri 's_http[s]?://(deb|security)\.debian_https://archive\.debian_g' /etc/apt/sources.list
RUN sed -ri 's_http[s]?://(deb|archive|security)\.raspbian_https://legacy\.raspbian_g' /etc/apt/sources.list
I don’t have a camera either, so I can’t help fully debug it; but this should at least help move things forward a bit .
It sounds like your output doesn’t quite match your Dockerfile.template ?
I found two little bugs in my last suggestion.
It seems the old apt doesn’t have https transport enabled; changing the new URLs to http should help.
Also stretch-updates was removed / replaced with stretch/updates; disabling that repo seems to work.
With the new modifications, your Dockerfile.template should look like:
FROM balenalib/%%BALENA_MACHINE_NAME%%-debian:stretch-20190612
# Change apt repositories to archive.debian.org and legacy.raspbian.org; disable stretch-updates
RUN sed -ri 's_http[s]?://(deb|security)\.debian_http://archive\.debian_g' /etc/apt/sources.list
RUN sed -ri 's_^(.*)(debian.org)(.*)(stretch-updates)(.*)$_# \0_g' /etc/apt/sources.list
RUN sed -ri 's_http[s]?://(deb|archive|security)\.raspbian_http://legacy\.raspbian_g' /etc/apt/sources.list
# Install dependencies
RUN apt-get update && \
apt-get install -yq \
python3 \
python3-dev \
python3-pip \
python3-setuptools \
gstreamer-1.0 \
v4l-utils \
libopus-dev \
libvpx-dev \
libsrtp2-dev \
libopencv-dev \
libatlas3-base \
libatlas-base-dev \
libjasper-dev \
libilmbase12 \
libopenexr22 \
libavformat-dev \
libswscale-dev \
libqtgui4 \
libqt4-test \
libavdevice-dev \
libavfilter-dev \
libavcodec-dev \
&& apt-get clean && rm -rf /var/lib/apt/lists/*
# Enable the v4l2 driver for the Raspberry Pi camera
#RUN printf "bcm2835-v4l2\n" >> /etc/modules
RUN pip3 install --upgrade pip
RUN pip3 install async-timeout av==6.1.0
RUN pip3 install pyee==8.2.2 aiohttp aiohttp_basicauth==0.1.3 aioice==0.6.10 aiortc==0.9.11 numpy==1.15.4 opencv-python==3.4.4.19 --index-url https://www.piwheels.org/simple
WORKDIR /usr/src/app
COPY ./app/ /usr/src/app/
CMD ["python3", "/usr/src/app/server.py"]
Note: I only tried building it locally with balena build -d raspberrypi3 -A armv7hf --emulated
With a little bit of luck, I should have some time later this week to see if I can get a bullseye build.
I did some testing, using your repo (Rail-Vista-Balena) as a basis.
I ran into some issues with the Bullseye build (something weird with pip), so I went straight on to Bookworm.
The following seems to get to the point where it gives an IndexOutOfBounds when trying to initialize the camera in the application:
FROM balenalib/%%BALENA_MACHINE_NAME%%-python:3-bookworm-run
# Install system packages required for compiling native extensions
RUN install_packages \
build-essential \
libjpeg-dev \
git \
libatlas-base-dev \
python3-dev \
python3-pip
# Upgrade pip, setuptools, and wheel to ensure we have the latest versions
RUN python3 -m pip install --upgrade pip setuptools wheel
RUN install_packages python3-libcamera python3-picamera2
# Now proceed to install Python dependencies from requirements.txt
COPY requirements.txt /usr/src/app/
RUN pip install --no-cache-dir -r /usr/src/app/requirements.txt
# Copy the rest of your application
COPY . /usr/src/app/
# Enable udevd so that plugged dynamic hardware devices show up in our container
ENV UDEV=1
# Set the working directory
WORKDIR /usr/src/app
# Expose the port for streaming
EXPOSE 8000
# CMD to run your Python application
CMD ["python3", "-u", "src/app.py"]
I think it’s probably a good idea to start with this setup and see what does and doesn’t work regarding the camera.
Once that’s up and running, you can see which versions of the other python libraries (aiohttp etc) you need for your application.
I have also modified the Dockerfile.template from balena-cam; in that one I tried to move as much as possible to the Debian system packages; but couldn’t find a substitute for one library (aiohttp_basicauth), so ended up creating a virtual environment for pip to use.
FROM balenalib/%%BALENA_MACHINE_NAME%%-debian:bookworm
# Install base python packages
RUN install_packages \
python3 \
python3-dev \
python3-pip \
python3-setuptools \
python3-venv
# Install dependencies
RUN install_packages \
python3-aiohttp \
python3-aioice \
python3-aiortc \
python3-async-timeout \
python3-av \
python3-libcamera \
python3-numpy \
python3-opencv \
python3-picamera2 \
python3-pyee
# Install drivers / libs
RUN install_packages \
gstreamer-1.0 \
v4l-utils \
libopus-dev \
libvpx-dev \
libsrtp2-dev \
libopencv-dev \
libatlas3-base \
libatlas-base-dev \
libavformat-dev \
libswscale-dev \
libavdevice-dev \
libavfilter-dev \
libavcodec-dev
# Add build system for new libraries
RUN install_packages build-essential gcc cmake
# Create and use virtual environment
ENV VIRTUAL_ENV=/opt/venv
RUN python3 -m venv $VIRTUAL_ENV --system-site-packages
ENV PATH="$VIRTUAL_ENV/bin:$PATH"
# Add libraries that don't have system packages
RUN pip install aiohttp_basicauth
# Setup our application
WORKDIR /usr/src/app
COPY ./app/ /usr/src/app/
CMD ["python3", "/usr/src/app/server.py"]