Skip to content

Commit c8045f4

Browse files
committed
Building FFmpeg from source for HLS. Using V4L2 M2M encoder.
1 parent 6cb38c2 commit c8045f4

File tree

2 files changed

+35
-12
lines changed

2 files changed

+35
-12
lines changed

src/modules/octopi/filesystem/root/etc/systemd/system/ffmpeg_hls.service

+3-3
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ ExecStartPre=/bin/chown -R webcam:webcam /run/webcam
1818
ExecStartPre=/bin/chmod -R 0755 /run/webcam
1919

2020
ExecStart=/usr/bin/sudo -u webcam \
21-
/usr/bin/ffmpeg \
21+
/opt/ffmpeg-hls/ffmpeg \
2222
\
2323
-framerate 30 -video_size 640x480 \
2424
-i /dev/video0 \
@@ -28,7 +28,7 @@ ExecStart=/usr/bin/sudo -u webcam \
2828
-f image2 -r 1 -update 1 -atomic_writing 1 \
2929
/run/webcam/jpeg/frame.jpg \
3030
\
31-
-c:v h264_omx -profile:v high \
31+
-c:v h264_v4l2m2m -level:v 4.0 \
3232
-b:v 1264k -flags +cgop \
3333
-g 30 -keyint_min 30 \
3434
\
@@ -40,7 +40,7 @@ ExecStart=/usr/bin/sudo -u webcam \
4040
\
4141
-vf scale=-1:240 \
4242
\
43-
-c:v h264_omx -profile:v high \
43+
-c:v h264_v4l2m2m -level:v 4.0 \
4444
-b:v 240k -flags +cgop \
4545
-g 30 -keyint_min 30 \
4646
\

src/modules/octopi/start_chroot_script

+32-9
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,16 @@ export LC_ALL=C
1111

1212
source /common.sh
1313

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

2121
WEBCAM_USER=webcam
22+
FFMPEG_HLS_COMMIT=c6fdbe26ef30fff817581e5ed6e078d96111248a
23+
FFMPEG_HLS_DIR=/opt/ffmpeg-hls
2224

2325
### Script ####
2426

@@ -66,7 +68,7 @@ pushd /home/"${BASE_USER}"
6668
apt-get -y --force-yes install libjpeg8-dev
6769
fi
6870
fi
69-
71+
7072
apt-get -y --force-yes --no-install-recommends install imagemagick ffmpeg libv4l-dev
7173

7274
wget $OCTOPI_MJPGSTREAMER_ARCHIVE -O mjpg-streamer.zip
@@ -120,11 +122,32 @@ EOT
120122
# FFMPEG HLS
121123
if [ "$OCTOPI_INCLUDE_FFMPEG_HLS" == "yes" ]
122124
then
123-
apt-get install -y --force-yes --no-install-recommends ffmpeg nginx
125+
apt-get install -y --force-yes --no-install-recommends nginx
126+
127+
FFMPEG_BUILD_DIR=$(mktemp -d)
128+
pushd ${FFMPEG_BUILD_DIR}
129+
FFMPEG_ARCHIVE=ffmpeg.tar.gz
130+
wget https://api.github.com/repos/FFmpeg/FFmpeg/tarball/${FFMPEG_COMMIT} -O ${FFMPEG_ARCHIVE}
131+
tar xvzf ${FFMPEG_ARCHIVE}
132+
cd FFmpeg*
133+
./configure \
134+
--disable-doc \
135+
--disable-htmlpages \
136+
--disable-manpages \
137+
--disable-podpages \
138+
--disable-txtpages \
139+
--disable-ffplay \
140+
--disable-ffprobe
141+
make -j$(nproc)
142+
mkdir -p ${FFMPEG_HLS_DIR}
143+
cp ffmpeg ${FFMPEG_HLS_DIR}
144+
popd
145+
rm -r ${FFMPEG_BUILD_DIR}
146+
124147
useradd ${WEBCAM_USER}
125148
usermod -aG video ${WEBCAM_USER}
126149
fi
127-
150+
128151
#CuraEngine
129152
if [ "$OCTOPI_INCLUDE_CURAENGINE" == "yes" ]
130153
then
@@ -151,7 +174,7 @@ EOT
151174

152175
# fetch current yq build and install to /usr/local/bin
153176
wget -O yq $OCTOPI_YQ_DOWNLOAD && chmod +x yq && mv yq /usr/local/bin
154-
177+
155178
popd
156179

157180
#Make sure user pi / ${BASE_USER} has access to serial ports
@@ -197,13 +220,13 @@ do
197220
done
198221
199222
for ip in $(hostname -I);
200-
do
223+
do
201224
echo " http://$ip"
202225
done
203226
204227
echo
205228
echo "https is also available, with a self-signed certificate."
206-
echo
229+
echo
207230
echo "------------------------------------------------------------"
208231
echo
209232
EOT
@@ -276,7 +299,7 @@ systemctl_if_exists enable streamer_select.service
276299
if [ "$OCTOPI_INCLUDE_MJPGSTREAMER" == "yes" ]
277300
then
278301
systemctl_if_exists enable webcamd.service
279-
### use legacy camera stack on bullseye for now
302+
### use legacy camera stack on bullseye for now
280303
if grep "camera_auto_detect=1" /boot/config.txt
281304
then
282305
sed -i "s/camera_auto_detect=1/camera_auto_detect=0/g" /boot/config.txt
@@ -304,7 +327,7 @@ apt-get -y install avrdude
304327
apt-get clean
305328
apt-get autoremove -y
306329

307-
if [ -n "$OCTOPI_APTMIRROR" ];
330+
if [ -n "$OCTOPI_APTMIRROR" ];
308331
then
309332
echo "Reverting /etc/apt/sources.list"
310333
mv /etc/apt/sources.list.backup /etc/apt/sources.list

0 commit comments

Comments
 (0)