From 076b28e28585998e0ebfe8841ac2daeb2ea4f3a8 Mon Sep 17 00:00:00 2001 From: Guilherme Rugai Freire <41879254+GRFreire@users.noreply.github.com> Date: Fri, 20 Aug 2021 15:36:28 -0300 Subject: [PATCH] vid2mov: better args handling --- vid2mov/README.md | 2 ++ vid2mov/vid2mov.sh | 34 ++++++++++++++++++++++++++++++---- 2 files changed, 32 insertions(+), 4 deletions(-) diff --git a/vid2mov/README.md b/vid2mov/README.md index d17e1fb..e9013ae 100644 --- a/vid2mov/README.md +++ b/vid2mov/README.md @@ -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) diff --git a/vid2mov/vid2mov.sh b/vid2mov/vid2mov.sh index 5f7ccc0..c439401 100755 --- a/vid2mov/vid2mov.sh +++ b/vid2mov/vid2mov.sh @@ -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