何らかの理由で失敗した場合にffmpegストリームを再起動するために、Restarting ffmpeg process using monitのような類似のソリューションを使用しました。問題/質問が重複していないことを覚えておいてください。例題の質問/回答Restarting ffmpeg process using monitとは違って、私は以下で説明する問題があるので、覚えておいてください。ここで TOTAL CPUが1%未満の場合にmonitを使用してffmpegプロセスを再開
check process FFMPEGStream with pidfile PATH-to-file/streampid.pid
start program = "PATH-to-file/streambash.sh restart"
stop program = "PATH-to-file/streambash.sh stop"
if TOTAL CPU is less than 1% for 10 cycles then restart
は私streambash.shファイルです:
#!/bin/bash
pid_file="PATH-to-file/streampid.pid"
case "$1" in
restart)
PATH-to-file/streambash.sh stop
PATH-to-file/streambash.sh start
;;
start)
rm $pid_file
/usr/bin/ffmpeg -i "INPUT-PATH" -c:v libx264 -b:v 900k -preset ultrafast -aspect 16:9 -s 640x376 -strict experimental -c:a aac -b:a 96k -f flv "RTMP-PATH" &> /dev/null &
ch_pid=$!
echo "Start Stream1: ffmpeg = $ch_pid";
echo $ch_pid > $pid_file
;;
stop)
echo "Stop ffmpeg Stream1";
kill `cat $pid_file` &> /dev/null
;;
*)
echo "Usage: PATH-to-file/streambash.sh {start|stop|restart}"
exit 1
;;
esac
exit 0
echo $pid_file
MONITが正常にbashのファイルを起動することができますが、この状態「TOTAL CPUの場合は1未満だからここに私のMONIT構成であります10サイクル後に%を再起動し、 "がmonit構成で一致した場合、再起動を試みますが、プロセスが実行されていないというエラーが表示されます。しかし実際にはffmpegプロセスはバックグラウンドで実行されており、ストリームが私のWebサイトに公開されていることがわかります。ここではMONITのログです:
[CET Jan 10 12:55:02] error : 'FFMPEGStream' total cpu usage of 0.4% matches resource limit [cpu usage>1.0%]
[CET Jan 10 12:55:07] error : 'FFMPEGStream' total cpu usage of 0.0% matches resource limit [cpu usage>1.0%]
[CET Jan 10 12:55:12] error : 'FFMPEGStream' total cpu usage of 0.0% matches resource limit [cpu usage>1.0%]
[CET Jan 10 12:55:17] error : 'FFMPEGStream' total cpu usage of 0.4% matches resource limit [cpu usage>1.0%]
[CET Jan 10 12:55:22] error : 'FFMPEGStream' total cpu usage of 0.9% matches resource limit [cpu usage>1.0%]
[CET Jan 10 12:55:27] error : 'FFMPEGStream' total cpu usage of 0.9% matches resource limit [cpu usage>1.0%]
[CET Jan 10 12:55:32] error : 'FFMPEGStream' total cpu usage of 0.0% matches resource limit [cpu usage>1.0%]
[CET Jan 10 12:55:37] error : 'FFMPEGStream' total cpu usage of 0.0% matches resource limit [cpu usage>1.0%]
[CET Jan 10 12:55:42] error : 'FFMPEGStream' total cpu usage of 0.0% matches resource limit [cpu usage>1.0%]
[CET Jan 10 12:55:47] error : 'FFMPEGStream' total cpu usage of 0.4% matches resource limit [cpu usage>1.0%]
[CET Jan 10 12:55:50] info : 'FFMPEGStream' trying to restart
[CET Jan 10 12:55:50] info : 'FFMPEGStream' stop: PATH-to-file/streambash.sh
[CET Jan 10 12:55:51] info : 'FFMPEGStream' start: PATH-to-file/streambash.sh
[CET Jan 10 12:55:56] error : 'FFMPEGStream' process is not running
[CET Jan 10 12:55:58] info : 'FFMPEGStream' trying to restart
[CET Jan 10 12:55:58] info : 'FFMPEGStream' start: PATH-to-file/streambash.sh
[CET Jan 10 12:56:04] error : 'FFMPEGStream' process is not running
[CET Jan 10 12:56:04] info : 'FFMPEGStream' trying to restart
[CET Jan 10 12:56:04] info : 'FFMPEGStream' start: PATH-to-file/streambash.sh
[CET Jan 10 12:56:09] error : 'FFMPEGStream' process is not running
[CET Jan 10 12:56:09] info : 'FFMPEGStream' trying to restart
[CET Jan 10 12:56:09] info : 'FFMPEGStream' start: PATH-to-file/streambash.sh
MONITリトライ処理を再開しようとすると、それぞれの上に、それがPATHツーファイル/ streampid.pidに新しいPIDをダンプしますが、私はそれが何らかの形で、それはそう言ったように保持しますバックグラウンドで動作し続けている実際のffmpegストリーム/ pidを停止することができます。
niceまたはcgroupを使用しないのはなぜですか? –
私の問題はCPUの処理ではありません。私の問題は、プロセスが再起動されないか、実行されていない場合にmonitで起動されたと少なくとも表示されないという問題です。 CPU使用量は、プロセスが動作していないか、またはffmpegがエンコードまたは関連する問題であるかどうかを知るために使用した方法です。 niceやcgroupを使うのは意味がありません。 – user2201239