<html><head></head><body>#!/bin/bash
searchDir=/channels/TV
fileExt="mpg"
PATH=$PATH:/usr/local/bin
if [ -d "$searchDir" ]
then
find "$searchDir" -name "*.$fileExt" -type f -exec sh -c '
file="$0"
fileDir=$(dirname "$file")
fileName=$(basename "$file")
fileNameNoExt="${fileName%.*}"
tmpFileDir="/home/user/temp"
newFileExt="mp4"
newFileName="$fileNameNoExt.$newFileExt"
workingFilePath="$tmpFileDir/$fileName"
tmpFilePath="$tmpFileDir/$newFileName"
finalDestination="/home/user/output"
echo "moving file to work dir: $file"
mv "$file" "$workingFilePath"
if [ $? -eq 0 ]
then
echo "Running ComCut on file: $workingFilePath"
comcut "$workingFilePath"
echo "processing: $workingFilePath"
ffmpeg -i "$workingFilePath" -ss 0 -vf yadif=0:-1:1,hqdn3d -vcodec av1_nvenc -preset 6 -crf 32 -map 0:v -sn -acodec aac -ab 160k -map 0:a  "$tmpFilePath"
if [ $? -eq 0 ]
then
echo "Moving file to final destination: $finalDestination/$newFileName"
mkdir -p "$finalDestination$fileDir"
mv "$tmpFilePath" "$finalDestination$fileDir/$newFileName"
if [ $? -eq 0 ]
then
echo "Removing old file: $workingFilePath"
rm "$workingFilePath"
fi
fi
fi
' {} ';'
else
echo "dir doesn't exist: $searchDir"
fi
</body></html>