2013-08-04 11:29:35 +02:00
|
|
|
#!/bin/sh
|
|
|
|
|
2013-10-23 20:15:15 +02:00
|
|
|
_printhelp()
|
2013-08-04 11:29:35 +02:00
|
|
|
{
|
2013-10-23 20:15:15 +02:00
|
|
|
cat <<EOF
|
|
|
|
Usage: ${1##*/} MODE
|
2013-08-04 11:29:35 +02:00
|
|
|
|
2013-10-23 20:15:15 +02:00
|
|
|
This script was generated with tc-video-custom.
|
2013-08-04 11:29:35 +02:00
|
|
|
|
2013-10-23 20:15:15 +02:00
|
|
|
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.
|
2013-08-04 11:29:35 +02:00
|
|
|
|
2013-10-23 20:15:15 +02:00
|
|
|
Modes:
|
2013-08-04 11:29:35 +02:00
|
|
|
|
2013-10-23 20:15:15 +02:00
|
|
|
-e: Excerpt of 1 minute starting at 1 minute.
|
|
|
|
-f: Full video.
|
2013-08-04 11:29:35 +02:00
|
|
|
|
|
|
|
EOF
|
|
|
|
}
|
|
|
|
|
2013-10-23 20:15:15 +02:00
|
|
|
TC_SAMPLE=""
|
|
|
|
OPT_PROCESS=false
|
|
|
|
while getopts ":hef" opt; do
|
2013-08-04 11:29:35 +02:00
|
|
|
case $opt in
|
|
|
|
h)
|
|
|
|
_printhelp "$0"
|
|
|
|
exit 1 ;;
|
2013-10-23 20:15:15 +02:00
|
|
|
e)
|
|
|
|
TC_SAMPLE="-ss 60 -t 60"
|
|
|
|
OPT_PROCESS=true ;;
|
2013-08-04 11:29:35 +02:00
|
|
|
f)
|
2013-10-23 20:15:15 +02:00
|
|
|
OPT_PROCESS=true ;;
|
2013-08-04 11:29:35 +02:00
|
|
|
?)
|
|
|
|
_printhelp "$0"
|
|
|
|
exit 1 ;;
|
|
|
|
:)
|
|
|
|
echo "Missing argument."
|
|
|
|
_printhelp "$0"
|
|
|
|
exit 1 ;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
|
|
|
|
shift $(($OPTIND - 1))
|
|
|
|
|
2013-10-23 20:15:15 +02:00
|
|
|
if ! $OPT_PROCESS; then
|
|
|
|
_printhelp "$0"
|
|
|
|
exit
|
|
|
|
fi
|
|
|
|
|
2013-10-27 19:50:23 +01:00
|
|
|
if ! command -v ffmpeg >/dev/null; then
|
2013-10-23 20:15:15 +02:00
|
|
|
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 \
|
2013-10-24 21:52:34 +02:00
|
|
|
ffmpeg -nostdin -i "$@" \
|
2013-10-23 20:15:15 +02:00
|
|
|
-c:v libx264 -preset slow -crf 20 \
|
|
|
|
-c:a libvorbis -b:a 192k -ac 2 \
|
|
|
|
-c:s copy \
|
|
|
|
-map 0 \
|
|
|
|
$SAMPLE \
|
2013-10-24 21:52:34 +02:00
|
|
|
"${1%.*}-$(date '+%F-%H%M%S').mkv"
|
2013-10-23 20:15:15 +02:00
|
|
|
|
|
|
|
## Restore Zsh previous options. This will not turn off shwordsplit if it
|
|
|
|
## was on before calling the function.
|
|
|
|
[ "$STATUS" = "off" ] && set +o shwordsplit
|
|
|
|
}
|
|
|
|
|
2013-10-23 12:51:09 +02:00
|
|
|
## Choose to process all files one after another.
|
2013-10-23 20:15:15 +02:00
|
|
|
while IFS= read -r i; do
|
2013-10-23 12:51:09 +02:00
|
|
|
_transcode "$i"
|
|
|
|
done<<FILELINES
|
|
|
|
FILELINES
|
2013-08-04 11:29:35 +02:00
|
|
|
|
2013-10-23 20:15:15 +02:00
|
|
|
## Or all files at the same time. You ahve to change the ffmpeg input in the
|
|
|
|
## function.
|
|
|
|
# _transcode
|
2013-08-04 11:29:35 +02:00
|
|
|
|
|
|
|
################################################################################
|
2013-08-04 18:28:34 +02:00
|
|
|
## USE CASES
|
2013-08-04 11:29:35 +02:00
|
|
|
##
|
|
|
|
## Exchange stream 1 an 2 by first removing them, then reading them in the
|
|
|
|
## desired order.
|
|
|
|
##
|
2013-08-12 19:10:11 +02:00
|
|
|
## -map -0:1 -map -0:2 -map 0:2 -map 0:1
|
2013-08-04 11:29:35 +02:00
|
|
|
##
|
|
|
|
## Change audio stream 1 title and remove audio stream 2 title:
|
|
|
|
##
|
2013-08-12 19:10:11 +02:00
|
|
|
## -metadata:s:a:0 title="FR: OGG Stereo" -metadata:s:a:1 title=""
|
2013-08-04 11:29:35 +02:00
|
|
|
##
|
|
|
|
## Demux audio:
|
2013-08-12 19:10:11 +02:00
|
|
|
## -vn -sn -c:a copy -map 0:1
|
2013-08-04 11:29:35 +02:00
|
|
|
##
|
2013-08-04 18:28:34 +02:00
|
|
|
## Dump audio to an ogg file:
|
2013-08-12 19:10:11 +02:00
|
|
|
## -vn -c:a libvorbis -b:a 192k
|
2013-08-04 11:29:35 +02:00
|
|
|
##
|
2013-08-04 13:24:35 +02:00
|
|
|
## Add a delay to audio (assuming stream 0 is video and stream 1 is audio)
|
2013-08-12 19:10:11 +02:00
|
|
|
## -i "$1" -itsoffset 0.300 -i "$1" -map 0:0 -map 1:1
|
2013-08-04 13:24:35 +02:00
|
|
|
##
|
2013-10-23 20:15:15 +02:00
|
|
|
## 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
|
|
|
|
##
|
2013-08-12 19:10:11 +02:00
|
|
|
## Concatenate files. See
|
2013-08-04 18:28:34 +02:00
|
|
|
## https://trac.ffmpeg.org/wiki/How%20to%20concatenate%20(join,%20merge)%20media%20files
|
|
|
|
## for more details
|
2013-08-12 19:10:11 +02:00
|
|
|
##
|
|
|
|
## -filter_complex '[0:0] [0:1] [1:0] [1:1] concat=n=2:v=1:a=1 [v] [a]' -map '[v]' -map '[a]'
|
|
|
|
##
|
2013-08-04 18:28:34 +02:00
|
|
|
################################################################################
|
|
|
|
|
|
|
|
################################################################################
|
|
|
|
## SOUND
|
2013-08-04 11:29:35 +02:00
|
|
|
##
|
2013-08-04 18:28:34 +02:00
|
|
|
## 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
|
2013-08-04 11:29:35 +02:00
|
|
|
##
|
2013-08-04 18:28:34 +02:00
|
|
|
## x264 presets (-preset <preset>).
|
2013-08-12 19:10:11 +02:00
|
|
|
## preset ~= speed and quality*size ~= 1/speed
|
2013-08-04 11:29:35 +02:00
|
|
|
## ultrafast, superfast, veryfast, faster, fast, medium, slow, slower, veryslow, placebo
|
2013-08-12 19:10:11 +02:00
|
|
|
## Recommended values: faster -- slow
|
|
|
|
## slow is approx. two times slower than fast, and reduces the size by approx. 10%.
|
2013-08-04 11:29:35 +02:00
|
|
|
##
|
|
|
|
## 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>).
|
2013-08-12 19:10:11 +02:00
|
|
|
## Possible values: hex, umh...
|
|
|
|
## me=umh is default.
|
2013-08-04 11:29:35 +02:00
|
|
|
################################################################################
|
2013-08-04 18:28:34 +02:00
|
|
|
|
|
|
|
################################################################################
|
|
|
|
## FALLACIOUS INPUT
|
|
|
|
##
|
2013-08-12 19:10:11 +02:00
|
|
|
## In general, FFmpeg is not so good at copying fallacious streams. Reecoding
|
|
|
|
## video and audio streams helps a lot.
|
2013-08-04 18:28:34 +02:00
|
|
|
##
|
|
|
|
## "Can't write packet with unknown timestamp"
|
2013-08-12 19:10:11 +02:00
|
|
|
## Put '-fflags genpts' before the input command.
|
2013-08-04 18:28:34 +02:00
|
|
|
################################################################################
|
|
|
|
|
|
|
|
################################################################################
|
|
|
|
## 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
|
|
|
|
################################################################################
|