2022年4月2日土曜日

motion いつの間にか落ちてる ffmpeg_put_frame: Error while writing video frame / event_ffmpeg_put: Error encoding image

トリガー条件不明。

motionはカメラから画像が指定したFPS以下の場合、不足したフレームを複製させてパディングするようなパラメータがあるが、実際のところ不足しているフレームは単純に抜け落ちるだけで保管もされない。

そのために落ちているのかもしれないが、よくわからない。

が、実際にこのエラーが表示されている状態でもファイル出力がされていたので、無視していいのかもしれない。

なお、部屋を暗くしたらこれが発生して落ちていた。

状況としては動作検知後、録画し始めて19時17分22秒あと、1分程度経ってからエラーが出始め、落ちていた。 

[1:ml1:F] [NTC] [EVT] [Apr 02 19:17:22] event_newfile: File of type 8 saved to: /tmp/motion/C270_2/20220402191722F-10.mp4
[1:ml1:F] [NTC] [ALL] [Apr 02 19:17:22] create_path: creating directory /tmp/motion/C270_2
[1:ml1:F] [NTC] [EVT] [Apr 02 19:17:22] event_create_extpipe: pipe: ffmpeg
[1:ml1:F] [NTC] [EVT] [Apr 02 19:17:22] event_create_extpipe: cnt->moviefps: 10
[1:ml1:F] [NTC] [EVT] [Apr 02 19:17:22] event_newfile: File of type 8 saved to: /tmp/motion/C270_2/20220402191722F-10
[1:ml1:F] [NTC] [ALL] [Apr 02 19:17:22] motion_detected: Motion detected - starting event 10
[1:ml1:F] [ERR] [ENC] [Apr 02 19:18:52] ffmpeg_put_frame: Error while writing video frame
[1:ml1:F] [ERR] [EVT] [Apr 02 19:18:52] event_ffmpeg_put: Error encoding image
[1:ml1:F] [ERR] [ENC] [Apr 02 19:18:52] ffmpeg_put_frame: Error while writing video frame
[1:ml1:F] [ERR] [EVT] [Apr 02 19:18:52] event_ffmpeg_put: Error encoding image
[1:ml1:F] [ERR] [ENC] [Apr 02 19:18:52] ffmpeg_put_frame: Error while writing video frame

[1:ml1:F] [ERR] [ENC] [Apr 02 19:20:02] ffmpeg_put_frame: Error while writing video frame
[1:ml1:F] [ERR] [EVT] [Apr 02 19:20:02] event_ffmpeg_put: Error encoding image
[1:ml1:F] [NTC] [ALL] [Apr 02 19:20:22] preview_save: different filename or picture only!

ログの抜粋はこんな感じ

作られたファイルとログは矛盾点はなかった。

もしかすると、pipeで渡しているフォーマットがまずいのかもしれないが、出力され始めるタイミングがずれているのと、フレームレートは10FPSと低めにしているのでそれなりなはずなのだが…

motion ファイル名の拡張子

use_extpipe on

でpipeで外部エンコーダを利用するとon_movie_endイベントでファイル名をパラメータとして渡したときに、拡張子がついていたりついてなかったりする。

トリガー条件が不明。

ログ(/var/log/motion/motion.log)を見てみると event_newfile: でファイル名が出力されているので見てみると、extpipeを使い始めたタイミングで2回ファイル名が出力されているように見える。extpipeがonでも拡張子があったりなかったりする。

問題がなさそうな時

[1:ml1:F] [NTC] [EVT] [Apr 01 19:58:26] event_newfile: File of type 8 saved to: /tmp/motion/C270/20220401195826F-01.mp4
[1:ml1:F] [NTC] [EVT] [Apr 01 19:59:08] event_newfile: File of type 1 saved to: /tmp/motion/C270/20220401195829F-01-05.jpg
[1:ml1:F] [NTC] [EVT] [Apr 01 20:02:28] event_newfile: File of type 8 saved to: /tmp/motion/C270/20220401200228F-02.mp4
[1:ml1:F] [NTC] [EVT] [Apr 01 20:02:58] event_newfile: File of type 1 saved to: /tmp/motion/C270/20220401200228F-02-04.jpg
[1:ml1:F] [NTC] [EVT] [Apr 01 20:11:02] event_newfile: File of type 8 saved to: /tmp/motion/C270/20220401201102F-03.mp4
[1:ml1:F] [NTC] [EVT] [Apr 01 20:14:02] event_newfile: File of type 1 saved to: /tmp/motion/C270/20220401201112F-03-02.jpg
[1:ml1:F] [NTC] [EVT] [Apr 01 20:14:26] event_newfile: File of type 8 saved to: /tmp/motion/C270/20220401201425F-04.mp4
[1:ml1:F] [NTC] [EVT] [Apr 01 20:15:06] event_newfile: File of type 1 saved to: /tmp/motion/C270/20220401201426F-04-02.jpg
[1:ml1:F] [NTC] [EVT] [Apr 01 20:15:28] event_newfile: File of type 8 saved to: /tmp/motion/C270/20220401201528F-05.mp4
[1:ml1:F] [NTC] [EVT] [Apr 01 20:16:54] event_newfile: File of type 1 saved to: /tmp/motion/C270/20220401201531F-05-01.jpg
[1:ml1:F] [NTC] [EVT] [Apr 01 20:16:56] event_newfile: File of type 8 saved to: /tmp/motion/C270/20220401201656F-06.mp4
[1:ml1:F] [NTC] [EVT] [Apr 01 20:17:57] event_newfile: File of type 1 saved to: /tmp/motion/C270/20220401201712F-06-07.jpg
[1:ml1:F] [NTC] [EVT] [Apr 01 20:21:46] event_newfile: File of type 8 saved to: /tmp/motion/C270/20220401202145F-07.mp4

問題が発生している前後では拡張子がないファイルが作成されている感じになっている。

[1:ml1:F] [NTC] [EVT] [Apr 01 22:26:47] event_newfile: File of type 8 saved to: /tmp/motion/C270/20220401222647F-02
[1:ml1:F] [NTC] [EVT] [Apr 01 22:27:31] event_newfile: File of type 1 saved to: /tmp/motion/C270/20220401222649F-02-05.jpg
[1:ml1:F] [NTC] [EVT] [Apr 01 22:38:21] event_newfile: File of type 8 saved to: /tmp/motion/C270/20220401223821F-01.mp4
[1:ml1:F] [NTC] [EVT] [Apr 01 22:38:21] event_newfile: File of type 8 saved to: /tmp/motion/C270/20220401223821F-01
[1:ml1:F] [NTC] [EVT] [Apr 01 22:38:58] event_newfile: File of type 1 saved to: /tmp/motion/C270/20220401223822F-01-07.jpg
[1:ml1:F] [NTC] [EVT] [Apr 01 22:42:45] event_newfile: File of type 8 saved to: /tmp/motion/C270/20220401224245F-02.mp4
[1:ml1:F] [NTC] [EVT] [Apr 01 22:42:45] event_newfile: File of type 8 saved to: /tmp/motion/C270/20220401224245F-02
[1:ml1:F] [NTC] [EVT] [Apr 01 22:45:45] event_newfile: File of type 1 saved to: /tmp/motion/C270/20220401224251F-02-05.jpg
[1:ml1:F] [NTC] [EVT] [Apr 01 22:45:45] event_newfile: File of type 8 saved to: /tmp/motion/C270/20220401224545F-03.mp4
[1:ml1:F] [NTC] [EVT] [Apr 01 22:45:45] event_newfile: File of type 8 saved to: /tmp/motion/C270/20220401224545F-03
[1:ml1:F] [NTC] [EVT] [Apr 01 22:47:29] event_newfile: File of type 1 saved to: /tmp/motion/C270/20220401224646F-03-02.jpg
[1:ml1:F] [NTC] [EVT] [Apr 01 22:47:30] event_newfile: File of type 8 saved to: /tmp/motion/C270/20220401224730F-04.mp4
[1:ml1:F] [NTC] [EVT] [Apr 01 22:47:30] event_newfile: File of type 8 saved to: /tmp/motion/C270/20220401224730F-04
 

動作させてるバージョン。

pi@rasp3b:~ $ motion -help
motion Version 4.1.1, Copyright 2000-2017 Jeroen Vreeken/Folkert van Heusden/Kenneth Lavrsen/Motion-Project maintainers
 

解決策としてはイベント中の処理スクリプトで拡張子を付加して対応したが、少々気持ち悪い動作というか多分バグ。仕様としては拡張パイプを使用した場合の拡張子がついてしまっているのがおかしいかな。

bash 文字列 ファイルの拡張子の扱い

pi@rasp3b:~ $ FILENAME=ABCDEF.GHI
pi@rasp3b:~ $ echo ${FILENAME##*.}
GHI
pi@rasp3b:~ $ FILENAME=ABCDEF.
pi@rasp3b:~ $ echo ${FILENAME##*.}

ファイル名に拡張子がない場合は同じ文字列になる。

pi@rasp3b:~ $ FILENAME=ABCDEF
pi@rasp3b:~ $ echo ${FILENAME##*.}
ABCDEF

拡張子しかない場合も同じものとなる。

pi@rasp3b:~ $ FILENAME=.XYZ
pi@rasp3b:~ $ echo ${FILENAME##*.}
XYZ
 

 

2020年7月1日水曜日

cannot VACUUM from within a transaction

センサーログのスクリプトを10分単位で動かしていましたが、試しに1分単位に動かしてみたところ、意外なところで想定外になってしまったようでグラフの表示やら、日時でテンポラリからストレージに移動しているスクリプトが動いてなかったり。
単純にデータ量が1日当たり144件から10倍の1440件になるので、どこかでおかしくなるかとは思っていましたが、それでも想定外でした。

Jul  1 02:03:01 rasp4b4g CRON[9173]: (root) CMD (/usr/local/sbin/savetosd.py)
Jul  1 02:03:01 rasp4b4g CRON[9164]: (CRON) info (No MTA installed, discarding output)

cronのログはsyslogにキックしたログはありましたが、エラーの出力は無い様なので、実際に動かしてみました。(メール設定をしていればエラーがメールで飛んでいく設定を作れるから設定しておいた方が良いかも…)

pi@rasp4b4g:~ $ sudo python3 /usr/local/sbin/savetosd.py
cannot VACUUM from within a transaction

VACUUMでエラーが出ているようです。
ググってみると、トランザクション中にVACUUMを行うとエラーが発生することがあるらしいのでスクリプトを確認してみると…
  1. テーブル間のデータコピー
  2. テンポラリテーブルのデータ削除
  3. VACUUM
  4. commit()
なんで、commitする前にVACUUMさせていたのかは謎ですが、今までVACUUMはトランザクションに影響しないというより、暗礁のcommitが行われてしまうものだとばかり思っていましたが、そうではなくトランザクションとして処理していてバッファが足りなくなったらしっかりエラーを吐き出すようですね。
  1. テーブル間のデータコピー
  2. テンポラリテーブルのデータ削除
  3. commit()
  4. VACUUM
という順序に入れ替えて実行してみると処理が通るようになりました。
グラフの表示が崩れていたのも、正常に戻ったので、グラフ表示させているスクリプトでテンポラリ内のデータが1日以上になってしまうと都合が悪い作りになってるようですね…





関係がありそうなインストール済みのパッケージ
libsqlite3-0:armhf                    3.27.2-3                               armhf        SQLite 3 shared library
php-sqlite3 2:7.3+69 all SQLite3 module for PHP [default]
php7.3-sqlite3 7.3.14-1~deb10u1 armhf SQLite3 module for PHP
libaprutil1-dbd-sqlite3:armhf 1.6.1-4 armhf Apache Portable Runtime Utility Library - SQLite3 Driver
libqt5sql5-sqlite:armhf 5.11.3+dfsg1-1+rpi1+deb10u3 armhf Qt 5 SQLite 3 database driver
スクリプトのpython3上でバージョンの確認
pi@rasp4b4g:~ $ python3
Python 3.7.3 (default, Dec 20 2019, 18:57:59)
[GCC 8.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import sqlite3
>>> sqlite3.sqlite_version
'3.27.2'
>>> exit()

2020年6月24日水曜日

passwd

理想はすべてのアカウントパスワードはある程度の強固なもので、それぞれ違うものをきちんと設定すべきです。

が、

一つ二つならまだしも、手持ちのデバイスが増えるにつれ、正直管理なんてできません。
実際は、使用用途によっていくつか決まったパスワードを使いまわすことが多いいわけですが、Raspberry piにターミナルでログインするたびに、パスワードを設定しろとしつこく表示されるのでパスワードの設定をしようとしてみると、

Bad: new password is too simple

と表示され、変更できず。複雑なパスワードにするべきなのはわかってはいるんですけどね。

何とかしたいので、管理者権限で

$ sudo passwd pi

とすれば、確認のパスワードも必要なく、パスワードチェックもされません。

忘れそうなのでメモメモw

2020年4月26日日曜日

セルの書式:億万の単位表示

日本人だと4桁区切りにすると読みやすいですが、カンマは3桁区切りが一般的。
不用意に4桁区切りにするよりは、どうせならとうまい表示方法はないかと調べてみると、書式設定に「####億####万####」と設定すれば良さそうですが、万単位の時に不要な「億」が表示されてしまうので条件を付けくわえて

[>100000000]####億####万####;[>10000]####万####;####

とすることでそれなりに。

これでも不要そうなゼロが消えないので、そこまでやらせようとすると表示用の別のセルにマクロや数式に頼ることになるかと。

コロナ騒ぎで計算するときに人口ベースの比率を計算するときに、桁が良く分からなくなので表計算上で数字を置いておくのに便利です。

2018年10月9日火曜日

i2cデバイスのアドレス確認

必要なパッケージ
i2c-tools
なければsudo apt-get install i2c-toolsでインストール

コマンド
i2cdetect -y 1

pi@rasp3b:~ $ i2cdetect -y 1
     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
00:          -- -- -- -- -- -- -- -- -- -- -- -- --
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 3f
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
70: -- -- -- -- -- -- 76 77

i2cに接続されているアドレスが表示されるので、接続前と後で見比べればどのアドレスに接続されたかわかる。

参考というか元ネタ
http://robocad.blog.jp/archives/729192.html