How to wait for file close in Linux

2019-05-31 22:32发布

问题:

My security cameras recorders (located in distant places), FTP`s to my server video files after any event. Using find and ffmpeg commands, server converts DAV file to AVI and remove DAV file using syntax like this:

find $katalog -type f -name "*.dav" -exec ffmpeg -y -i {} -vcodec libx264 -crf 24 {}.avi >/dev/null 2>&1 \; -exec rm -f {} \;

I use "inotify" to trigger conversion action. The problem is when two or more recorders ftp`s files to server. "inotify" trigger conversion action when first file will be transmitted completely. But other recorders will be still transmit files, so such files will not be closed. How can I modify above syntax to be sure that ffmpeg conversion will be done only on closed (fully transited) files?