Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 55 additions & 19 deletions installer/sc.sh
Original file line number Diff line number Diff line change
Expand Up @@ -1383,29 +1383,20 @@ check_audio_encoder() {
fi
}

log_message "Starting HLS recording with audio support and 60-minute playlist rotation"

# Check for audio encoder availability
check_audio_encoder
AUDIO_AVAILABLE=\$?

# Main recording loop - runs indefinitely
while true; do
# Generate timestamp for this hour's recording
TIMESTAMP=\$(date +%Y%m%d_%H%M%S)
# Function to run GStreamer with logging
run_gstreamer_with_logging() {
local timestamp=\$1
local audio_available=\$2

log_message "Creating new playlist: \${TIMESTAMP}_playlist.m3u8"

if [ \$AUDIO_AVAILABLE -eq 0 ]; then
if [ \$audio_available -eq 0 ]; then
log_message "Recording with audio from UDP stream (port 5011)"
# Enhanced pipeline with audio support (video + UDP audio stream)
# Try hardware encoding first, fallback to software if it fails
timeout 3630 gst-launch-1.0 -e \\
mpegtsmux name=mux ! \\
hlssink playlist-root=file://\$OUTPUT_DIR \\
target-duration=60 playlist-length=60 max-files=0 \\
playlist-location="\$OUTPUT_DIR/\${TIMESTAMP}_playlist.m3u8" \\
location="\$OUTPUT_DIR/\${TIMESTAMP}_segment_%05d.ts" \\
playlist-location="\$OUTPUT_DIR/\${timestamp}_playlist.m3u8" \\
location="\$OUTPUT_DIR/\${timestamp}_segment_%05d.ts" \\
rtspsrc location=rtsp://${TARGET_IP}:8554/main.264 latency=50 drop-on-latency=true ! \\
rtph264depay ! h264parse ! \\
avdec_h264 ! videoconvert ! \\
Expand All @@ -1418,7 +1409,7 @@ while true; do
audioconvert ! audioresample ! \\
audio/x-raw,rate=48000,channels=2 ! \\
queue max-size-buffers=200 max-size-time=2000000000 ! \\
avenc_aac bitrate=128000 ! aacparse ! mux.
avenc_aac bitrate=128000 ! aacparse ! mux. &
else
log_message "Recording video only (no audio device available)"
# Video-only pipeline using software encoding
Expand All @@ -1434,10 +1425,55 @@ while true; do
target-duration=60 \\
playlist-length=60 \\
max-files=0 \\
playlist-location="\$OUTPUT_DIR/\${TIMESTAMP}_playlist.m3u8" \\
location="\$OUTPUT_DIR/\${TIMESTAMP}_segment_%05d.ts"
playlist-location="\$OUTPUT_DIR/\${timestamp}_playlist.m3u8" \\
location="\$OUTPUT_DIR/\${timestamp}_segment_%05d.ts" &
fi

local gst_pid=\$!

# Keep track of logged files to avoid duplicates
local logged_files_list="/tmp/logged_segments_\${timestamp}.txt"
touch "\$logged_files_list"

# Monitor for new .ts files while GStreamer is running
while kill -0 \$gst_pid 2>/dev/null; do
# Find all current .ts files for this timestamp
for ts_file in "\$OUTPUT_DIR"/\${timestamp}_segment_*.ts; do
if [ -f "\$ts_file" ]; then
local filename=\$(basename "\$ts_file")
# Check if we've already logged this file
if ! grep -q "^\$filename\$" "\$logged_files_list" 2>/dev/null; then
log_message "Created segment file: \$filename"
echo "\$filename" >> "\$logged_files_list"
fi
fi
done
sleep 2
done

# Clean up the temporary file
rm -f "\$logged_files_list"

wait \$gst_pid
return \$?
}

log_message "Starting HLS recording with audio support and 60-minute playlist rotation"

# Check for audio encoder availability
check_audio_encoder
AUDIO_AVAILABLE=\$?

# Main recording loop - runs indefinitely
while true; do
# Generate timestamp for this hour's recording
TIMESTAMP=\$(date +%Y%m%d_%H%M%S)

log_message "Creating new playlist: \${TIMESTAMP}_playlist.m3u8"

# Run GStreamer with logging
run_gstreamer_with_logging "\$TIMESTAMP" \$AUDIO_AVAILABLE

# Check if gst-launch exited due to an error
EXIT_CODE=\$?
if [ \$EXIT_CODE -ne 0 ] && [ \$EXIT_CODE -ne 124 ]; then
Expand Down
74 changes: 55 additions & 19 deletions installer/video_encoders/video_storage_encoder_with_audio.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,29 +26,20 @@ check_audio_encoder() {
fi
}

log_message "Starting HLS recording with audio support and 60-minute playlist rotation"

# Check for audio encoder availability
check_audio_encoder
AUDIO_AVAILABLE=$?

# Main recording loop - runs indefinitely
while true; do
# Generate timestamp for this hour's recording
TIMESTAMP=$(date +%Y%m%d_%H%M%S)

log_message "Creating new playlist: ${TIMESTAMP}_playlist.m3u8"
# Function to run GStreamer with logging
run_gstreamer_with_logging() {
local timestamp=$1
local audio_available=$2

if [ $AUDIO_AVAILABLE -eq 0 ]; then
if [ $audio_available -eq 0 ]; then
log_message "Recording with audio from UDP stream (port 5011)"
# Enhanced pipeline with audio support (video + UDP audio stream)
# Try hardware encoding first, fallback to software if it fails
timeout 3630 gst-launch-1.0 -e \
mpegtsmux name=mux ! \
hlssink playlist-root=file://$OUTPUT_DIR \
target-duration=60 playlist-length=60 max-files=0 \
playlist-location="$OUTPUT_DIR/${TIMESTAMP}_playlist.m3u8" \
location="$OUTPUT_DIR/${TIMESTAMP}_segment_%05d.ts" \
playlist-location="$OUTPUT_DIR/${timestamp}_playlist.m3u8" \
location="$OUTPUT_DIR/${timestamp}_segment_%05d.ts" \
rtspsrc location=rtsp://192.168.144.25:8554/main.264 latency=50 drop-on-latency=true ! \
rtph264depay ! h264parse ! \
avdec_h264 ! videoconvert ! \
Expand All @@ -61,7 +52,7 @@ while true; do
audioconvert ! audioresample ! \
audio/x-raw,rate=48000,channels=2 ! \
queue max-size-buffers=200 max-size-time=2000000000 ! \
avenc_aac bitrate=128000 ! aacparse ! mux.
avenc_aac bitrate=128000 ! aacparse ! mux. &
else
log_message "Recording video only (no audio device available)"
# Video-only pipeline using software encoding
Expand All @@ -77,10 +68,55 @@ while true; do
target-duration=60 \
playlist-length=60 \
max-files=0 \
playlist-location="$OUTPUT_DIR/${TIMESTAMP}_playlist.m3u8" \
location="$OUTPUT_DIR/${TIMESTAMP}_segment_%05d.ts"
playlist-location="$OUTPUT_DIR/${timestamp}_playlist.m3u8" \
location="$OUTPUT_DIR/${timestamp}_segment_%05d.ts" &
fi

local gst_pid=$!

# Keep track of logged files to avoid duplicates
local logged_files_list="/tmp/logged_segments_${timestamp}.txt"
touch "$logged_files_list"

# Monitor for new .ts files while GStreamer is running
while kill -0 $gst_pid 2>/dev/null; do
# Find all current .ts files for this timestamp
for ts_file in "$OUTPUT_DIR"/${timestamp}_segment_*.ts; do
if [ -f "$ts_file" ]; then
local filename=$(basename "$ts_file")
# Check if we've already logged this file
if ! grep -q "^$filename$" "$logged_files_list" 2>/dev/null; then
log_message "Created segment file: $filename"
echo "$filename" >> "$logged_files_list"
fi
fi
done
sleep 2
done

# Clean up the temporary file
rm -f "$logged_files_list"

wait $gst_pid
return $?
}

log_message "Starting HLS recording with audio support and 60-minute playlist rotation"

# Check for audio encoder availability
check_audio_encoder
AUDIO_AVAILABLE=$?

# Main recording loop - runs indefinitely
while true; do
# Generate timestamp for this hour's recording
TIMESTAMP=$(date +%Y%m%d_%H%M%S)

log_message "Creating new playlist: ${TIMESTAMP}_playlist.m3u8"

# Run GStreamer with logging
run_gstreamer_with_logging "$TIMESTAMP" $AUDIO_AVAILABLE

# Check if gst-launch exited due to an error
EXIT_CODE=$?
if [ $EXIT_CODE -ne 0 ] && [ $EXIT_CODE -ne 124 ]; then
Expand Down