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