Shell: transcoding parameters, merged splice into transcode.
parent
5e83fa6273
commit
22e0e39a7c
1
.bashrc
1
.bashrc
|
@ -23,6 +23,5 @@ source "${SHELL_DIR}/options_bash"
|
||||||
## Source order should not matter.
|
## Source order should not matter.
|
||||||
source "${SHELL_DIR}/alias_rc"
|
source "${SHELL_DIR}/alias_rc"
|
||||||
source "${SHELL_DIR}/funs_rc"
|
source "${SHELL_DIR}/funs_rc"
|
||||||
source "${SHELL_DIR}/funs_transcode"
|
|
||||||
source "${SHELL_DIR}/funs_bash"
|
source "${SHELL_DIR}/funs_bash"
|
||||||
source "${SHELL_DIR}/personal_rc"
|
source "${SHELL_DIR}/personal_rc"
|
||||||
|
|
|
@ -849,13 +849,13 @@ formatc()
|
||||||
}
|
}
|
||||||
|
|
||||||
##==============================================================================
|
##==============================================================================
|
||||||
## Pacman Functions
|
## Pacman functions
|
||||||
##==============================================================================
|
##==============================================================================
|
||||||
|
|
||||||
[ -n "$(command -v pacman)" ] && . "${SHELL_DIR}/funs_pacman"
|
[ -n "$(command -v pacman)" ] && . "${SHELL_DIR}/funs_pacman"
|
||||||
|
|
||||||
##==============================================================================
|
##==============================================================================
|
||||||
## FreeBSD Functions
|
## FreeBSD functions
|
||||||
##==============================================================================
|
##==============================================================================
|
||||||
|
|
||||||
[ "$(uname)" = FreeBSD ] && . "${SHELL_DIR}/funs_freebsd"
|
[ "$(uname)" = FreeBSD ] && . "${SHELL_DIR}/funs_freebsd"
|
||||||
|
@ -882,3 +882,9 @@ if [ -d "/usr/local/texlive" ]; then
|
||||||
sudo sh -c 'umask 022 && tlmgr remove $0 $@' "$@"
|
sudo sh -c 'umask 022 && tlmgr remove $0 $@' "$@"
|
||||||
}
|
}
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
##==============================================================================
|
||||||
|
## Transcoding functions
|
||||||
|
##==============================================================================
|
||||||
|
|
||||||
|
[ -n "$(command -v ffmpeg)" ] && . "${SHELL_DIR}/funs_transcode"
|
||||||
|
|
|
@ -87,12 +87,6 @@ tc_text_2utf8 ()
|
||||||
TC_AUDIO_QUAL=192k
|
TC_AUDIO_QUAL=192k
|
||||||
TC_OUTDIR="$HOME/temp"
|
TC_OUTDIR="$HOME/temp"
|
||||||
|
|
||||||
## TODO: as parameter instead.
|
|
||||||
## What to do if file exists:
|
|
||||||
# -y overwrite
|
|
||||||
# -n do not overwrite.
|
|
||||||
TC_OVERWRITE=-n
|
|
||||||
|
|
||||||
## quality*size ~= 1/speed
|
## quality*size ~= 1/speed
|
||||||
# ultrafast, superfast, veryfast, faster, fast, medium, slow, slower, veryslow, placebo
|
# ultrafast, superfast, veryfast, faster, fast, medium, slow, slower, veryslow, placebo
|
||||||
TC_VIDEO_PRESET=slow
|
TC_VIDEO_PRESET=slow
|
||||||
|
@ -127,28 +121,86 @@ tc_audio()
|
||||||
ffmpeg -threads 4 $TC_OVERWRITE -i "$1" -vn -c:a libvorbis -b:a $TC_AUDIO_QUAL "${1%.*}-$(date "+%F-%H%M%S").ogg"
|
ffmpeg -threads 4 $TC_OVERWRITE -i "$1" -vn -c:a libvorbis -b:a $TC_AUDIO_QUAL "${1%.*}-$(date "+%F-%H%M%S").ogg"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
tc_transcode()
|
||||||
tc_splice()
|
|
||||||
{
|
{
|
||||||
## Note: we put the time options *before* the input file so that it uses
|
_printhelp()
|
||||||
## keyframes, thus being much faster butless accurate.
|
|
||||||
_tc_splice()
|
|
||||||
{
|
{
|
||||||
echo "================================================================================"
|
echo "Synopsis:"
|
||||||
ffmpeg $TC_OVERWRITE -ss 60 -t 600 -i "$1" -c:v copy -c:a copy -c:s copy -map 0 "${1%.*}-$(date "+%F-%H%M%S").${1##*.}"
|
echo -e " $1 [-f|-h|-s] FILES"
|
||||||
|
echo
|
||||||
|
echo "Usage:"
|
||||||
|
echo -e " default:\tTranscode FILES to .mkv with x264 and ogg. Output files are the same as the original, with time appended. You can customize encoding with the TC_* variables."
|
||||||
|
echo -e " -f:\t\tOverwrite existing file if any."
|
||||||
|
echo -e " -h:\t\tDisplay this help."
|
||||||
|
echo -e " -s:\t\tSample of ten minutes."
|
||||||
}
|
}
|
||||||
|
|
||||||
|
## What to do if file exists:
|
||||||
|
# -y overwrite
|
||||||
|
# -n do not overwrite.
|
||||||
|
local TC_OVERWRITE
|
||||||
|
TC_OVERWRITE=-n
|
||||||
|
|
||||||
|
local TC_SAMPLE
|
||||||
|
TC_SAMPLE=""
|
||||||
|
|
||||||
|
while getopts ":fhs" opt; do
|
||||||
|
case $opt in
|
||||||
|
f)
|
||||||
|
TC_OVERWRITE=-y
|
||||||
|
;;
|
||||||
|
h)
|
||||||
|
_printhelp "$0"
|
||||||
|
return 1
|
||||||
|
;;
|
||||||
|
s)
|
||||||
|
TC_SAMPLE="-ss 60 -t 600 -i"
|
||||||
|
;;
|
||||||
|
?)
|
||||||
|
_printhelp "$0"
|
||||||
|
return 1
|
||||||
|
;;
|
||||||
|
:)
|
||||||
|
echo "Missing argument."
|
||||||
|
echo "Use $0 -h for help."
|
||||||
|
return 1
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
|
||||||
|
shift $(($OPTIND - 1))
|
||||||
|
|
||||||
|
|
||||||
|
## Zsh compatibility
|
||||||
|
local STATUS
|
||||||
|
STATUS="$(set -o | grep 'shwordsplit' | awk '{print $2}')"
|
||||||
|
if [ "$STATUS" = "off" ]; then
|
||||||
|
set -o shwordsplit
|
||||||
|
fi
|
||||||
|
|
||||||
|
|
||||||
if [ $# -eq 0 ]; then
|
if [ $# -eq 0 ]; then
|
||||||
tc_splice .
|
tc_transcode .
|
||||||
return
|
return
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
_tc_transcode()
|
||||||
|
{
|
||||||
|
echo "================================================================================"
|
||||||
|
ffmpeg $TC_OVERWRITE $TC_SAMPLE -i "$1" \
|
||||||
|
-c:v libx264 -preset $TC_VIDEO_PRESET -crf $TC_VIDEO_QUAL $TC_VIDEO_TUNE $TC_VIDEO_OPTS \
|
||||||
|
-c:a libvorbis -b:a $TC_AUDIO_QUAL \
|
||||||
|
-c:s copy \
|
||||||
|
-map 0 "${1%.*}-$(date "+%F-%H%M%S").mkv"
|
||||||
|
}
|
||||||
|
|
||||||
for i in "$@"; do
|
for i in "$@"; do
|
||||||
if [ -d "$i" ]; then
|
if [ -d "$i" ]; then
|
||||||
|
|
||||||
local IFS
|
local IFS
|
||||||
IFS="
|
IFS="
|
||||||
"
|
"
|
||||||
|
|
||||||
## TODO: provide max-depth as option.
|
## TODO: provide max-depth as option.
|
||||||
for i in $(find "$i" \( \
|
for i in $(find "$i" \( \
|
||||||
-iname '*.mkv' -o \
|
-iname '*.mkv' -o \
|
||||||
|
@ -158,37 +210,22 @@ tc_splice()
|
||||||
-iname '*.flv' -o \
|
-iname '*.flv' -o \
|
||||||
-iname '*.wmv' -o \
|
-iname '*.wmv' -o \
|
||||||
-iname '*.mpg' \) ); do
|
-iname '*.mpg' \) ); do
|
||||||
_tc_splice $i
|
_tc_transcode $i
|
||||||
done
|
done
|
||||||
|
|
||||||
else
|
else
|
||||||
_tc_splice "$i"
|
_tc_transcode "$i"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
done
|
done
|
||||||
}
|
|
||||||
|
|
||||||
## TODO: splice should be a parameter for transcode.
|
|
||||||
tc_transcode()
|
|
||||||
{
|
|
||||||
## Zsh compatibility
|
|
||||||
local STATUS="$(set -o | grep 'shwordsplit' | awk '{print $2}')"
|
|
||||||
if [ "$STATUS" = "off" ]; then
|
|
||||||
set -o shwordsplit
|
|
||||||
fi
|
|
||||||
|
|
||||||
echo "================================================================================"
|
|
||||||
ffmpeg $TC_OVERWRITE -i "$1" \
|
|
||||||
-c:v libx264 -preset $TC_VIDEO_PRESET -crf $TC_VIDEO_QUAL $TC_VIDEO_TUNE $TC_VIDEO_OPTS \
|
|
||||||
-c:a libvorbis -b:a $TC_AUDIO_QUAL \
|
|
||||||
-c:s copy \
|
|
||||||
-map 0 "${1%.*}-$(date "+%F-%H%M%S").mkv"
|
|
||||||
|
|
||||||
## Restore Zsh previous options. This will not turn off shwordsplit if it
|
## Restore Zsh previous options. This will not turn off shwordsplit if it
|
||||||
## was on before calling the function.
|
## was on before calling the function.
|
||||||
if [ "$STATUS" = "off" ]; then
|
if [ "$STATUS" = "off" ]; then
|
||||||
set +o shwordsplit
|
set +o shwordsplit
|
||||||
fi
|
fi
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
# tc_mux()
|
# tc_mux()
|
||||||
|
|
1
.zshrc
1
.zshrc
|
@ -18,7 +18,6 @@ source "${SHELL_DIR}/options_zsh"
|
||||||
source "${SHELL_DIR}/alias_rc"
|
source "${SHELL_DIR}/alias_rc"
|
||||||
source "${SHELL_DIR}/colors_zsh"
|
source "${SHELL_DIR}/colors_zsh"
|
||||||
source "${SHELL_DIR}/funs_rc"
|
source "${SHELL_DIR}/funs_rc"
|
||||||
source "${SHELL_DIR}/funs_transcode"
|
|
||||||
source "${SHELL_DIR}/keys_zsh"
|
source "${SHELL_DIR}/keys_zsh"
|
||||||
source "${SHELL_DIR}/personal_rc"
|
source "${SHELL_DIR}/personal_rc"
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue