-
Notifications
You must be signed in to change notification settings - Fork 0
/
upload_moosia.sh
42 lines (31 loc) · 1.18 KB
/
upload_moosia.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#!/usr/bin/env bash
set -eE
[ "$1" ]
tg_token="�"
tg_chat_id="�"
tg_curl() { curl "https://api.telegram.org/bot$tg_token/$@"; echo; }
trap 'tg_curl "sendMessage?chat_id=$tg_chat_id&text=Something%20wrong"' ERR
tmp=$(mktemp --directory --tmpdir moosia_uploader_XXXXX)
trap 'rm -rvf "$tmp"' EXIT
# Extract a sane filename
vid_name=${1##*/}
vid_name=${vid_name%%.*}
vid_name=${vid_name//[!0-9a-zA-Z_-]/}
# Convert to get better compression
ffmpeg -y -loglevel error -i "$1" -c:v libx265 "$tmp/full.mp4"
# Generate thumbnail
ffmpeg -y -loglevel error -i "$tmp/full.mp4" \
-vf "thumbnail,scale=w=320:h=320:force_original_aspect_ratio=decrease" \
-frames:v 1 "$tmp/thumb.jpg"
# Make message
msg=$([[ $1 =~ .*-timelapse.mpg ]] && echo '%23timelapse' || echo '')
# Read some metadata
IFS=, read width height duration < <(
ffprobe -v error -select_streams v:0 \
-show_entries stream=width,height,duration -of csv=p=0 \
"$tmp/full.mp4")
# Upload
tg_curl \
"sendVideo?chat_id=$tg_chat_id&caption=$msg&width=$width&height=$height&duration=$duration&supports_streaming=True" \
-F "video=@$tmp/full.mp4;filename=Moosia_$vid_name.mp4" \
-F "thumb=@$tmp/thumb.jpg"