Videostreams von IP-Kamera als E-Mail und Live (NVR, h.264, IPC, HLS, FFmpeg)

Begonnen von Torxgewinde, 01 Dezember 2022, 19:17:18

Vorheriges Thema - Nächstes Thema

Torxgewinde

Sorry, schon wieder zeitgleich,
Ich hatte gerade noch ein Skript für nur einen Parameter ergänzt. Klappt das?


kroonen

Same issue here. The video works, but only gives last 5 seconds and than it stops, and there comes no new video. In the video dir I get new hd_*.tls files that are newer. Tested with firefox and safari


#!/bin/bash

#Put HLS output into $WEBFOLDER
WEBFOLDER="/opt/fhem/www/video/"

#High resolution RTSP stream
STREAMHIGH="rtsp://user:pass@192.168.180.55:554/"

########################################################################
function cleanup () {
echo "cleaning up..."
exit 0
}
trap cleanup INT EXIT

cd

#download hls.js if not present
if [ ! -f "$WEBFOLDER/hls.js" ]; then
##wget "https://cdn.jsdelivr.net/npm/hls.js@latest" -O "$WEBFOLDER/hls.js" || exit 1
curl "https://cdn.jsdelivr.net/npm/hls.js@latest" --no-progress-meter --output "$WEBFOLDER/hls.js" || exit 1
fi

#this is a simple webpage with the HLS video.
#Safari plays it without Javascript, Firefox needs hls.js
cat << 'EOM' > "$WEBFOLDER/index.html"
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<script src="hls.js"></script>
<style>
body {
margin: 0;
padding: 0;
}
video {
object-fit: fill;
width: 100%;
height: auto;
}
</style>
</head>
<body>
<video id="video" controls autoplay>
<source src="stream.m3u8" type="application/x-mpegURL">
</video>
<script>
if (Hls.isSupported()) {
var video = document.getElementById('video');

var config = {
autoStartLoad: true,
startPosition: 30,
backBufferLength: 60
};
var hls = new Hls(config);

hls.loadSource('stream.m3u8');
hls.attachMedia(video);

//autoplay, many browsers are configured to only allow autoplay when muted
hls.on(Hls.Events.MANIFEST_PARSED, function() {
video.muted = true;
video.volume = 0;
video.play();
});

hls.on(Hls.Events.FRAG_LOADED, function() {
video.currentTime = video.duration - 5;
});
}
</script>
</body>
</html>
EOM

# https://ffmpeg.org/ffmpeg.html#Advanced-options
# https://ffmpeg.org/ffmpeg-formats.html#hls-2
# -hide_banner: Hide the infos at startup
# -rtsp_transport tcp: Default is to use UDP, which reveals skipped packets in my network
# -i $STREAMHIGH: the input at high resolution
# -i $STREAMLOW: the input at low resultion
# -codec copy: do not transcode, just remux - this is essential for embedded devices!
# -b:v:0 1024k Describe the bandwidth of video of the first input (index starts at 0)
# -b:v:1 256k  For the low resolution stream the bandwidth is about 256kBit/s
# -map 0:v include the videostream of the first input
# -map 1:v include the videostream of second input as well
# -map 0:a for audio of first input (not used here)
# -copytb 1 Use the demuxer timebase
# -copyts copy timestamps from input to output
# -f hls output is HLS
# -var_stream_map 'v:0,name:hd,agroup:my_stream v:1,name:sd,agroup:my_stream' select first video stream, name it "hd", assign a group + select second video stream, name it "sd", assign it to group
# -hls_time 5 each *.ts file has a length of ~5 seconds
# -hls_allow_cache 0 client must not cache the file
# -hls_list_size 10 limit the number of files to this value
# -hls_flags delete_segments+append_list+program_date_time : delete unreferenced (old) *.ts files, append new ts files to playlist, insert recorded date+time
# -hls_segment_filename '$WEBFOLDER/%v_file%d.ts' pattern for the *.ts filename
# -master_pl_name stream.m3u8 pattern for the the HLS master playlist
# -master_pl_publish_rate 10 publish a current master playlist after creating N *.ts segments
# '$WEBFOLDER/%v_stream.m3u8' the output for HLS playlists
while true; do
ffmpeg -hide_banner \
  -rtsp_transport tcp -i $STREAMHIGH \
  -codec copy \
  -b:v:0 2M \
  -map 0:v \
  -copytb 1 -copyts \
  -f hls \
  -var_stream_map 'v:0,name:hd,agroup:my_stream' \
  -hls_time 5 \
  -hls_allow_cache 0 \
  -hls_list_size 10 \
  -hls_flags delete_segments+append_list+program_date_time \
  -hls_segment_filename "$WEBFOLDER/%v_file%d.ts" \
  "$WEBFOLDER/stream.m3u8"
sleep 1
done

exit 0

Torxgewinde

@kroonen:
Please try removing the Javascript:

hls.on(Hls.Events.FRAG_LOADED, function() {
video.currentTime = video.duration - 5;
});


If that does not work, I can only suggest to check the Developer-Console by pressing F12 on Firefox. Safari does not rely on HLS.js and if that also fails it might be something else. Strange indeed.

kroonen

Hi,

I remove the piece. Than it works for about 20 seconds. When I do a fresh reload of firefox (hold shift and reload), than it again for 20 seconds later.

It looks like something with cache?