Last active
July 8, 2024 06:17
-
-
Save xtetsuji/73e1acb5b18b9d87573d9ecd79968807 to your computer and use it in GitHub Desktop.
For GitHub movie screenshot explaination, convet from .mov to .mp4 by avconvert command on macOS built-in
This file contains 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 -eu | |
PRESET="PresetAppleM4V1080pHD" | |
function usage { | |
# local error_code=${1:-0} | |
cat <<EOF | |
Usage: | |
mov2mp4.sh input.mov | |
EOF | |
# exit "$error_code" | |
} | |
function handle_error { | |
local error_code=$? | |
if [ "$error_code" -ne 0 ] ; then | |
echo "エラーが発生しました: コマンド '$BASH_COMMAND' で error_code=$error_code エラーが発生 (行番号: $LINENO)" | |
usage "$error_code" | |
fi | |
} | |
trap handle_error EXIT | |
# main 関数 | |
function main { | |
local argv=("$@") | |
local input=${argv[0]:-} | |
echo "入力ファイル: $input" | |
# コマンド例(ここでエラーが発生する) | |
# ls /tmp/notfounddir | |
if ! [[ $input =~ \.mov$ ]] ; then | |
echo "入力ファイルの拡張子は .mov である必要があります" | |
# usage 1 | |
usage | |
exit | |
fi | |
# M4V 入りのプリセットは m4v 拡張子のみ受け付ける | |
local output_m4v=${input%.mov}.m4v | |
echo "avconvert start" | |
avconvert --preset "$PRESET" --source "$input" --output "$output_m4v" | |
# GitHub 添付は m4v ではなく mp4 拡張子である必要がある | |
local output_mp4=${input%.mov}.mp4 | |
mv -v "$output_m4v" "$output_mp4" | |
} | |
main "$@" | |
exit |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment