クリーンインストールが楽 (Raspberry Pi OS Bookworm UG)

Raspberry Pi 3 (Raspberry Pi OS Bullseye)でRTSPを見るのはffplayが楽だと記事を書いた翌日に,Raspberry Pi OS Bookwormがリリースされました.Debian Bookwormは随分前にリリースされ,Raspberry Pi OS Bookwormも近々リリースされると聞いてはいましたが,翌日とはなんというめぐり合わせでしょう.

それで,早速Raspberry Pi 3 Model Bと同Model B+にインストールしてあるRaspberry Pi OSをBullseyeからBookwormにupgradeしてみましたが,結構手間と時間がかかるうえ,ちょっとしたトラブルにも巻き込まれてしまいました.

もし,Raspberry PiをRTSPを見るなど単機能のみに使用するのでしたら,クリーンインストールのほうがずっと楽だし時間もかかかりませんし,トラブルも起きにくいです.

Upgradeしてだめならクリーンインストールという方が時間を潰すには適していますが😅

ところで,Raspberry Pi OS Bookwormもデフォルトのインストールでは,swapにファイルを使うdphys-swapfileでした.SDカードをswapに使うのは全くメリットがないので,デフォルトでZRAMを採用してほしかったですが,まあたぶん開発元ではいろんな議論があったのでょう.

書き込みが遅いし書き込みを繰り返すと寿命が来る.

How to View RTSP by Raspberry Pi 3 Using ffplay (FFMPEG)

The following article is outdated. For the Raspberry Pi OS only, you can use VLC to watch RTSP as of 3 November 2023.

Original Article follows;

For Raspberry Pis, there are many outdated or sometimes harmful guides to watching video streams (RTSP) generated by webcams. The biggest issue obstructing the approach is that Debian removed RTSP capability from the VLC media player. People who want to simply watch RTSP on the Raspberry Pi are straying.

The goal of this article is to run ffplay on the Raspberry Pi OS automatically.

Disclaimer

The first purpose of this article is to record what I did. However, I am happy if this will be helpful to someone, no matter how much or little. I would like to state this article is based on GPLv3. No warranty at all.

Prior Information

  • The information in this article is tested on Raspberry Pi 3 Model B (RPi3) and Raspberry Pi 3 Model B+ (RPi3+) both of them have 1GB RAM. Raspberry Pi 4 Model B is not tested but may work as well.
  • URL to webcam is in the form of “rtsp://user_id:password@ipaddress/designated_string”
  • Used OS is Raspberry Pi OS bullseye. The next generation, bookworm, will be released soon. This article will or will not be updated after bookworm release.

Raspberry Pi OS installation

Details of the OS installation are omitted in this article because there are many guides, including official and unofficial ones. It is lucky if you find one that suits to you. The installation is not difficult, so you can manage to install it even if the guide you found is not friendly.

The recommendable points are as follows:

  • Install Raspberry Pi OS (64bit) full version, not the LITE version.
  • Enable auto-login (just according to the default).
  • Disable screen blanking.
  • Enable the ssh server (sshd).

The following section assumes the WiFi setup is finished and that all packages have been updated.

Recommended Option: Zram

This is not a must, but I strongly recommend installing ZRAM. Many distros enable ZRAM on their default installation today, but Raspberry Pi OS bullseye doesn’t.

Installation is not difficult. Just install zram-tools with an apt command like,

sudo apt install zram-tools

then swap on the RAM with compression starts functioning. ZRAM has extremely high priority, so the bullseye default, swap-on-file, will never work again. Because the swap file remains just a huge, redundant file, you may want to remove it. It is removed as follows:

sudo systemctl stop dphys-swapfile
sudo systemctl disable dphys-swapfile
sudo rm -v /var/swap

Test ffplay

During the OS installation, you have a mouse, a keyboard, and a monitor connected to the RPi3(+). Keep them connected until the set-up finishes.

The program to view RTSP, ffplay, is included in the FFMPEG package that comes with the Raspberry Pi OS. Open a terminal and execute the next command as a user.

ffplay -fs -loglevel quiet rtsp://user_id:password@ip_address/designated_string

where use_id, password, ip_address, and designated_string are those of the corresponding webcam.

If you get a full-screen video stream, you are one step closer. If you can’t, I can just say “It depends.”

Type “q” to quit the video.

Next, create a shell script file as a user with your favorite editor. You can name it whatever you like. For simplicity, it is named “run_ffplay.sh” here. Inside, it is like,

#!/bin/sh
sleep 20
/usr/bin/ffplay -fs -loglevel quiet rtsp://user_id:password@ip_address/designated_string >/dev/null 2>&1 &

This script sleeps 20 seconds before the execution of ffplay. I don’t know if 20 seconds is optimum. Please trim it if you like.

You can place the script file wherever you want, but your home directory is safe. Then give it execute permission.

chmod a+x run_ffplay.sh

Just run the script to see if you get a full-screen video again.

./run_ffplay.sh

Again, type “q” to quit.

Autostart

You need to create an autostart configuration file in the directory "~/.config/autostart/". By the default of bullseye installation, "~/.config" has been created then you will need,

mkdir ~/.config/autostart

Then create a file named “ffplay.desktop” in the directory with your editor. The contents will like,

[Desktop Entry]
Type=Application
Name=ffplay
Exec=/THE/PATH/TO/run_ffplay.sh

I know I’m being nosy, but /THE/PATH/TO should be the path to run_ffplay.sh. All done; just cross-finger and sudo reboot; exit.

If success, you can remove the mouse and the keyboard.

Shutdown

Unfortunately, there is no smart shutdown method provided without a keyboard and a mouse. Login to the box via ssh from another PC, then execute the command sudo poweroff. Installing an electrical switch on the GPIO and configuring it will be fun. LIRC will be a smarter alternative.

Conclusion

Since Debian removed RTSP capability from the VLC media player, many people are struggling. You can use ffplay of the FFMPEG package as an alternative.

; exit may be redundant.
Or simply poweroff may work.

Raspberry Pi 3 でRTSPを見る(結論)

使い道のないRaspberry Pi 3 Model B (RPi3) やRaspberry Pi 3 Model B+ (RPi3+)で,RTSPを視聴する方法の結論としては,

ffplay (FFMPEG)で見る

で最終決定しました.唯一懸念されていた時間遅れの蓄積は,その後半日ほど連続運転したところ,不思議と解消されました

FFMPEGが使えるならばRaspberry Pi OSでも行けるはずですが,いまさら面倒なので,RPi3ではManjaro ARM xfce, RPi3+ではManjaro ARM KDE Plasmaでこのまま行きます.

自動起動については,

#!/bin/sh
sleep 30
DISPLAY=:0 /usr/bin/ffplay rtsp://ユーザー名:パスワード@ホストのFQDN/指定された文字列 -loglevel quiet -fs > /dev/null 2>&1 &

というスクリプトを実行可能にして適当な場所に置いて設定からAutostartに指定したら,xfceもKDE Plasmaもうまくいきました.sleep 30については要調整です.フルスクリーンオプション-fsはお好みで.

なお,xfceでは設定のScreen saverをOFFが機能しますが,KDE Plasmaはそのスイッチが効かないようなので,ワークアラウンドとして,.xprofile

DISPLAY=:0 xset -dpms
DISPLAY=:0 xset s off

を書いてます.

たぶん,下記のスクリプトのように,コンソールにlogを出さないようにしたためかもしれません.それでも多少は遅れます.
と言いつつ後日試しました.ffplayだけのためにインストールするなら,Raspberry Pi OSが一番楽で,起動も早いのでお勧めです.
一年前にそうだったのですがその後確認はしていません😅

macOSとiPhoneの同期が終わらない

どうもiPhone 14のiOSを17.0.xに上げてからだと思いますが,Mac mini (Intel, macOS 13.6)と同期しようとしても,最後の「項目がコピーされるのを待っています」が終了しません.iOSのほうはとっくに同期の処理が終わっているようで,バッテリーの表示のところをプルダウンしてもぐるぐるは見えませんし,写真アプリでもMac側にしかない写真が送られないままで「同期中」のサインもありません.

ながらくMacとiPhone (iPod touc, iPad)を使ってきて,同期がうまく行かないことはこれまでもありました.非常に不便でなかなかAppleは直してくれませんが,あんまり気にするとストレスになるので気にしないことにします.

追記: 動きました

何回か試したら同期処理が完了しました.しばらく様子見ます.

Manjaro ARMでもVLCでRTSPはNGに

ここだけの話にしておいてください.2023年10月3日(火)現在ですが,Manjaro ARMの配布しているVLC最新版(3.0.18-16)は,RTSPの視聴が可能です.Raspberry Pi 4 Model B (RPi4)で確認しました.

で,めでたしめでたしと行きたかったのですが,他の2台のManjaro ARMを最新版にしたところ,VLCによるRTSPの視聴はできなくなりました.

どうも,視聴できる方がどこかおかしいようです.パッケージ管理のデータベース上は最新版にアップデートされているはずが実際は古いままだとか.

FFMPEGも微妙

かつて,VLCでなくコマンドラインのmplayerPython3のライブラリーを試したことがありましたが,いずれも遅延がどんどん大きくなって,実時間の監視用には使えないことがわかりました.Raspberry Pi 3 Model B (RPi3) とRaspberry Pi 3 Model B+ (RPi3+) でのテストでした.

今回,FFMPEGを試してないことを思い出し同じくRPi3, RPi3+でFFMPEGのコマンドラインプレーヤーffplayを試してみましたが,mplayer, Python3のライブラリーほどではないものの微妙に遅延していきます.

RPi3でffplayを動かしていると,一時間に数十秒遅れて,数時間で数分遅れという状況になります.一時間ごとに再起動すれば良いかもしれませんが,あんまりスマートではありません.

いろいろ試すとVLCがよくできているのが解るばかりで弱ります.

いずれもあくまで当社調べです.

ちなみにCore i7のデスクトップ機ではffplayでも遅延が増大することはありません.