Last active
June 9, 2019 09:00
-
-
Save jiahut/6b42e7082f38316f615636633d0821bf to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
set -o errexit # set -e | |
set -o pipefail | |
# https://superuser.com/questions/100288/how-can-i-check-the-integrity-of-a-video-file-avi-mpeg-mp4 | |
OPTIONS=dio:v | |
LONGOPTS=debug,info,output:,verbose | |
# brew install gnu-getopt | |
getopt_tool=$(which getopt) | |
if [[ "$(uname)" == "Darwin" ]]; then | |
getopt_tool=/usr/local/opt/gnu-getopt/bin/getopt | |
fi | |
# https://stackoverflow.com/questions/192249/how-do-i-parse-command-line-arguments-in-basht | |
# -allow a command to fail with "!'s" side effect on errexit | |
! PARSED=$($getopt_tool --options=$OPTIONS --longoptions=$LONGOPTS --name "$0" -- "$@") | |
eval set -- "$PARSED" | |
out=/tmp/$(basename -- $0 ".sh").log | |
while true; do | |
case "$1" in | |
-d|--debug) | |
debug=true | |
shift | |
;; | |
-i|--info) | |
info=true | |
shift | |
;; | |
-o|--out) | |
out="$2" | |
shift 2 | |
;; | |
-v|--verbose) | |
verbose=true | |
shift | |
;; | |
--) | |
shift | |
break | |
;; | |
*) | |
echo "$0 options error" | |
exit -1 | |
;; | |
esac | |
done | |
[[ $verbose == true ]] && echo "debug: $debug, info: $info, out: $out, in: $1" | |
video=$1 | |
if [[ -z $video ]]; then | |
echo "[error] please spectify the video path" | |
exit -1 | |
fi | |
ffmpeg -v error -i $video -map 0:1 -f null - >$out 2>&1 | |
err_code=$? | |
[[ ! -z $debug ]] && cat $out | |
if [[ $info == true ]] && [[ $err_code == 0 ]]; then | |
# brew install coreutils | |
# apt install realpath | |
echo $(realpath "$video") | |
fi | |
exit $err_code |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment