mkdir Rendered;

for file in $(ls -a *.mkv *.mp4); do
  if [[ $file == *.mkv ]]; then
    output_file="$PWD/Rendered/Render_$(basename "$file" .mkv).mkv"
  elif [[ $file == *.mp4 ]]; then
    output_file="$PWD/Rendered/Render_$(basename "$file" .mp4).mp4"
  fi
  
  duration=$(ffmpeg -i "$file" 2>&1 | grep "Duration" | cut -d ' ' -f 4 | sed s/,//)
  
  ffmpeg -i "$file" -i logo.png \
    -filter_complex "drawtext=text='%{pts\:hms}':x=50:y=h-th-40:fontsize=21:fontcolor=white,drawtext=text='$(basename "$file" | sed 's/\.[^.]*$//')':x=w-tw-50:y=h-th-40:fontsize=21:fontcolor=white,overlay=x=(main_w-overlay_w)-50:y=(main_h-overlay_h)/(main_h-overlay_h)+50" \
    -c:v libx264 -b:v 4M -maxrate 4M -bufsize 2M -preset veryfast \
    -c:a aac -b:a 192k "$output_file" > output.log 2>&1 < /dev/null &
done
