Shell: transcoding parameters, merged splice into transcode.

master
Pierre Neidhardt 2013-01-20 23:25:29 +01:00
parent 5e83fa6273
commit 22e0e39a7c
4 changed files with 77 additions and 36 deletions

View File

@ -23,6 +23,5 @@ source "${SHELL_DIR}/options_bash"
## Source order should not matter.
source "${SHELL_DIR}/alias_rc"
source "${SHELL_DIR}/funs_rc"
source "${SHELL_DIR}/funs_transcode"
source "${SHELL_DIR}/funs_bash"
source "${SHELL_DIR}/personal_rc"

View File

@ -849,13 +849,13 @@ formatc()
}
##==============================================================================
## Pacman Functions
## Pacman functions
##==============================================================================
[ -n "$(command -v pacman)" ] && . "${SHELL_DIR}/funs_pacman"
##==============================================================================
## FreeBSD Functions
## FreeBSD functions
##==============================================================================
[ "$(uname)" = FreeBSD ] && . "${SHELL_DIR}/funs_freebsd"
@ -882,3 +882,9 @@ if [ -d "/usr/local/texlive" ]; then
sudo sh -c 'umask 022 && tlmgr remove $0 $@' "$@"
}
fi
##==============================================================================
## Transcoding functions
##==============================================================================
[ -n "$(command -v ffmpeg)" ] && . "${SHELL_DIR}/funs_transcode"

View File

@ -87,12 +87,6 @@ tc_text_2utf8 ()
TC_AUDIO_QUAL=192k
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
# ultrafast, superfast, veryfast, faster, fast, medium, slow, slower, veryslow, placebo
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"
}
tc_splice()
tc_transcode()
{
## Note: we put the time options *before* the input file so that it uses
## keyframes, thus being much faster butless accurate.
_tc_splice()
_printhelp()
{
echo "================================================================================"
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 "Synopsis:"
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
tc_splice .
tc_transcode .
return
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
if [ -d "$i" ]; then
local IFS
IFS="
"
## TODO: provide max-depth as option.
for i in $(find "$i" \( \
-iname '*.mkv' -o \
@ -158,37 +210,22 @@ tc_splice()
-iname '*.flv' -o \
-iname '*.wmv' -o \
-iname '*.mpg' \) ); do
_tc_splice $i
_tc_transcode $i
done
else
_tc_splice "$i"
_tc_transcode "$i"
fi
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
## was on before calling the function.
if [ "$STATUS" = "off" ]; then
set +o shwordsplit
fi
}
# tc_mux()

1
.zshrc
View File

@ -18,7 +18,6 @@ source "${SHELL_DIR}/options_zsh"
source "${SHELL_DIR}/alias_rc"
source "${SHELL_DIR}/colors_zsh"
source "${SHELL_DIR}/funs_rc"
source "${SHELL_DIR}/funs_transcode"
source "${SHELL_DIR}/keys_zsh"
source "${SHELL_DIR}/personal_rc"