Merge branch 'MultiuserUse' into 'master'
More features See merge request scripts/ts-to-mkv.sh!1
This commit is contained in:
commit
cd261ec072
1 changed files with 95 additions and 11 deletions
106
ts-to-mkv.sh
106
ts-to-mkv.sh
|
@ -1,27 +1,105 @@
|
||||||
#!/bin/bash
|
#!/usr/bin/env bash
|
||||||
|
########################
|
||||||
|
|
||||||
|
## functions ##
|
||||||
|
vercomp () {
|
||||||
|
if [[ $1 == $2 ]]
|
||||||
|
then
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
local IFS=.
|
||||||
|
local i ver1=($1) ver2=($2)
|
||||||
|
# fill empty fields in ver1 with zeros
|
||||||
|
for ((i=${#ver1[@]}; i<${#ver2[@]}; i++))
|
||||||
|
do
|
||||||
|
ver1[i]=0
|
||||||
|
done
|
||||||
|
for ((i=0; i<${#ver1[@]}; i++))
|
||||||
|
do
|
||||||
|
if [[ -z ${ver2[i]} ]]
|
||||||
|
then
|
||||||
|
# fill empty fields in ver2 with zeros
|
||||||
|
ver2[i]=0
|
||||||
|
fi
|
||||||
|
if ((10#${ver1[i]} > 10#${ver2[i]}))
|
||||||
|
then
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
if ((10#${ver1[i]} < 10#${ver2[i]}))
|
||||||
|
then
|
||||||
|
return 2
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
ffmpegcheck(){
|
||||||
|
ffmpegversion=$("$FFMPEG" -version | head -n1 | awk '{print $3}')
|
||||||
|
vercomp "$ffmpegversion" "4"
|
||||||
|
}
|
||||||
|
##/functions ##
|
||||||
|
|
||||||
|
## Env ##
|
||||||
SAVEIFS=$IFS
|
SAVEIFS=$IFS
|
||||||
IFS=$(echo -en "\n\b")
|
IFS=$(echo -en "\n\b")
|
||||||
|
FFMPEG="/data/sourcecode/ffmpeg/ffmpeg-4.1.3-amd64-static/ffmpeg"
|
||||||
|
if [[ ! -f "$FFMPEG" ]]; then
|
||||||
|
FFMPEG=$(/usr/bin/env which ffmpeg)
|
||||||
|
fi
|
||||||
|
|
||||||
echo "[info] convert .ts to .mkv; v1 start"
|
ffmpegcheck
|
||||||
|
if [[ "$?" == "2" ]]; then
|
||||||
|
echo "[error] ffmpeg version too low, need to use version 4.0.0 or newer."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
WORKPATH="./"
|
||||||
|
keepsource="0"
|
||||||
|
version="2"
|
||||||
|
##/Env ##
|
||||||
|
|
||||||
|
## Start ##
|
||||||
|
echo "[info] $0 -- v$version"
|
||||||
|
while getopts d:hk:p: OPT; do
|
||||||
|
case "$OPT" in
|
||||||
|
d)
|
||||||
|
if [[ -e "$OPTARG" ]]; then
|
||||||
|
FFMPEG="$OPTARG"
|
||||||
|
echo "[debug] custom daemon: $OPTARG"
|
||||||
|
else
|
||||||
|
echo "[debug] no custom daemon; using $FFMPEG"
|
||||||
|
fi ;;
|
||||||
|
h)
|
||||||
|
echo "[help] -d, path to custom ffmpeg (default: $FFMPEG)"
|
||||||
|
echo "[help] -k, keep the original ts file"
|
||||||
|
echo "[help] -p, custom path to scan recursively (default: $WORKPATH)"
|
||||||
|
exit 0;;
|
||||||
|
k)
|
||||||
|
echo "[debug] keeping the original file"
|
||||||
|
keepsource="1";;
|
||||||
|
p)
|
||||||
|
if [[ -e "$OPTARG" ]]; then
|
||||||
|
WORKPATH="$OPTARG"
|
||||||
|
echo "[debug] custom pathing: $OPTARG"
|
||||||
|
else
|
||||||
|
echo "[debug] no custom pathing; using $WORKPATH"
|
||||||
|
fi ;;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
|
||||||
|
shift $(($OPTIND-1))
|
||||||
echo "[info] finding files"
|
echo "[info] finding files"
|
||||||
filelist="$(find ./ -name "*.ts")"
|
filelist="$(find $WORKPATH -name "*.ts")"
|
||||||
if [[ "$filelist" ]]; then
|
if [[ "$filelist" ]]; then
|
||||||
for i in $filelist;
|
for i in $filelist;
|
||||||
do
|
do
|
||||||
if [[ "$i" == "./*/*.ts" ]] || [[ "$i" == "./*.ts" ]] || [[ "$i" == "./*/*/*.ts" ]]; then
|
|
||||||
echo "[exit] no files found."
|
|
||||||
exit 0
|
|
||||||
fi
|
|
||||||
sleep 2
|
|
||||||
echo "[info] working on $i"
|
echo "[info] working on $i"
|
||||||
INFILE="$i"
|
INFILE="$i"
|
||||||
echo "[debug] Infile: $INFILE"
|
echo "[debug] Infile: $INFILE"
|
||||||
OUTFILE="${i//.ts/.mkv}"
|
OUTFILE="${i//.ts/.mkv}"
|
||||||
echo "[debug] Outfile: $OUTFILE"
|
echo "[debug] Outfile: $OUTFILE"
|
||||||
sleep 2
|
sleep 2
|
||||||
|
|
||||||
INFILE2="${INFILE//\'/\'\\\\\\\'\'}"
|
INFILE2="${INFILE//\'/\'\\\\\\\'\'}"
|
||||||
/data/sourcecode/ffmpeg/ffmpeg-4.1.3-amd64-static/ffmpeg \
|
"$FFMPEG" \
|
||||||
-i "${INFILE}" \
|
-i "${INFILE}" \
|
||||||
-f lavfi -i movie="'${INFILE2}'[out+subcc]" \
|
-f lavfi -i movie="'${INFILE2}'[out+subcc]" \
|
||||||
-map 0 -map 1:s \
|
-map 0 -map 1:s \
|
||||||
|
@ -33,9 +111,15 @@ if [[ "$filelist" ]]; then
|
||||||
|
|
||||||
exitcode="$?"
|
exitcode="$?"
|
||||||
if [[ $exitcode -eq 0 ]]; then
|
if [[ $exitcode -eq 0 ]]; then
|
||||||
|
echo "[info] successful conversion"
|
||||||
|
if [[ "$keepsource" == "0" ]]; then
|
||||||
|
echo "[debug] deleting original file"
|
||||||
rm -v "$INFILE"
|
rm -v "$INFILE"
|
||||||
else
|
else
|
||||||
echo "[error] PROBLEM FOUND IN $INFILE, moving on..."
|
echo "[info] retaining original file"
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
echo "[error] $INFILE is corrupted, abandoning..."
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
else
|
else
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue