175 lines
5.1 KiB
Bash
175 lines
5.1 KiB
Bash
#!/bin/sh
|
|
|
|
_printhelp()
|
|
{
|
|
cat <<EOF
|
|
Usage: ${1##*/} MODE
|
|
|
|
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=""
|
|
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)
|
|
OPT_PROCESS=true ;;
|
|
?)
|
|
_printhelp "$0"
|
|
exit 1 ;;
|
|
:)
|
|
echo "Missing argument."
|
|
_printhelp "$0"
|
|
exit 1 ;;
|
|
esac
|
|
done
|
|
|
|
shift $(($OPTIND - 1))
|
|
|
|
if ! $OPT_PROCESS; then
|
|
_printhelp "$0"
|
|
exit
|
|
fi
|
|
|
|
if ! command -v ffmpeg >/dev/null; 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 -nostdin -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"
|
|
|
|
## 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 IFS= read -r i; do
|
|
_transcode "$i"
|
|
done<<FILELINES
|
|
FILELINES
|
|
|
|
## Or all files at the same time. You ahve to change the ffmpeg input in the
|
|
## function.
|
|
# _transcode
|
|
|
|
################################################################################
|
|
## USE CASES
|
|
##
|
|
## Exchange stream 1 an 2 by first removing them, then reading them in the
|
|
## desired order.
|
|
##
|
|
## -map -0:1 -map -0:2 -map 0:2 -map 0:1
|
|
##
|
|
## Change audio stream 1 title and remove audio stream 2 title:
|
|
##
|
|
## -metadata:s:a:0 title="FR: OGG Stereo" -metadata:s:a:1 title=""
|
|
##
|
|
## Demux audio:
|
|
## -vn -sn -c:a copy -map 0:1
|
|
##
|
|
## Dump audio to an ogg file:
|
|
## -vn -c:a libvorbis -b:a 192k
|
|
##
|
|
## 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
|
|
##
|
|
## -filter_complex '[0:0] [0:1] [1:0] [1:1] concat=n=2:v=1:a=1 [v] [a]' -map '[v]' -map '[a]'
|
|
##
|
|
################################################################################
|
|
|
|
################################################################################
|
|
## SOUND
|
|
##
|
|
## You should consider mixing down audio to 2 channels with '-ac
|
|
## 2'. This greatly reduce file size and avoid any confusion for playback, which
|
|
## is often the case when converting DTS to any other format because DTS has
|
|
## embedded channel description which is not available in other formats.
|
|
################################################################################
|
|
|
|
################################################################################
|
|
## X264 OPTIONS
|
|
##
|
|
## x264 presets (-preset <preset>).
|
|
## preset ~= speed and quality*size ~= 1/speed
|
|
## ultrafast, superfast, veryfast, faster, fast, medium, slow, slower, veryslow, placebo
|
|
## Recommended values: faster -- slow
|
|
## slow is approx. two times slower than fast, and reduces the size by approx. 10%.
|
|
##
|
|
## x264 overall quality (-crf) is a logarithmic scale.
|
|
## 18 is near perfection.
|
|
## 22 is really good compression, while a bit more blurry than the original.
|
|
## 20 is a good compromise.
|
|
##
|
|
## x264 tuning (-tune <preset>).
|
|
## Possible values: film, animation, grain, ...
|
|
## See x264 --fullhelp.
|
|
## No tuning by default.
|
|
##
|
|
## x264 options (-x264opts me=<value>).
|
|
## Possible values: hex, umh...
|
|
## me=umh is default.
|
|
################################################################################
|
|
|
|
################################################################################
|
|
## FALLACIOUS INPUT
|
|
##
|
|
## In general, FFmpeg is not so good at copying fallacious streams. Reecoding
|
|
## video and audio streams helps a lot.
|
|
##
|
|
## "Can't write packet with unknown timestamp"
|
|
## Put '-fflags genpts' before the input command.
|
|
################################################################################
|
|
|
|
################################################################################
|
|
## MISC
|
|
## To check what fmmpeg supports:
|
|
## $ ffmpeg -codecs
|
|
## $ ffmpeg -formats
|
|
##
|
|
## Useful guides:
|
|
## x264: http://ffmpeg.org/trac/ffmpeg/wiki/x264EncodingGuide
|
|
## ID3 details: http://en.wikipedia.org/wiki/ID3
|
|
################################################################################
|