Compare commits

...

3 Commits

14 changed files with 107 additions and 87 deletions

22
.vimrc
View File

@ -1213,6 +1213,7 @@ fu! Build(optimized=0, silent=0)
let l:is_jai = 0
let l:has_jai_build_file = 0
let l:has_jai_first_file = 1
let l:ext = tolower(expand('%:e'))
let l:current_dir = expand('%:p:h')
@ -1225,16 +1226,24 @@ fu! Build(optimized=0, silent=0)
" Check for a build file in the current directory or one directory back
" (e.g. we're in modules/ or src/, code/, etc)
if filereadable(l:current_dir . "/build.jai") || filereadable(l:one_dir_back . "/build.jai")
if filereadable(l:current_dir . "/build.jai") || filereadable(l:one_dir_back . "/build.jai") || filereadable(l:current_dir . "/first.jai") || filereadable(l:one_dir_back . "/first.jai")
let l:has_jai_build_file = 1
if filereadable(l:current_dir . "/build.jai") == 1
let l:cmd = "jai ". l:current_dir . "/build.jai"
elseif filereadable(l:current_dir . "/first.jai") == 1
let l:cmd = "jai ". l:current_dir . "/first.jai"
let l:has_jai_first_file = 1
else
" It's one directory back. We don't want to include '../' in
" the cmd because then our reported paths in the program get
" botched, e.g. path shown in an assert error.
let l:cmd = "jai " . l:one_dir_back . "/build.jai"
if filereadable(l:one_dir_back . "/build.jai") == 1
let l:cmd = "jai " . l:one_dir_back . "/build.jai"
else
let l:cmd = "jai " . l:one_dir_back . "/first.jai"
let l:has_jai_first_file = 1
endif
endif
else
let l:cmd = "jai % "
@ -1251,8 +1260,13 @@ fu! Build(optimized=0, silent=0)
let l:set_metaprogram_args = 0
if l:has_jai_build_file
let l:filename = "build.jai"
if l:has_jai_first_file
let l:filename = "first.jai"
endif
if a:optimized == 1
echo "Compiling release build.jai"
echo "Compiling release " . l:filename
" @note We pass 'release' as a user metaprogram arg for the
" build file to parse in case it cares about that. -release is
" a compiler arg that we also include because some build
@ -1262,7 +1276,7 @@ fu! Build(optimized=0, silent=0)
let l:cmd .= " -release - -release"
let l:set_metaprogram_args = 1
else
echo "Compiling debug build.jai"
echo "Compiling debug " . l:filename
endif
else
if a:optimized == 1

View File

@ -51,7 +51,7 @@ fi
printf "\n${YELLOW}${BOLD}Modifying audio volume in $filename.$extension | output: $output | delta: $delta_db${NORMAL}\n"
# Since we're re-encoding the audio we have to specify a codec to use.
cmd="ffmpeg -i \"$filename.$extension\" -af \"volume=${delta_db}dB\" -c:v copy -c:a aac -map 0 \"$output\""
cmd="ffmpeg -y -stats -loglevel level+error -i \"$filename.$extension\" -af \"volume=${delta_db}dB\" -c:v copy -c:a aac -map 0 \"$output\""
printf "\n${BOLD}Running: $cmd\n\n${NORMAL}"
eval $cmd

View File

@ -47,5 +47,5 @@ else
fi
printf "\n${YELLOW}${BOLD}Encoding '$filename.$extension' with target bitrate $bitrate | output: $output${NORMAL}\n"
ffmpeg -i "$filename.$extension" -c:a aac -c:v mpeg4 -b:v $bitrate "$output"
ffmpeg -y -stats -loglevel level+error -i "$filename.$extension" -c:a aac -c:v mpeg4 -b:v $bitrate "$output"
printf "\n${GREEN}${BOLD}Done encoding '$filename.$extension' to '$output'${NORMAL}\n\n"

View File

@ -1,51 +0,0 @@
#!/usr/bin/env bash
if which tput >/dev/null 2>&1; then
ncolors=$(tput colors)
fi
if [ -t 1 ] && [ -n "$ncolors" ] && [ "$ncolors" -ge 8 ]; then
RED="$(tput setaf 1)"
GREEN="$(tput setaf 2)"
YELLOW="$(tput setaf 3)"
BLUE="$(tput setaf 4)"
MAGENTA="$(tput setaf 5)"
CYAN="$(tput setaf 6)"
BOLD="$(tput bold)"
NORMAL="$(tput sgr0)"
else
RED=""
GREEN=""
YELLOW=""
BLUE=""
MAGENTA=""
CYAN=""
BOLD=""
NORMAL=""
fi
input="$1"
output_name="$2"
if [[ $input == "" || $output_name == "" ]]; then
printf "${BOLD}${RED}Usage: $0 <input video> <wav output name>${NORMAL}\n"
exit 1
fi
if [[ ! -f "$input" ]]; then
printf "${RED}${BOLD}Error: failed to extract audio. Video file \"$input\" doesn't exist.\n${NORMAL}"
exit 1
fi
# Add extension if not provided.
output_basename=$(basename -- "$output_name")
output_extension="${output_basename##*.}"
if [[ $output_extension != "wav" ]]; then
output_name="${output_name}.wav"
fi
printf "\n${YELLOW}${BOLD}Extracting 16-bit WAV from $input | output: $output_name${NORMAL}\n"
# -ac 1 mixes audio to a single channel.
ffmpeg -i "$input" -ar 16000 -ac 1 -c:a pcm_s16le "$output_name"
printf "${GREEN}${BOLD}Done extracting 16-bit WAV from $input | output: $output_name${NORMAL}\n"

View File

@ -1,5 +1,10 @@
#!/usr/bin/env bash
# Extracts audio from a video. It expects you to know what audio codecs the video container has, e.g.
# it's an mp4 video with aac and m4a audio. Just set the format to the appropriate extension.
# If you want to convert to a different format or you want to change the bit rate, channels, trim the audio, etc.
# then use extract-audio-from-video-and-transcode
if which tput >/dev/null 2>&1; then
ncolors=$(tput colors)
fi
@ -23,13 +28,11 @@ else
NORMAL=""
fi
transcode="$1"
filename=$(basename -- "$2")
format="$3"
bitrate="$4"
filename=$(basename -- "$1")
format="$2"
if [[ $1 == "" || $2 == "" || $3 == "" ]]; then
printf "${BOLD}${RED}Usage: $0 <transcode? 0|1 (needed when container doesn't contain format)> <filename> <format (mp3, m4a, aac, etc)> <optional: bitrate. Uses 64k when not specified, 0 = variable (e.g. 0, 64, 128, etc)>${NORMAL}\n"
if [[ $1 == "" || $2 == "" ]]; then
printf "${BOLD}${RED}Usage: extract-audio-from-video <filename> <format (mp3, m4a, aac, etc)>${NORMAL}\n"
exit 1
fi
@ -37,19 +40,9 @@ extension="${filename##*.}"
filename="${filename%.*}"
output_name="$filename.$format"
if [[ $bitrate == "" ]]; then
bitrate="64"
fi
printf "\n${YELLOW}${BOLD}Extracting audio from $filename.$extension | output: $output_name${NORMAL}\n"
printf "\n${YELLOW}${BOLD}Extracting audio from $filename.$extension | bitrate: ${bitrate}k | output: $output_name${NORMAL}\n"
if [[ $transcode == "1" ]]; then
# Transcode audio
ffmpeg -i "$filename.$extension" -b:a ${bitrate}k -ac 2 -ar 44100 -map a "$output_name"
else
# Grab the audio stream from the video.
ffmpeg -i "$filename.$extension" -vn -acodec copy "$output_name"
fi
ffmpeg -y -stats -loglevel level+error -i "$filename.$extension" -vn -acodec copy "$output_name"
printf "\n${GREEN}${BOLD}Done extracting audio from $filename.$extension | output name '$output_name'${NORMAL}\n\n"

View File

@ -0,0 +1,65 @@
#!/usr/bin/env bash
# Extracts audio from a video and transcodes it based on the supplied params. If you just want the audio
# from the video as-is then use extract-audio-from-video
if which tput >/dev/null 2>&1; then
ncolors=$(tput colors)
fi
if [ -t 1 ] && [ -n "$ncolors" ] && [ "$ncolors" -ge 8 ]; then
RED="$(tput setaf 1)"
GREEN="$(tput setaf 2)"
YELLOW="$(tput setaf 3)"
BLUE="$(tput setaf 4)"
MAGENTA="$(tput setaf 5)"
CYAN="$(tput setaf 6)"
BOLD="$(tput bold)"
NORMAL="$(tput sgr0)"
else
RED=""
GREEN=""
YELLOW=""
BLUE=""
MAGENTA=""
CYAN=""
BOLD=""
NORMAL=""
fi
filename="$1"
output_name="$2"
sample_rate="$3"
channel_count="$4"
start_time="$5"
end_time="$6"
output_base=$(basename -- "$output_name")
output_extension="${output_base##*.}"
if [[ $filename == "" || $output_extension == "" || $output_extension == $output_base ]]; then
printf "${BOLD}${RED}Usage: extract-audio-from-video-and-transcode <filename> <output name w/ extension> <optional: sample rate. Defaults to 44100> <optional: channel count. Defaults to 2> <optional: start time HH:MM:SS> <optional: end time HH:MM:SS>${NORMAL}\n"
exit 1
fi
if [[ $sample_rate == "" ]]; then
sample_rate="44100"
fi
if [[ $channel_count == "" ]]; then
channel_count="2"
fi
timing_args=""
if [[ $start_time != "" ]]; then
timing_args="-ss $start_time "
fi
if [[ $end_time != "" ]]; then
timing_args+="-to $end_time"
fi
printf "\n${YELLOW}${BOLD}Extracting audio from '$filename' | output: '$output_name' | sample rate: $sample_rate | channels: $channel_count | start: $start_time | end: $end_time${NORMAL}\n"
ffmpeg -y -stats -loglevel level+error $timing_args -accurate_seek -i "$filename" -ar $sample_rate -ac $channel_count -map a "$output_name"
printf "\n${GREEN}${BOLD}Done extracting audio from '$filename' | output '$output_name'${NORMAL}\n\n"

View File

@ -45,7 +45,7 @@ fi
printf "\n${YELLOW}${BOLD}Repairing audio in $filename.$extension | output: $output${NORMAL}\n"
ffmpeg -i "$filename.$extension" -c:v copy -ac 1 -map 0 "$output"
ffmpeg -y -stats -loglevel level+error -i "$filename.$extension" -c:v copy -ac 1 -map 0 "$output"
printf "\n${GREEN}${BOLD}Done repairing audio in $filename.$extension | output: $output${NORMAL}\n\n"

View File

@ -37,7 +37,7 @@ output="${output_name}.mp4"
printf "\n${YELLOW}${BOLD}Joining contents of '$filename'| output: $output${NORMAL}\n"
ffmpeg -f concat -safe 0 -accurate_seek -i "$filename.$extension" -c:v libx264 -c:a copy "$output"
ffmpeg -y -stats -loglevel level+error -f concat -safe 0 -accurate_seek -i "$filename.$extension" -c:v libx264 -c:a copy "$output"
printf "\n${GREEN}${BOLD}Finished joining${NORMAL}\n\n"

View File

@ -40,7 +40,7 @@ output="${output_name}.mp4"
printf "\n${YELLOW}${BOLD}Joining contents of '$filename'| output: $output${NORMAL}\n"
ffmpeg -f concat -safe 0 -i "$filename" -c copy "$output"
ffmpeg -y -stats -loglevel level+error -f concat -safe 0 -i "$filename" -c copy "$output"
printf "\n${GREEN}${BOLD}Finished joining${NORMAL}\n\n"

View File

@ -68,7 +68,7 @@ it=`grep \"input_thresh\" $temp_file | cut -d: -f2 | tr -cd [:digit:].-`
to=`grep \"target_offset\" $temp_file | cut -d: -f2 | tr -cd [:digit:].-`
# 2nd pass:
cmd="ffmpeg -i \"$filename.$extension\" -c:v copy -pass 2 -filter:a loudnorm=linear=true:I=-16:LRA=11:tp=-1.5:measured_I=$ii:measured_LRA=$ilra:measured_tp=$itp:measured_thresh=$it:offset=$to:print_format=summary -map 0 \"$output\""
cmd="ffmpeg -y -stats -loglevel level+error -i \"$filename.$extension\" -c:v copy -pass 2 -filter:a loudnorm=linear=true:I=-16:LRA=11:tp=-1.5:measured_I=$ii:measured_LRA=$ilra:measured_tp=$itp:measured_thresh=$it:offset=$to:print_format=summary -map 0 \"$output\""
printf "${BOLD}Re-encoding audio:\n$cmd\n\n${NORMAL}"
eval $cmd

View File

@ -43,7 +43,7 @@ fi
printf "\n${YELLOW}${BOLD}Removing audio from '$filename.$extension' | output: '$output'${NORMAL}\n"
# -an removes the audio.
ffmpeg -i "$filename.$extension" -c:v copy -an -map 0 "$output"
ffmpeg -y -stats -loglevel level+error -i "$filename.$extension" -c:v copy -an -map 0 "$output"
printf "\n${GREEN}${BOLD}Done removing audio from '$filename.$extension' | output: '$output'${NORMAL}\n\n"

View File

@ -53,7 +53,7 @@ model="$3"
threads=$4
if [[ $input_wav == "" || $output_name_without_ext == "" || $model == "" ]]; then
printf "${BOLD}${RED}Usage: $0 <input.wav> <output name without extension> <model name> <optional: thread count>${NORMAL}\n"
printf "${BOLD}${RED}Usage: transcribe-audio <input.wav> <output name without extension> <model name> <optional: thread count>${NORMAL}\n"
exit 1
fi

View File

@ -29,7 +29,7 @@ shift 2
models=("$@")
if [[ $input_video == "" || $output_name_without_ext == "" || ${#models[@]} -eq 0 ]]; then
printf "${BOLD}${RED}Usage: $0 <input.mp4> <output name without extension> <list of model names to use>${NORMAL}\n"
printf "${BOLD}${RED}Usage: transcribe-video <input.mp4> <output name without extension> <list of model names to use>${NORMAL}\n"
exit 1
fi
@ -43,7 +43,9 @@ if [[ input_extension != "wav" ]]; then
wav_name="${wav_name}.wav"
fi
extract-16bit-wav-from-video "$input_video" "$wav_name"
channel_count=1
sample_rate=16000
extract-audio-from-video-and-transcode "$input_video" "$wav_name" $sample_rate $channel_count
if [[ $? == 1 ]]; then exit 1; fi
for model in "$@"; do

View File

@ -42,10 +42,7 @@ timing_args="-ss $start_time -to $end_time"
printf "\n${YELLOW}${BOLD}Trimming '$filename.$extension' | output: $output | start: $start_time | end: $end_time${NORMAL}\n"
# You might have issues if the file has multiple video streams or embedded subtitles. The -map 0 arg is typically given
# when copying a video stream, but I'm not sure if it's appropriate to use here.
# Trying out async to keep video and audio synced.
ffmpeg -y -stats -loglevel level+error $timing_args -accurate_seek -async 1 -i "$filename.$extension" -c copy "$output"
ffmpeg -y -stats -loglevel level+error $timing_args -accurate_seek -i "$filename.$extension" -c copy "$output"
printf "\n${GREEN}${BOLD}Finished trimming${NORMAL}\n\n"