<commit_before>#!/bin/bash
#
# convert-video.sh
#
# Copyright (c) 2013-2014 <NAME>
#

about() {
    cat <<EOF
$program 2.0 of December 3, 2014
Copyright (c) 2013-2014 <NAME>
EOF
    exit 0
}

usage() {
    cat <<EOF
Convert video file from Matroska to MP4 format or from MP4 to Matroksa format
WITHOUT TRANSCODING VIDEO.

Usage: $program [OPTION]... [FILE]

    --help      display this help and exit
    --version   output version information and exit

Requires \`mkvmerge\`, \`ffmpeg\` and \`mp4track\` executables in \$PATH
Output is written to current working directory.
EOF
    exit 0
}

syntax_error() {
    echo "$program: $1" >&2
    echo "Try \`$program --help\` for more information." >&2
    exit 1
}

die() {
    echo "$program: $1" >&2
    exit ${2:-1}
}

readonly program="$(basename "$0")"

case $1 in
    --help)
        usage
        ;;
    --version)
        about
        ;;
esac

readonly input="$1"

if [ ! "$input" ]; then
    syntax_error 'too few arguments'
fi

if [ ! -f "$input" ]; then
    die "input file not found: $input"
fi

for tool in mkvmerge ffmpeg mp4track; do

    if ! $(which $tool >/dev/null); then
        die "executable not in \$PATH: $tool"
    fi
done

readonly identification="$(mkvmerge --identify-verbose "$input")"
readonly input_container="$(echo "$identification" | sed -n 's/^File .*: container: \(.*\) \[.*\]$/\1/p')"

if [ ! "$input_container" ]; then
    die "unknown input container format: $input"
fi

case $input_container in
    'Matroska')
        container_format='mp4'
        ;;
    'QuickTime/MP4')
        container_format='mkv'
        ;;
    *)
        die "unsupported input container format: $input"
        ;;
esac

readonly output="$(basename "$input" | sed 's/\.[^.]*$//').$container_format"

if [ -e "$output" ]; then
    die "output file already exists: $output"
fi

video_track=''
ac3_audio_track=''
aac_audio_track=''
extra_aac_audio_track_list=''
other_audio_track=''
index='0'
<commit_msg>Simplify getting output file name (removing need for sed).<commit_after>#!/bin/bash
#
# convert-video.sh
#
# Copyright (c) 2013-2014 <NAME>
#

about() {
    cat <<EOF
$program 2.0 of December 3, 2014
Copyright (c) 2013-2014 <NAME>
EOF
    exit 0
}

usage() {
    cat <<EOF
Convert video file from Matroska to MP4 format or from MP4 to Matroksa format
WITHOUT TRANSCODING VIDEO.

Usage: $program [OPTION]... [FILE]

    --help      display this help and exit
    --version   output version information and exit

Requires \`mkvmerge\`, \`ffmpeg\` and \`mp4track\` executables in \$PATH
Output is written to current working directory.
EOF
    exit 0
}

syntax_error() {
    echo "$program: $1" >&2
    echo "Try \`$program --help\` for more information." >&2
    exit 1
}

die() {
    echo "$program: $1" >&2
    exit ${2:-1}
}

readonly program="$(basename "$0")"

case $1 in
    --help)
        usage
        ;;
    --version)
        about
        ;;
esac

readonly input="$1"

if [ ! "$input" ]; then
    syntax_error 'too few arguments'
fi

if [ ! -f "$input" ]; then
    die "input file not found: $input"
fi

for tool in mkvmerge ffmpeg mp4track; do

    if ! $(which $tool >/dev/null); then
        die "executable not in \$PATH: $tool"
    fi
done

readonly identification="$(mkvmerge --identify-verbose "$input")"
readonly input_container="$(echo "$identification" | sed -n 's/^File .*: container: \(.*\) \[.*\]$/\1/p')"

if [ ! "$input_container" ]; then
    die "unknown input container format: $input"
fi

case $input_container in
    'Matroska')
        container_format='mp4'
        ;;
    'QuickTime/MP4')
        container_format='mkv'
        ;;
    *)
        die "unsupported input container format: $input"
        ;;
esac

readonly output="$(basename "${input%.*}").$container_format"

if [ -e "$output" ]; then
    die "output file already exists: $output"
fi

video_track=''
ac3_audio_track=''
aac_audio_track=''
extra_aac_audio_track_list=''
other_audio_track=''
index='0'

{'fraction_non_alphanumeric': 0.15341912692404744, 'fraction_numerical': 0.022710068130204392, 'mean_word_length': 2.9015748031496065, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4776105', 'n_tokens_mistral': 1451, 'n_tokens_neox': 1349, 'n_words': 422}