From 1d03dac58d3747477e2caf6d661b84dd9e4cdc91 Mon Sep 17 00:00:00 2001 From: mofeng-git Date: Tue, 30 Jan 2024 12:40:53 +0000 Subject: [PATCH] fix sh --- patch/stream.sh | 6 +- patch/stream_when_ustream_exists.sh | 86 ++++++++++++++--------------- 2 files changed, 46 insertions(+), 46 deletions(-) diff --git a/patch/stream.sh b/patch/stream.sh index d48222ca..c0dfb00c 100644 --- a/patch/stream.sh +++ b/patch/stream.sh @@ -1,3 +1,3 @@ -#!/bin/bash - -/usr/bin/ustreamer-dump --sink kvmd::ustreamer::jpeg --output - | /usr/bin/ffmpeg -re -use_wallclock_as_timestamps 1 -i pipe: -rtbufsize 10M -c:v libx264 -pix_fmt yuv420p -preset:v ultrafast -tune:v zerolatency -profile:v baseline -bf 0 -b:v 3M -maxrate:v 5M -r 30 -g 30 -an -f rtp rtp://127.0.0.1:5004 +#!/bin/bash + +/usr/bin/ustreamer-dump --sink kvmd::ustreamer::jpeg --output - | /usr/bin/ffmpeg -re -use_wallclock_as_timestamps 1 -i pipe: -rtbufsize 10M -c:v libx264 -pix_fmt yuv420p -preset:v ultrafast -tune:v zerolatency -profile:v baseline -bf 0 -b:v 3M -maxrate:v 5M -r 30 -g 30 -an -f rtp rtp://127.0.0.1:5004 diff --git a/patch/stream_when_ustream_exists.sh b/patch/stream_when_ustream_exists.sh index 0de77eed..1528eab8 100644 --- a/patch/stream_when_ustream_exists.sh +++ b/patch/stream_when_ustream_exists.sh @@ -1,43 +1,43 @@ -#!/bin/bash - -# 存储 stream.sh 的进程 ID -b_pid="" - - -cleanup() { - echo "Received SIGINT. Terminating the process group..." - [ -n "$b_pid" ] && pkill -9 -g $b_pid # 终止整个进程组 - exit 0 -} - -# 捕获 SIGINT 信号 -trap cleanup SIGINT - - -while true; do - # 检测是否有包含 "ustreamer" 的进程 - if pgrep -f "/usr/bin/ustreamer " > /dev/null; then - # 如果存在,但是 stream.sh 进程不存在,执行 stream.sh 并记录其进程 ID - if [ -z "$b_pid" ]; then - echo "Found a process with 'ustreamer' in the command. Executing stream.sh in the background..." - setsid /usr/share/kvmd/stream.sh & - b_pid=$(ps -o pgid= $!) - echo "stream.sh started with PID: $b_pid" - else - echo "Process with 'ustreamer' is already running. Skipping..." - fi - else - # 如果不存在 "ustreamer" 进程,但是 stream.sh 进程存在,终止 stream.sh 并清除进程 ID - if [ -n "$b_pid" ]; then - echo "No process with 'ustreamer' found. Terminating stream.sh (PID: $b_pid)..." - pkill -9 -g $b_pid - b_pid="" - else - echo "No process with 'ustreamer' found. Waiting for the next check..." - fi - fi - - # 等待一段时间,可以根据需要调整等待的时间间隔 - sleep 1 - -done +#!/bin/bash + +# 存储 stream.sh 的进程 ID +b_pid="" + + +cleanup() { + echo "Received SIGINT. Terminating the process group..." + [ -n "$b_pid" ] && pkill -9 -g $b_pid # 终止整个进程组 + exit 0 +} + +# 捕获 SIGINT 信号 +trap cleanup SIGINT + + +while true; do + # 检测是否有包含 "ustreamer" 的进程 + if pgrep -f "/usr/bin/ustreamer " > /dev/null; then + # 如果存在,但是 stream.sh 进程不存在,执行 stream.sh 并记录其进程 ID + if [ -z "$b_pid" ]; then + echo "Found a process with 'ustreamer' in the command. Executing stream.sh in the background..." + setsid /usr/share/kvmd/stream.sh & + b_pid=$(ps -o pgid= $!) + echo "stream.sh started with PID: $b_pid" + else + echo "Process with 'ustreamer' is already running. Skipping..." + fi + else + # 如果不存在 "ustreamer" 进程,但是 stream.sh 进程存在,终止 stream.sh 并清除进程 ID + if [ -n "$b_pid" ]; then + echo "No process with 'ustreamer' found. Terminating stream.sh (PID: $b_pid)..." + pkill -9 -g $b_pid + b_pid="" + else + echo "No process with 'ustreamer' found. Waiting for the next check..." + fi + fi + + # 等待一段时间,可以根据需要调整等待的时间间隔 + sleep 1 + +done