tc-video-custom: various fixes
parent
78ac5b0dcc
commit
5836eb3586
|
@ -1,51 +1,36 @@
|
|||
#!/bin/sh
|
||||
|
||||
if [ -z "$(command -v ffmpeg)" ]; then
|
||||
echo "ffmpeg required."
|
||||
exit
|
||||
fi
|
||||
|
||||
_transcode ()
|
||||
{
|
||||
## Zsh compatibility. We need it otherwise word splitting of parameter like
|
||||
## TC_SAMPLE will not work.
|
||||
STATUS="$(set -o | grep 'shwordsplit' | awk '{print $2}')"
|
||||
[ "$STATUS" = "off" ] && set -o shwordsplit
|
||||
|
||||
ffmpeg -i "$@" \
|
||||
-c:v libx264 -preset slow -crf 20 \
|
||||
-c:a libvorbis -b:a 192k -ac 2 \
|
||||
-c:s copy \
|
||||
-map 0 \
|
||||
$TC_SAMPLE \
|
||||
"${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.
|
||||
[ "$STATUS" = "off" ] && set +o shwordsplit
|
||||
}
|
||||
|
||||
|
||||
_printhelp()
|
||||
{
|
||||
cat <<EOF
|
||||
Usage: ${1##*/} [-f] [FILES]
|
||||
Usage: ${1##*/} MODE
|
||||
|
||||
Transcode FILES using custom FFmpeg command. By default FFmpeg will only encode
|
||||
a sample for preview purpose. Use the '-f' flag to process the complete file.
|
||||
Edit this file to fit your needs and learn more about FFmpeg.
|
||||
This script was generated with tc-video-custom.
|
||||
|
||||
It transcodes the embedded list of files using FFmpeg. MODE will specify what
|
||||
kind of output you want. Edit this file to fit your needs and learn more about
|
||||
FFmpeg.
|
||||
|
||||
Modes:
|
||||
|
||||
-e: Excerpt of 1 minute starting at 1 minute.
|
||||
-f: Full video.
|
||||
|
||||
EOF
|
||||
}
|
||||
|
||||
TC_SAMPLE="-ss 60 -t 360"
|
||||
while getopts ":hf" opt; do
|
||||
TC_SAMPLE=""
|
||||
OPT_PROCESS=false
|
||||
while getopts ":hef" opt; do
|
||||
case $opt in
|
||||
h)
|
||||
_printhelp "$0"
|
||||
exit 1 ;;
|
||||
e)
|
||||
TC_SAMPLE="-ss 60 -t 60"
|
||||
OPT_PROCESS=true ;;
|
||||
f)
|
||||
TC_SAMPLE="" ;;
|
||||
OPT_PROCESS=true ;;
|
||||
?)
|
||||
_printhelp "$0"
|
||||
exit 1 ;;
|
||||
|
@ -58,14 +43,48 @@ done
|
|||
|
||||
shift $(($OPTIND - 1))
|
||||
|
||||
if ! $OPT_PROCESS; then
|
||||
_printhelp "$0"
|
||||
exit
|
||||
fi
|
||||
|
||||
if [ -z "$(command -v ffmpeg)" ]; then
|
||||
echo "ffmpeg required."
|
||||
exit
|
||||
fi
|
||||
|
||||
_transcode ()
|
||||
{
|
||||
## Zsh compatibility. We need it otherwise word splitting of parameter will
|
||||
## not work.
|
||||
STATUS="$(set -o | grep 'shwordsplit' | awk '{print $2}')"
|
||||
[ "$STATUS" = "off" ] && set -o shwordsplit
|
||||
|
||||
## You can choose here to process all files at the same time. Useful if you
|
||||
## need to remux streams or to concatenate.
|
||||
# ffmpeg -i ###FILELIST \
|
||||
ffmpeg -i "$@" \
|
||||
-c:v libx264 -preset slow -crf 20 \
|
||||
-c:a libvorbis -b:a 192k -ac 2 \
|
||||
-c:s copy \
|
||||
-map 0 \
|
||||
$SAMPLE \
|
||||
"${1%.*}-$(date '+%F-%H%M%S').mkv" </dev/null
|
||||
|
||||
## Restore Zsh previous options. This will not turn off shwordsplit if it
|
||||
## was on before calling the function.
|
||||
[ "$STATUS" = "off" ] && set +o shwordsplit
|
||||
}
|
||||
|
||||
## Choose to process all files one after another.
|
||||
while read -r i; do
|
||||
while IFS= read -r i; do
|
||||
_transcode "$i"
|
||||
done<<FILELINES
|
||||
FILELINES
|
||||
|
||||
## Or in one batch
|
||||
# _transcode ###FILELIST
|
||||
## Or all files at the same time. You ahve to change the ffmpeg input in the
|
||||
## function.
|
||||
# _transcode
|
||||
|
||||
################################################################################
|
||||
## USE CASES
|
||||
|
@ -88,6 +107,10 @@ FILELINES
|
|||
## Add a delay to audio (assuming stream 0 is video and stream 1 is audio)
|
||||
## -i "$1" -itsoffset 0.300 -i "$1" -map 0:0 -map 1:1
|
||||
##
|
||||
## Insert stream 3 from file2 between all non-audio streams and audio streams of
|
||||
## file1:
|
||||
## -i "file1" -i "file2" -map -0:a map 1:3 -map 0:a
|
||||
##
|
||||
## Concatenate files. See
|
||||
## https://trac.ffmpeg.org/wiki/How%20to%20concatenate%20(join,%20merge)%20media%20files
|
||||
## for more details
|
||||
|
|
|
@ -1,12 +1,14 @@
|
|||
#!/bin/sh
|
||||
|
||||
OUTPUT_NAME="tc-video"
|
||||
|
||||
_printhelp()
|
||||
{
|
||||
cat <<EOF
|
||||
Usage: ${1##*/} [FILES]
|
||||
|
||||
Create a 'tc-video' script in current folder. The script provides a FFmpeg call
|
||||
command with some useful options and instructive help.
|
||||
Create a '$OUTPUT_NAME' script in current folder. The script provides a FFmpeg call
|
||||
to transcode FILES with some useful options and instructive help.
|
||||
|
||||
FILES realpath will be included into the script.
|
||||
|
||||
|
@ -15,8 +17,8 @@ This script is meant to be easily editable to fit the user needs.
|
|||
EOF
|
||||
}
|
||||
|
||||
if [ "$1" = "-h" ]; then
|
||||
_printhelp "$0"
|
||||
if [ $# -eq 0 ] || [ "$1" = "-h" ]; then
|
||||
_printhelp "$0"
|
||||
exit
|
||||
fi
|
||||
|
||||
|
@ -25,25 +27,17 @@ if [ -z "$(command -v realpath)" ]; then
|
|||
exit
|
||||
fi
|
||||
|
||||
|
||||
for i ; do
|
||||
REAL="$(realpath "$i")"
|
||||
FILELIST="${FILELIST:+$FILELIST }'$REAL'"
|
||||
done
|
||||
|
||||
SCRIPT_PATH="${0%/*}"
|
||||
SCRIPT_NAME="${0##*/}"
|
||||
OUTPUT_NAME="tc-video"
|
||||
FILELIST=""
|
||||
if [ -f "$SCRIPT_PATH/.$SCRIPT_NAME.in" ]; then
|
||||
cp -i "$SCRIPT_PATH/.$SCRIPT_NAME.in" "$OUTPUT_NAME"
|
||||
# echo "$FILELIST"
|
||||
# echo "$FILELINES"
|
||||
sed -i 's|###FILELIST|'"$FILELIST"'|' "$OUTPUT_NAME"
|
||||
for i ; do
|
||||
REAL="$(realpath "$i")"
|
||||
sed -i "s|# FILELINES|# $REAL\n# FILELINES|" "$OUTPUT_NAME"
|
||||
FILELIST="${FILELIST:+$FILELIST -i }'$REAL'"
|
||||
sed -i "s|^FILELINES|$REAL\nFILELINES|" "$OUTPUT_NAME"
|
||||
done
|
||||
sed -i "s|###FILELINES||" "$OUTPUT_NAME"
|
||||
sed -i 's|###FILELIST|'"$FILELIST"'|' "$OUTPUT_NAME"
|
||||
chmod +x "$OUTPUT_NAME"
|
||||
else
|
||||
echo ".$SCRIPT_NAME.in not found!"
|
||||
|
|
Loading…
Reference in New Issue