Skip to content

Commit

Permalink
Merge pull request #784 from chudsaviet/feature/hls-v4l2m2m
Browse files Browse the repository at this point in the history
HLS V4L2 M2M encoder
  • Loading branch information
guysoft authored Jul 11, 2022
2 parents 6cb38c2 + c8045f4 commit 9c07cd0
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ ExecStartPre=/bin/chown -R webcam:webcam /run/webcam
ExecStartPre=/bin/chmod -R 0755 /run/webcam

ExecStart=/usr/bin/sudo -u webcam \
/usr/bin/ffmpeg \
/opt/ffmpeg-hls/ffmpeg \
\
-framerate 30 -video_size 640x480 \
-i /dev/video0 \
Expand All @@ -28,7 +28,7 @@ ExecStart=/usr/bin/sudo -u webcam \
-f image2 -r 1 -update 1 -atomic_writing 1 \
/run/webcam/jpeg/frame.jpg \
\
-c:v h264_omx -profile:v high \
-c:v h264_v4l2m2m -level:v 4.0 \
-b:v 1264k -flags +cgop \
-g 30 -keyint_min 30 \
\
Expand All @@ -40,7 +40,7 @@ ExecStart=/usr/bin/sudo -u webcam \
\
-vf scale=-1:240 \
\
-c:v h264_omx -profile:v high \
-c:v h264_v4l2m2m -level:v 4.0 \
-b:v 240k -flags +cgop \
-g 30 -keyint_min 30 \
\
Expand Down
41 changes: 32 additions & 9 deletions src/modules/octopi/start_chroot_script
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,16 @@ export LC_ALL=C

source /common.sh

if [ -n "$OCTOPI_APTMIRROR" ];
if [ -n "$OCTOPI_APTMIRROR" ];
then
echo "Switching apt mirror in /etc/apt/sources.list to $OCTOPI_APTMIRROR"
cp /etc/apt/sources.list /etc/apt/sources.list.backup
sed -i "s@http://raspbian.raspberrypi.org/raspbian/@$OCTOPI_APTMIRROR@g" /etc/apt/sources.list
fi

WEBCAM_USER=webcam
FFMPEG_HLS_COMMIT=c6fdbe26ef30fff817581e5ed6e078d96111248a
FFMPEG_HLS_DIR=/opt/ffmpeg-hls

### Script ####

Expand Down Expand Up @@ -66,7 +68,7 @@ pushd /home/"${BASE_USER}"
apt-get -y --force-yes install libjpeg8-dev
fi
fi

apt-get -y --force-yes --no-install-recommends install imagemagick ffmpeg libv4l-dev

wget $OCTOPI_MJPGSTREAMER_ARCHIVE -O mjpg-streamer.zip
Expand Down Expand Up @@ -120,11 +122,32 @@ EOT
# FFMPEG HLS
if [ "$OCTOPI_INCLUDE_FFMPEG_HLS" == "yes" ]
then
apt-get install -y --force-yes --no-install-recommends ffmpeg nginx
apt-get install -y --force-yes --no-install-recommends nginx

FFMPEG_BUILD_DIR=$(mktemp -d)
pushd ${FFMPEG_BUILD_DIR}
FFMPEG_ARCHIVE=ffmpeg.tar.gz
wget https://api.github.com/repos/FFmpeg/FFmpeg/tarball/${FFMPEG_COMMIT} -O ${FFMPEG_ARCHIVE}
tar xvzf ${FFMPEG_ARCHIVE}
cd FFmpeg*
./configure \
--disable-doc \
--disable-htmlpages \
--disable-manpages \
--disable-podpages \
--disable-txtpages \
--disable-ffplay \
--disable-ffprobe
make -j$(nproc)
mkdir -p ${FFMPEG_HLS_DIR}
cp ffmpeg ${FFMPEG_HLS_DIR}
popd
rm -r ${FFMPEG_BUILD_DIR}

useradd ${WEBCAM_USER}
usermod -aG video ${WEBCAM_USER}
fi

#CuraEngine
if [ "$OCTOPI_INCLUDE_CURAENGINE" == "yes" ]
then
Expand All @@ -151,7 +174,7 @@ EOT

# fetch current yq build and install to /usr/local/bin
wget -O yq $OCTOPI_YQ_DOWNLOAD && chmod +x yq && mv yq /usr/local/bin

popd

#Make sure user pi / ${BASE_USER} has access to serial ports
Expand Down Expand Up @@ -197,13 +220,13 @@ do
done
for ip in $(hostname -I);
do
do
echo " http://$ip"
done
echo
echo "https is also available, with a self-signed certificate."
echo
echo
echo "------------------------------------------------------------"
echo
EOT
Expand Down Expand Up @@ -276,7 +299,7 @@ systemctl_if_exists enable streamer_select.service
if [ "$OCTOPI_INCLUDE_MJPGSTREAMER" == "yes" ]
then
systemctl_if_exists enable webcamd.service
### use legacy camera stack on bullseye for now
### use legacy camera stack on bullseye for now
if grep "camera_auto_detect=1" /boot/config.txt
then
sed -i "s/camera_auto_detect=1/camera_auto_detect=0/g" /boot/config.txt
Expand Down Expand Up @@ -304,7 +327,7 @@ apt-get -y install avrdude
apt-get clean
apt-get autoremove -y

if [ -n "$OCTOPI_APTMIRROR" ];
if [ -n "$OCTOPI_APTMIRROR" ];
then
echo "Reverting /etc/apt/sources.list"
mv /etc/apt/sources.list.backup /etc/apt/sources.list
Expand Down

0 comments on commit 9c07cd0

Please sign in to comment.