Support a time range in the transcribe video scripts
This commit is contained in:
parent
90c312e954
commit
ba9a776867
25
.aliases
25
.aliases
|
@ -354,36 +354,51 @@ function my_transcribe_video() {
|
||||||
file="$1"
|
file="$1"
|
||||||
output="$2"
|
output="$2"
|
||||||
include_small=$3
|
include_small=$3
|
||||||
|
start_time="$4"
|
||||||
|
end_time="$5"
|
||||||
|
|
||||||
if [[ $file == "" ]]; then
|
if [[ $file == "" ]]; then
|
||||||
error "Usage: <input video> <optional output name>"
|
error "Usage: <input video> <optional output name> <optional include small model (1 or 0)> <optional start time> <optional end time>"
|
||||||
return
|
return
|
||||||
fi
|
fi
|
||||||
if [[ $output == "" ]]; then
|
if [[ $output == "" ]]; then
|
||||||
output="${1%.*}" # just use the input name without the extension.
|
output="${1%.*}" # just use the input name without the extension.
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
if [[ $start_time == "" ]]; then start_time="0"; fi
|
||||||
|
if [[ $end_time == "" ]]; then end_time="0"; fi
|
||||||
|
|
||||||
# Tiny is fast and semi-accurate, so whatever.
|
# Tiny is fast and semi-accurate, so whatever.
|
||||||
# Base is pretty good overall. It has good punctuation inserting and
|
# Base is pretty good overall. It has good punctuation inserting and
|
||||||
# catches most words. Small and medium can do better word detection at
|
# catches most words. Small and medium can do better word detection at
|
||||||
# times, but suffer from bad punctuation. Medium is particularly bad and
|
# times, but suffer from bad punctuation. Medium is particularly bad and
|
||||||
# not adding commas and periods.
|
# not adding commas and periods.
|
||||||
if [[ $include_small -eq 1 ]]; then
|
if [[ $include_small -eq 1 ]]; then
|
||||||
transcribe-video "$file" "$output" tiny base small
|
transcribe-video "$file" "$output" $start_time $end_time tiny base small
|
||||||
else
|
else
|
||||||
transcribe-video "$file" "$output" tiny base
|
transcribe-video "$file" "$output" $start_time $end_time tiny base
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
function my_transcribe_video_all_models() {
|
function my_transcribe_video_all_models() {
|
||||||
file="$1"
|
file="$1"
|
||||||
output="$2"
|
output="$2"
|
||||||
|
start_time="$3"
|
||||||
|
end_time="$4"
|
||||||
|
|
||||||
if [[ $file == "" ]]; then
|
if [[ $file == "" ]]; then
|
||||||
error "Usage: <input video> <optional output name>"
|
error "Usage: <input video> <optional output name> <optional start time> <optional end time>"
|
||||||
return
|
return
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [[ $output == "" ]]; then
|
if [[ $output == "" ]]; then
|
||||||
output="${1%.*}" # just use the input name without the extension.
|
output="${1%.*}" # just use the input name without the extension.
|
||||||
fi
|
fi
|
||||||
transcribe-video "$file" "$output" tiny base small medium
|
|
||||||
|
if [[ $start_time == "" ]]; then start_time="0"; fi
|
||||||
|
if [[ $end_time == "" ]]; then end_time="0"; fi
|
||||||
|
|
||||||
|
transcribe-video "$file" "$output" $start_time $end_time tiny base small medium
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -26,7 +26,7 @@ fi
|
||||||
use_gpu=0
|
use_gpu=0
|
||||||
|
|
||||||
if [[ "$#" < 3 || "$#" > 6 ]]; then
|
if [[ "$#" < 3 || "$#" > 6 ]]; then
|
||||||
printf "${BOLD}${RED}Usage: $0 <crf value> <filename> <output name> <optional: use-gpu (1|0), defaults to $use_gpu> <optional: start time HH:MM:SS> <optional: end time HH:MM:SS>\n\nIf you want to encode a range of CRF values then use -1 as the crf value.${NORMAL}\n"
|
printf "${BOLD}${RED}Usage: compress-video-with-crf <crf value> <filename> <output name> <optional: use-gpu (1|0), defaults to $use_gpu> <optional: start time HH:MM:SS> <optional: end time HH:MM:SS>\n\nIf you want to encode a range of CRF values then use -1 as the crf value.${NORMAL}\n"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
|
@ -29,7 +29,7 @@ else
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [[ $1 == "" || $2 == "" ]]; then
|
if [[ $1 == "" || $2 == "" ]]; then
|
||||||
printf "${BOLD}${RED}Usage: $0 <filename> <bitrate, e.g. \"4000k\"> <optional output name>${NORMAL}\n"
|
printf "${BOLD}${RED}Usage: convert-video-avi-to-mp4 <filename> <bitrate, e.g. \"4000k\"> <optional output name>${NORMAL}\n"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
|
@ -27,7 +27,7 @@ else
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [[ $1 == "" || $2 == "" ]]; then
|
if [[ $1 == "" || $2 == "" ]]; then
|
||||||
printf "${BOLD}${RED}Usage: $0 <compress 1|0> <filename> <optional output name>${NORMAL}\n"
|
printf "${BOLD}${RED}Usage: convert-video-flv-to-mp4 <compress 1|0> <filename> <optional output name>${NORMAL}\n"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
|
@ -27,7 +27,7 @@ else
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [[ $1 == "" || $2 == "" ]]; then
|
if [[ $1 == "" || $2 == "" ]]; then
|
||||||
printf "${BOLD}${RED}Usage: $0 <compress 1|0> <filename> <optional output name>${NORMAL}\n"
|
printf "${BOLD}${RED}Usage: convert-video-mkv-to-mp4 <compress 1|0> <filename> <optional output name>${NORMAL}\n"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
|
@ -30,9 +30,11 @@ fi
|
||||||
|
|
||||||
filename=$(basename -- "$1")
|
filename=$(basename -- "$1")
|
||||||
format="$2"
|
format="$2"
|
||||||
|
start_time="$3"
|
||||||
|
end_time="$4"
|
||||||
|
|
||||||
if [[ $1 == "" || $2 == "" ]]; then
|
if [[ $1 == "" || $2 == "" ]]; then
|
||||||
printf "${BOLD}${RED}Usage: extract-audio-from-video <filename> <format (mp3, m4a, aac, etc)>${NORMAL}\n"
|
printf "${BOLD}${RED}Usage: extract-audio-from-video <filename> <format (mp3, m4a, aac, etc)> <optional: start time HH:MM:SS, use empty string or 0 for start> <optional: end time HH:MM:SS, use empty string or 0 for no value>${NORMAL}\n"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
@ -40,9 +42,23 @@ extension="${filename##*.}"
|
||||||
filename="${filename%.*}"
|
filename="${filename%.*}"
|
||||||
output_name="$filename.$format"
|
output_name="$filename.$format"
|
||||||
|
|
||||||
printf "\n${YELLOW}${BOLD}Extracting audio from $filename.$extension | output: $output_name${NORMAL}\n"
|
timing_args=""
|
||||||
|
if [[ $start_time != "" ]]; then
|
||||||
|
timing_args="-ss $start_time "
|
||||||
|
fi
|
||||||
|
if [[ $end_time != "" ]]; then
|
||||||
|
if [[ $start_time == "0" && $end_time == "0" ]]; then
|
||||||
|
# We treat a start and end with 0 values as no op.
|
||||||
|
timing_args=""
|
||||||
|
elif [[ $end_time != "0" ]]; then
|
||||||
|
# Handle having a start time but end time is set to 0, can just ignore it and it'll use the remainder of the video.
|
||||||
|
timing_args+="-to $end_time"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
ffmpeg -y -stats -loglevel level+error -i "$filename.$extension" -vn -acodec copy "$output_name"
|
printf "\n${YELLOW}${BOLD}Extracting audio from $filename.$extension | output: $output_name | start: $start_time | end: $end_time${NORMAL}\n"
|
||||||
|
|
||||||
|
ffmpeg -y -stats -loglevel level+error $timing_args -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"
|
printf "\n${GREEN}${BOLD}Done extracting audio from $filename.$extension | output name '$output_name'${NORMAL}\n\n"
|
||||||
|
|
||||||
|
|
|
@ -37,7 +37,7 @@ output_base=$(basename -- "$output_name")
|
||||||
output_extension="${output_base##*.}"
|
output_extension="${output_base##*.}"
|
||||||
|
|
||||||
if [[ $filename == "" || $output_extension == "" || $output_extension == $output_base ]]; then
|
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"
|
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, use empty string or 0 for start> <optional: end time HH:MM:SS, use empty string or 0 for no value>${NORMAL}\n"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
@ -54,7 +54,13 @@ if [[ $start_time != "" ]]; then
|
||||||
timing_args="-ss $start_time "
|
timing_args="-ss $start_time "
|
||||||
fi
|
fi
|
||||||
if [[ $end_time != "" ]]; then
|
if [[ $end_time != "" ]]; then
|
||||||
timing_args+="-to $end_time"
|
if [[ $start_time == "0" && $end_time == "0" ]]; then
|
||||||
|
# We treat a start and end with 0 values as no op.
|
||||||
|
timing_args=""
|
||||||
|
elif [[ $end_time != "0" ]]; then
|
||||||
|
# Handle having a start time but end time is set to 0, can just ignore it and it'll use the remainder of the video.
|
||||||
|
timing_args+="-to $end_time"
|
||||||
|
fi
|
||||||
fi
|
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"
|
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"
|
||||||
|
|
|
@ -27,7 +27,7 @@ else
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [[ $1 == "" ]]; then
|
if [[ $1 == "" ]]; then
|
||||||
printf "${BOLD}${RED}Usage: $0 <filename> <optional output name>${NORMAL}\n"
|
printf "${BOLD}${RED}Usage: fix-audio-in-one-channel <filename> <optional output name>${NORMAL}\n"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
|
@ -31,7 +31,7 @@ else
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [[ $1 == "" ]]; then
|
if [[ $1 == "" ]]; then
|
||||||
printf "${BOLD}${RED}Usage: $0 <filename> <optional output name>${NORMAL}\n"
|
printf "${BOLD}${RED}Usage: normalize-video-volume <filename> <optional output name>${NORMAL}\n"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
|
@ -24,7 +24,7 @@ else
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [[ $1 == "" ]]; then
|
if [[ $1 == "" ]]; then
|
||||||
printf "${BOLD}${RED}Usage: $0 <filename> <optional output name>${NORMAL}\n"
|
printf "${BOLD}${RED}Usage: remove-audio-from-video <filename> <optional output name>${NORMAL}\n"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
|
@ -25,11 +25,13 @@ fi
|
||||||
|
|
||||||
input_video="$1"
|
input_video="$1"
|
||||||
output_name_without_ext="$2"
|
output_name_without_ext="$2"
|
||||||
shift 2
|
start_time="$3"
|
||||||
|
end_time="$4"
|
||||||
|
shift 4
|
||||||
models=("$@")
|
models=("$@")
|
||||||
|
|
||||||
if [[ $input_video == "" || $output_name_without_ext == "" || ${#models[@]} -eq 0 ]]; then
|
if [[ $input_video == "" || $output_name_without_ext == "" || $start_time == "" || $end_time == "" || ${#models[@]} -eq 0 ]]; then
|
||||||
printf "${BOLD}${RED}Usage: transcribe-video <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> <start time HH:MM:SS, use 0 for start> <end time HH:MM:SS, use 0 for no value> <list of model names to use>${NORMAL}\n"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
@ -45,7 +47,7 @@ fi
|
||||||
|
|
||||||
channel_count=1
|
channel_count=1
|
||||||
sample_rate=16000
|
sample_rate=16000
|
||||||
extract-audio-from-video-and-transcode "$input_video" "$wav_name" $sample_rate $channel_count
|
extract-audio-from-video-and-transcode "$input_video" "$wav_name" $sample_rate $channel_count $start_time $end_time
|
||||||
if [[ $? == 1 ]]; then exit 1; fi
|
if [[ $? == 1 ]]; then exit 1; fi
|
||||||
|
|
||||||
for model in "$@"; do
|
for model in "$@"; do
|
||||||
|
|
|
@ -1,2 +1,37 @@
|
||||||
#!/usr/bin/env bash
|
#!/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
|
||||||
|
|
||||||
|
if [[ $2 == "" ]]; then
|
||||||
|
printf "${BOLD}${RED}Usage: transcribe-video-base <input.mp4> <output name without extension> <optional: start time HH:MM:SS, use 0 for start> <optional: end time HH:MM:SS, use empty string or 0 for no value>${NORMAL}\n"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
start_time="$3"
|
||||||
|
end_time="$4"
|
||||||
|
|
||||||
|
if [[ $start_time == "" ]]; then start_time="0"; fi
|
||||||
|
if [[ $end_time == "" ]]; then end_time="0"; fi
|
||||||
|
|
||||||
transcribe-video "$1" "$2" "base"
|
transcribe-video "$1" "$2" "base"
|
||||||
|
|
|
@ -1,2 +1,37 @@
|
||||||
#!/usr/bin/env bash
|
#!/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
|
||||||
|
|
||||||
|
if [[ $2 == "" ]]; then
|
||||||
|
printf "${BOLD}${RED}Usage: transcribe-video-medium <input.mp4> <output name without extension> <optional: start time HH:MM:SS, use 0 for start> <optional: end time HH:MM:SS, use empty string or 0 for no value>${NORMAL}\n"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
start_time="$3"
|
||||||
|
end_time="$4"
|
||||||
|
|
||||||
|
if [[ $start_time == "" ]]; then start_time="0"; fi
|
||||||
|
if [[ $end_time == "" ]]; then end_time="0"; fi
|
||||||
|
|
||||||
transcribe-video "$1" "$2" "medium"
|
transcribe-video "$1" "$2" "medium"
|
||||||
|
|
|
@ -1,2 +1,37 @@
|
||||||
#!/usr/bin/env bash
|
#!/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
|
||||||
|
|
||||||
|
if [[ $2 == "" ]]; then
|
||||||
|
printf "${BOLD}${RED}Usage: transcribe-video-small <input.mp4> <output name without extension> <optional: start time HH:MM:SS, use 0 for start> <optional: end time HH:MM:SS, use empty string or 0 for no value>${NORMAL}\n"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
start_time="$3"
|
||||||
|
end_time="$4"
|
||||||
|
|
||||||
|
if [[ $start_time == "" ]]; then start_time="0"; fi
|
||||||
|
if [[ $end_time == "" ]]; then end_time="0"; fi
|
||||||
|
|
||||||
transcribe-video "$1" "$2" "small"
|
transcribe-video "$1" "$2" "small"
|
||||||
|
|
|
@ -1,2 +1,37 @@
|
||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
transcribe-video "$1" "$2" "tiny"
|
|
||||||
|
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
|
||||||
|
|
||||||
|
if [[ $2 == "" ]]; then
|
||||||
|
printf "${BOLD}${RED}Usage: transcribe-video-tiny <input.mp4> <output name without extension> <optional: start time HH:MM:SS, use 0 for start> <optional: end time HH:MM:SS, use empty string or 0 for no value>${NORMAL}\n"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
start_time="$3"
|
||||||
|
end_time="$4"
|
||||||
|
|
||||||
|
if [[ $start_time == "" ]]; then start_time="0"; fi
|
||||||
|
if [[ $end_time == "" ]]; then end_time="0"; fi
|
||||||
|
|
||||||
|
transcribe-video "$1" "$2" $start_time $end_time "tiny"
|
||||||
|
|
Loading…
Reference in New Issue
Block a user