The following will do most of what you request using 'ExifTool'. It can be downloaded from https://exiftool.org/ or installed with homebrew on your Mac: brew install exiftool. ExifTool reads the EXIF metadata "Exchangeable Image File Format" embedded in digital images and can use the information to rename files, create directories and move images there. There is extensive documentation and example usage at the website and in the man page.
Open a terminal and run the following in the directory where your mp4's reside:
exiftool -d %Y%m%d-%H%M%S.%%e '-Filename<'CreateDate' *mp4
This will rename the files to a form like 20191214-165635.mp4
Then execute
exiftool -r -d %Y/%m/%d '-directory<$CreateDate/%d' .
This will create a directory structure like: '2021/02/05/'
and put each mp4 in it's folder based on the date.
Note that the date used is that from the metadata embedded in the file, not the one shown by ls or MacOS Finder. If you have done any image processing or certain other file operations the latter date will reflect these operations rather than the creation date of the image. I would think having the correct creation date would be important for security video.
EXIF tags vary depending on the model of camera. Yours may have something like 'Date/Time Original' instead of 'Create Date'. If so, replace 'CreateDate' in the above commands with the corresponding tag from your camera without any spaces or backslashes. To view the EXIF data execute exiftool example_filename.mp4. This will dump all the EXIF tags. To view only those with dates, execute exiftool example_file.mp4 | grep -i date.
Processing a million files make take a long time depending on their size. The following script will select a random subset of 500 files and put them in subdirectory 'tmp'. Create it in the directory where your mp4's are, make it executable with chmod u+x select_files.sh and run it: ./select_files.sh. Move to the directory (cd tmp) and run the above exiftool commands to confirm that they do what you want.
#!/bin/bash # # select_files.sh - Copy a random selection of files to subdirecotry 'tmp' # ext="mp4" # File extension num=500 # Number of files to select ls *.${ext} | sort -R | head -n $num > random_files.txt mkdir tmp while read -r file ; do cp $file ./tmp done < random_files.txt # End
YYYY-MM-DDdate format. It's always nice if the listing by filename is already sorted by date.The files are named in this format: "2021/02/01 | 00_03_07.mp4"-- you mean there's a 2021 directory, with subdir 02, which contains a file named "01 | 00_03_07.mp4" ? filenames cannot contain a slash.