Add a script to extract audio from a video

This commit is contained in:
Michael Campagnaro 2022-02-07 10:22:42 -05:00
parent 09d69f997b
commit 8b634e3841
2 changed files with 55 additions and 3 deletions

View File

@ -0,0 +1,55 @@
#!/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
transcode="$1"
filename=$(basename -- "$2")
format="$3"
bitrate="$4"
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"
exit 1
fi
extension="${filename##*.}"
filename="${filename%.*}"
output_name="$filename.$format"
if [[ $bitrate == "" ]]; then
bitrate="64"
fi
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
printf "\n${GREEN}${BOLD}Done extracting audio from '$filename.$extension' | output name '$output_name'${NORMAL}\n\n"

3
vimrc
View File

@ -374,9 +374,6 @@ augroup campoCmds
" Jump to last cursor position unless it's invalid or in an event handler. " Jump to last cursor position unless it's invalid or in an event handler.
autocmd BufReadPost * if line("'\"") > 1 && line("'\"") <= line("$") | exe "normal! g`\"" | endif autocmd BufReadPost * if line("'\"") > 1 && line("'\"") <= line("$") | exe "normal! g`\"" | endif
" Indent HTML <p> tags.
autocmd FileType html,eruby if g:html_indent_tags !~ '\\|p\>' | let g:html_indent_tags .= '\|p\|li\|dt\|dd' | endif
" Properly indent schemes (scheme, racket, etc). " Properly indent schemes (scheme, racket, etc).
autocmd BufRead,BufNewFile *.{lisp,scm,rkt} setlocal equalprg=scmindent.rkt autocmd BufRead,BufNewFile *.{lisp,scm,rkt} setlocal equalprg=scmindent.rkt