#!/bin/bash if [ "$#" -ne 2 ]; then echo "usage ts2mkv.sh [path to vdr recording] [path to movies]"; exit 1; fi if [ ! -d "$1" ]; then echo "vdr recording directory not valid: $1"; exit 1; fi if [ ! -d "$2" ]; then echo "movie directory not valid: $2"; exit 1; fi echo "vdr recordings directory: $1"; echo "movie directory: $2"; echo "changing into vdr recordings directory '$1'"; cd $1; echo `pwd` FILE_LIST="$1/tomkv.lst" while IFS= read -r LINE do echo "processing directory '$LINE'"; cd "$LINE"; for j in *.rec; do cd $j; MOVIENAME=$(sed -n -e 's/^T \(.*\)$/\1/p' "info"); DEST_NAME="$2/$MOVIENAME/$MOVIENAME.mkv" TRIMMED_NAME="$MOVIENAME.trimmed.ts" if [ ! -f "$DEST_NAME" ]; then echo "converting $MOVIENAME"; STAMPS=($(sed -n -e 's/^\([0-9:]\+.[0-9]\{2\}\).*$/\1/p' "marks")) if [ "${#STAMPS[@]}" -ne "2" ]; then echo "more than two cut marks found; skipping"; echo "${#STAMPS[@]}"; cd ..; continue; fi; echo "trimming form ${STAMPS[0]} to ${STAMPS[1]}"; FILENAMES=$(ls *.ts | paste -sd "|" -); if [ ! -f "$TRIMMED_NAME" ]; then echo ffmpeg -nostdin -i "concat:$FILENAMES" -ss ${STAMPS[0]} -to ${STAMPS[1]} -c:v copy -c:a copy "$TRIMMED_NAME"; ffmpeg -nostdin -i "concat:$FILENAMES" -ss ${STAMPS[0]} -to ${STAMPS[1]} -c:v copy -c:a copy "$TRIMMED_NAME"; fi if [ ! -d "$2/$MOVIENAME" ]; then mkdir "$2/$MOVIENAME"; fi echo ffmpeg -nostdin -i "$TRIMMED_NAME" -c:v libx264 -c:a copy "$DEST_NAME"; ffmpeg -nostdin -i "$TRIMMED_NAME" -c:v libx264 -c:a copy "$DEST_NAME"; else echo "video file $DEST_NAME already exists; skipping"; fi cd ..; done; cd ..; done < "$FILE_LIST"