How can I set Last Modified Date of file after using HandbrakeCLI to convert a file?
The modification date can be set with
touch -m -t 201207010742 whatever.m4v
AFAIK the creation/birth date can't be modified.
To set the modification date based on the creation date of another file you can use stat
:
touch -m -t $(stat -f %SB -t %Y%m%d%H%M original-file.mov) new-file-m4v
To apply this to your script, use something like
for f in "$@"
do
olddate=$(stat -f %SB -t %Y%m%d%H%M "$f")
base=${f%.*}
extension=${f##*.}
newfile=${base}.m4v
echo Converting \"$f\" to \"$newfile\"
/Applications/HandBrakeCLI -e x264 -b 4000 -a 1 -E faac -B 160 -R 48 -6 dpl2 -f mp4 --crop 0:0:0:0 -x level=40:ref=2:mixed-refs:bframes=3:weightb:subme=9:direct=auto:b-pyramid:me=umh:analyse=all:no-fast-pskip:filter=-2,-1 -i "$f" -o "$newfile"
touch -m -t $olddate "$newfile"
done