Skip to content

Instantly share code, notes, and snippets.

@Enelar
Created May 8, 2017 15:38
Show Gist options
  • Save Enelar/ea95cf79d383560f7296460fcd46c7d0 to your computer and use it in GitHub Desktop.
Save Enelar/ea95cf79d383560f7296460fcd46c7d0 to your computer and use it in GitHub Desktop.
Compress videos each night. NEVER KILL ffmpeg, otherwise you will lose files.
Each file inside incomming folder would be converted into HVEC/OPUS, with same folder structure into output folder (will be created near).
if [ -f converting.lock ]; then
read -r pid < converting.lock
if kill -0 $pid; then
kill -CONT $pid
exit
else
rm converting.lock
fi
fi
bash convert_vps.bash
if [ -f converting.lock ]; then
read -r pid < converting.lock
echo "PID: $pid";
if kill -0 $pid; then
kill -STOP $pid
exit
fi
fi
if [ -f converting.lock ]; then
echo "Converting lock is presend. Abort"
exit
fi
echo $$ > converting.lock
files=`du -a incomming/* | sort -n | head -n 30 | cut -f 2`
while read line; do
echo "CONVERTING $line"
file=${line#incomming}
resfile=`echo $file | sed -e 's/\.\w*$/\.opus\.x265\.mkv/'`
busy=`lsof -t "incomming/$file"`
rmdir "incomming/$file"
if [ ! -z "$busy" ]; then
continue;
fi;
processing=".processing$resfile"
result="outcomming$resfile"
echo $processing $result
mkdir -p -- "$(dirname -- "$result")"
mkdir -p -- "$(dirname -- "$processing")"
cp $file $result # if ffmpeg would fail
rm "$processing"
res=`nice -n 9001 ffmpeg -d -i "$line" -c:v libx265 -crf 28 -c:a libopus -b:a 50k -threads 1 "$processing" & echo $! > converting.lock`
mv "$processing" "$result"
echo "done: $line"
rm "$line"
done <<< "$files"
rm converting.lock
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment