Skip to content

Instantly share code, notes, and snippets.

@xtetsuji
Last active July 8, 2024 06:17
Show Gist options
  • Select an option

  • Save xtetsuji/73e1acb5b18b9d87573d9ecd79968807 to your computer and use it in GitHub Desktop.

Select an option

Save xtetsuji/73e1acb5b18b9d87573d9ecd79968807 to your computer and use it in GitHub Desktop.

Revisions

  1. xtetsuji revised this gist Jul 8, 2024. No changes.
  2. xtetsuji revised this gist Jul 8, 2024. No changes.
  3. xtetsuji revised this gist Jul 8, 2024. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion mov2mp4.sh
    Original file line number Diff line number Diff line change
    @@ -25,7 +25,7 @@ trap handle_error EXIT
    # main 関数
    function main {
    local argv=("$@")
    local input=${argv[0]}
    local input=${argv[0]:-}
    echo "入力ファイル: $input"
    # コマンド例(ここでエラーが発生する)
    # ls /tmp/notfounddir
  4. xtetsuji created this gist Jul 7, 2024.
    49 changes: 49 additions & 0 deletions mov2mp4.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,49 @@
    #!/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