Raspberry Pi でHDMIキャプチャ
右の画面がゲーム機からリアルタイムで取り込み映像
— ハート (@heartpz) March 2, 2022
左がキャプチャーユニットからブラウザ経由での
プレビュー
左下がさかのぼり録画30秒の映像 pic.twitter.com/cWmlQZvyt8
メモとして残します。
使用環境:
・Raspberry Pi 4 Model B (4 GB)
・Elgato Cam Link 4K
・Raspberry Pi OS Lite (Bulleseye) 2023-02-21
・FFMPEG
・nginx RTMP
NGINX 編集
/etc/nginx/nginx.conf
内容
rtmp {
server{
listen 1935;
chunk_size 4196;
application live {
live on;
hls_fragment 15s
hls_playlist_length 300s
hls on;
hsl_path /var/www/html/hls;
}
}
}
FFMPEG コマンド
ffmpeg -re -stream_loop -1 -f alsa -thread_queue_size 4096k -i hw:3,0 -y -framerate 60 -f v4l2 -thread_queue_size 8196k -i /dev/video0 -s 1920x1080 -bufsize 8000k -vcodec h264_v4l2m2m -vb 8196k -bufsize 8196k -pix_fmt yuv420p -acodec aac -ab 160k -f flv rtmp://localhost/live/key
HLS Player
置く場所
/var/www/html
内容 PC用
<html>
<head>
<title>Live Streaming</title>
<link href="https://vjs.zencdn.net/7.0/video-js.min.css" rel="stylesheet">
<script src="https://vjs.zencdn.net/7.0/video.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/videojs-contrib-hls/5.14.1/videojs-contrib-hls.min.js"></script>
</head>
<body>
<video id="live_streaming" width="800px"
class="video-js vjs-default-skin" controls>
<source
src="hls/key.m3u8"
type="application/x-mpegURL">
</video>
<script>
var player = videojs("live_streaming");
player.play();
</script>
</body>
</html>
ios用
<html>
<head>
<title>Live Streaming</title>
<script>
video { width: 100%;}
</script>
</head>
<body>
<div>
<video controls autoplay muted playsinline width="100%" src="hls/key.m3u8"></video>
</body>
</div>
</html>
さかのぼり録画
間違っているかもしれないけど
動いている
sakanobori.sh
150秒 さかのぼるときの設定
RUN_ID=`date +%Y%m%d_%H%M%S`
OUTPUT=/home/pi/rec/output_$RUN_ID.mp4
MYLIST=/home/pi/rec/$RUN_ID.txt
echo "" > $MYLIST
for file in `ls -v /var/www/html/hls/key*.ts|head -n -1 |tail -n -12`;do
echo "file $file" >> $MYLIST
done
ffmpeg -sseof -150 -safe 0 -f concat -i $MYLIST -t 150 -acodec copy -vcodec copy -y -f mp4 $OUTPUT
気が向いたら書き足すかも