camrectoavi/camrectoavi.sh

47 lines
1 KiB
Bash
Raw Normal View History

2021-12-22 05:29:39 -05:00
#!/bin/bash
set -e
# Arg parser
while [ ! $# == 0 ]; do
case "$1" in
2021-12-30 00:47:33 -05:00
-o | --output) shift; OUTPUT=$1;;
*)
2021-12-22 05:29:39 -05:00
if [[ -f $1 ]]; then
INPUT=$1
else
echo "Invalid argument \"$1\""
exit 1
fi
;;
esac
shift
done
# If no input is specified, exit
[[ ! -f $INPUT ]] && echo "No input file specified!" && exit 1
# If no output is specified, plop it into the same folder as the source and rename to *.avi
[[ ! $OUTPUT ]] && OUTPUT=$(echo "$INPUT" | sed 's/\(.*\)\..*/\1/').avi
#################
# Make tempdir
2021-12-30 00:47:33 -05:00
TMPDIR="/tmp/$(basename "$INPUT" | sed 's/\(.*\)\..*/\1/')-$RANDOM"
2021-12-22 05:29:39 -05:00
mkdir "$TMPDIR"
# Extract camrec file
7z e "$INPUT" -o"$TMPDIR"
# Ready up ffmpeg jank for merging audio (I hope to god there is only one video stream)
AUDIO=
NUM=0
for i in "$TMPDIR/*.wav"; do
AUDIO+="-i $i -map $NUM "
NUM=$(( $NUM + 1 )) # Fuck you Bash
done
# Convert contents to AVI
ffmpeg -i "$TMPDIR/Screen_Stream.avi" $AUDIO -map $NUM -c:v copy -c:a copy $OUTPUT
rm -r "$TMPDIR"