From c08b55a4243e89650c5f48630b9c49e4901dafe5 Mon Sep 17 00:00:00 2001 From: klemek Date: Sat, 29 Aug 2026 20:08:27 +0200 Subject: [PATCH] delay.sh --- Makefile | 3 ++- delay.sh | 28 ++++++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) create mode 100755 delay.sh diff --git a/Makefile b/Makefile index 2130785..51cd195 100644 --- a/Makefile +++ b/Makefile @@ -80,7 +80,8 @@ build: $(BUILD_DIR)/$(TARGET) .PHONY: run run: $(BUILD_DIR)/$(TARGET) - $(BUILD_DIR)/$(TARGET) $(RUN_ARGS) + # $(BUILD_DIR)/$(TARGET) $(RUN_ARGS) + $(PROJECT_DIR)/delay.sh /dev/video0 25 640x480 30 .PHONY: submodule-init submodule-init: diff --git a/delay.sh b/delay.sh new file mode 100755 index 0000000..8aebfbc --- /dev/null +++ b/delay.sh @@ -0,0 +1,28 @@ +#!/bin/bash + +set -e + +DEVICE=${1:-/dev/video0} +DELAY=${2:-30} +SIZE=${3:-1280x720} +FPS=${4:-20} + +rm -rf /tmp/delay_stream* + +ffmpeg -f v4l2 -framerate $FPS -video_size $SIZE -i $DEVICE \ + -vcodec libx264 -preset ultrafast -tune zerolatency \ + -f hls -hls_time 1 -hls_list_size $((DELAY + 5)) -hls_flags delete_segments \ + /tmp/delay_stream.m3u8 & +FFMPEG_PID=$! + +start=`date +%s` + +until [ -f /tmp/delay_stream.m3u8 ]; do sleep 0.1; done + +end=`date +%s` + +sleep $((DELAY - end + start)) + +ffplay /tmp/delay_stream.m3u8 + +kill $FFMPEG_PID $HTTP_PID