init
This commit is contained in:
parent
369cc5c103
commit
f0fbe6d093
2 changed files with 48 additions and 0 deletions
19
Dockerfile
Normal file
19
Dockerfile
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
FROM alpine:3.20
|
||||||
|
|
||||||
|
COPY inotiy.sh /inotiy.sh
|
||||||
|
RUN CHOWN +x /inotiy.sh
|
||||||
|
|
||||||
|
RUN apk --no-cache add \
|
||||||
|
inotify-tools \
|
||||||
|
curl \
|
||||||
|
&& rm -rf /var/cache/apk/*
|
||||||
|
|
||||||
|
|
||||||
|
ENV CHUNK_SIZE=1048576 \
|
||||||
|
WATCH_PATH=/opt/livekit-egress \
|
||||||
|
UPLOAD_URL= \
|
||||||
|
AUTH_TOKEN=verySecretToken \
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
CMD ["sh", "/inotiy.sh" ]
|
29
inotify.sh
Normal file
29
inotify.sh
Normal file
|
@ -0,0 +1,29 @@
|
||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
inotifywait -m "$WATCH_PATH" -e close_write |
|
||||||
|
while read PATH ACTION FILE; do
|
||||||
|
|
||||||
|
if [[ "${FILE}" == *.mp4 ]]
|
||||||
|
then
|
||||||
|
echo "Following PATH is selected: $PATH"
|
||||||
|
echo "Uploading following FILE: $FILE"
|
||||||
|
|
||||||
|
file_path="${PATH}${FILE}"
|
||||||
|
chunk_size="$CHUNK_SIZE"
|
||||||
|
id="${FILE%.mp4}"
|
||||||
|
|
||||||
|
file_size=$(stat -c%s "$file_path")
|
||||||
|
num_chunks=$(( (file_size + chunk_size - 1) / chunk_size ))
|
||||||
|
|
||||||
|
for (( i=0; i<num_chunks; i++ )); do
|
||||||
|
offset=$(( i * chunk_size ))
|
||||||
|
dd if="$file_path" bs=$chunk_size skip=$i count=1 2>/dev/null | curl \
|
||||||
|
--location "$UPLOAD_URL" \
|
||||||
|
--header "Authorization: Bearer $AUTH_TOKEN" \
|
||||||
|
--form "recording_id=${id}" \
|
||||||
|
--form "chunk_index=${i}" \
|
||||||
|
--form "total_chunks=${num_chunks}" \
|
||||||
|
--form "FILE=@-"
|
||||||
|
done
|
||||||
|
fi
|
||||||
|
done
|
Loading…
Add table
Reference in a new issue