Artificial intelligent assistant

Creating a for loop with find -exec and while I am trying to make this script that loops through video files created between hours 00 and 12, convert them with ffmpeg and then remove them. The script works in terms of finding the files and starting ffpmeg but it seems that it continues to "send" characters from the find -exec after that ffmpeg has started on the first conversion and it eventually breaks ffmpeg and stop the conversion. How can I modify the script so this does not happen? The current script !/bin/bash -e find /videos/. -type f -print0 -exec sh -c 'h=$(date -d @$(stat -c %Y "$1") +%-H); [ "$h" -ge 00 ] && [ "$h" -lt 12 ]' sh {} \;|while read -d $'\0' i; do ffmpeg -y -i "$i" -vcodec libx264 -crf 27 -preset veryfast -movflags +faststart -c:a copy -threads 14 /output/"$(basename "$i" .ts)".mp4 rm -f -- "$i" done

Thanks to Gordon Davisson I managed to solve the problem. Here is the complete working script if someone happens to stumple upon this issue in the future.


#!/bin/bash -e
find /videos/. -type f -exec sh -c 'h=$(date -d @$(stat -c %Y "$1") +%-H); [ "$h" -ge 00 ] && [ "$h" -lt 12 ]' sh {} \; -print | while IFS= read -r i;
do
ffmpeg -y -i "$i" -vcodec libx264 -crf 27 -preset veryfast -movflags +faststart -c:a copy -threads 14 /output/"$(basename "$i" .ts)".mp4 rm -f -- "$i"
done

xcX3v84RxoQ-4GxG32940ukFUIEgYdPy a80db43dbc9c795b13412faa92c1fe18