vid2mov: better args handling

This commit is contained in:
Guilherme Rugai Freire 2021-08-20 15:36:28 -03:00
parent 928d5d8304
commit 076b28e285
No known key found for this signature in database
GPG Key ID: 0F9FE41723A8A297
2 changed files with 32 additions and 4 deletions

View File

@ -5,6 +5,8 @@ a simple script around ffmpeg to convert a video file to `.mov`.
I personally use this script when I record something in OBS Studio and then want to import into DaVinci Resolve.
Run ``vid2mov -h`` for help.
## Requirements
- [ffmpeg](https://www.ffmpeg.org/)
- [notify-send](https://gitlab.gnome.org/GNOME/libnotify) (optional)

View File

@ -1,17 +1,43 @@
#!/bin/sh
usage() {
cat << EOF
Usage: vid2mov -i [input_file] {-o [output_file]} {-y}
-h Show this help.
-i Specify input_file.
-o Specify output_file. Default to input_file with .mov extension.
-y Pass the -y flag to ffmpeg.
EOF
}
notify() {
if [ "$(command -v notify-send)" ]; then
notify-send "$@"
fi
}
VIDEO_PATH=$1
[ "$VIDEO_PATH" = "" ] && echo "error: video_path not given" && exit 1
[ "$2" != "" ] && OUT_PATH=$2 || OUT_PATH=${VIDEO_PATH%%.*}.mov
VIDEO_PATH=""
OUT_PATH=""
CONFIRMATION=""
if ffmpeg -i "$VIDEO_PATH" -vcodec mpeg4 -q:v 2 -acodec pcm_s16le -q:a 0 -f mov "$OUT_PATH"; then
while getopts "hi:o::y" ARG; do
case $ARG in
h) usage ; exit 0;;
i) VIDEO_PATH=$OPTARG;;
o) OUT_PATH=$OPTARG;;
y) CONFIRMATION="-y";;
esac
done
[ "$VIDEO_PATH" = "" ] && echo "error: video_path not given" && usage && exit 1
[ "$OUT_PATH" = "" ] && OUT_PATH=${VIDEO_PATH%%.*}.mov
if ffmpeg -i "$VIDEO_PATH" -vcodec mpeg4 -q:v 2 -acodec pcm_s16le -q:a 0 -f mov "$OUT_PATH" $CONFIRMATION; then
echo "Done"
notify "vid2mov" "$OUT_PATH done converting"
exit 0