forked from MariosPapasofokli/databrary
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtranscode
More file actions
executable file
·106 lines (89 loc) · 2.54 KB
/
transcode
File metadata and controls
executable file
·106 lines (89 loc) · 2.54 KB
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
#!/usr/bin/env bash
# Transcode job management.
# This is run on transcode.host, called from conf/transctl.sh
# It is also the SLURM script so is in fact run twice, once with arguments (up to the sbatch), once with variables.
#SBATCH --nodes=1
#SBATCH --mem=1024m
SLURM=$0
if [[ $SLURM != /* ]] ; then
SLURM=$PWD/$SLURM
fi
while getopts 'i:h:d:v:m:k:s:r:f:' opt ; do case "$opt" in
i) id=$OPTARG ;;
h) hpc=$OPTARG ;;
d) dir=$OPTARG ;;
v) version=$OPTARG ;;
m) mount=$OPTARG ;;
k) kill=$OPTARG ;;
s) ;;
r) url=$OPTARG ;;
f) fmt=$OPTARG ;;
?) exit 1 ;;
esac ; done
shift $[OPTIND-1]
args=("$@")
if [[ -z $id || -z $dir || -z $kill && ( -z $url || -z $fmt ) ]] ; then
echo "$0: usage error: $*" >&2
exit 1
fi
if [[ -n $mount ]] ; then
rsync "$mount/$dir/$id" "$dir/$id" || exit 1
fi
cd $dir || exit 1
IN=$id
OUT=$id.$fmt
LOG=$id.log
if [[ -n $kill ]] ; then
if [[ -n $hpc ]] ; then
scancel $kill
else
kill $kill
fi
rm -f "$IN" "$OUT"
exit 0
fi
if [[ ! -f $IN ]] ; then
echo "$IN: file not found" >&2
exit 1
fi
IFS='
'
if [[ -n $hpc ]] ; then
rate=80000
sec=$[60+`stat -c %s "$IN"`/$rate]
if [[ $sec -gt 604800 ]] ; then
sec=604800
elif [[ $sec -lt 43200 ]] ; then
sec=43200
fi
min=$[$sec/60]
echo "${args[*]}" > $id.args
exec sbatch --job-name="${dir##*/}$id" --export="dir=$PWD,id=$id,fmt=$fmt,url=$url,version=$version" -t $min "$SLURM"
elif [[ -n $SLURM_JOB_NAME ]] ; then # if SLURM_JOB_NAME is non zero length
# remove everything in the name past the first dot .
PID=${SLURM_JOBID%%.*}
read -d '' -r -a args < $id.args
else
PID=$$
fi
exec >$LOG 2>&1
case $fmt in
mp4) outargs=(-f mp4 -g 60 -c:v libx264 -pix_fmt yuvj420p -c:a libfdk_aac) ;;
mp3) outargs=(-f mp3 -c:a libmp3lame -q:a 1) ;;
*)
echo "Unknown format $fmt" >&2
exit 1
esac
sleep 5 # hope server knows job has started by now
ls -s "$IN"
ffmpeg -loglevel warning -benchmark -threads ${SLURM_NTASKS:-1} -i "$IN" -map_metadata -1 -metadata comment="databrary.org ${dir##*/}/$version" -metadata description="http://databrary.org/asset/$id" "${args[@]}" -threads ${SLURM_NTASKS:-1} "${outargs[@]}" -y "$OUT"
r=$?
[[ -f "$OUT" ]] && ls -s "$OUT"
if [[ $r -ne 0 ]] ; then
rm -f "$OUT"
else
sha1=`sha1sum "$OUT"`
rm -f "$id.args"
fi
# sha1 arg is split to work around weird HPC error:
curl -sSk --data-urlencode "pid=$PID" --data-urlencode "res=$r" ${sha1:+--data-urlencode} ${sha1:+"sha1=${sha1%% *}"} --data-urlencode "log@$LOG" "$url"