Support a time range in the transcribe video scripts

This commit is contained in:
2023-08-07 17:22:07 -04:00
parent 90c312e954
commit ba9a776867
15 changed files with 201 additions and 22 deletions

View File

@@ -30,9 +30,11 @@ fi
filename=$(basename -- "$1")
format="$2"
start_time="$3"
end_time="$4"
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
fi
@@ -40,9 +42,23 @@ extension="${filename##*.}"
filename="${filename%.*}"
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"