Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.
I believe I've figured it out! :)
Apple iphone movie "create date" is wrong which is used by Adobe Lightroom cleared up my main issue (which metadata tag that Adobe Lightroom uses to show the correct time/date). The solution: copy CreationDate over to all XMP date tags using EXIFtool, like this:
Bash:
$ exiftool -m -P -overwrite_original '-XMP:AllDates<CreationDate' FILENAME.mp4
$

But that was only half the problem!
FFMPEG doesn't copy all the metadata from the original H265 video using -map_metadata 0 after all, confirmed in How to prevent FFmpeg from dropping metadata?
The correct command to use with FFMPEG is -movflags use_metadata_tags as a step before the EXIFtool task of writing those XMP date tags, like this:
Bash:
export PATH="$PATH:/usr/local/bin"

for f in "$@"
do
ffmpeg -i "$f" -c:v libx264 -crf 18 -preset slow -c:a copy -movflags use_metadata_tags "${f%.*}_CONVERTED.mp4"
done

However... someone in that thread pointed out that FFMPEG writes the metadata in a non-standard way.
So although my tests show that the above to work in Lightroom (show the correct time/date), the better solution will probably be using the following 3 steps (compared to the above, this slightly bigger job also results in more metadata (such as "Apple" and "iPhone") to be shown in Lightroom as well.

I believe the working solution then will be (I still need to do some extensive testing with multiple H265 files and also fine-tune the H264 converting as there are some minor issues with pixel size etc.):

1) Convert the H265 video to H264 but without any metadata-transferring:
Bash:
export PATH="$PATH:/usr/local/bin"

for f in "$@"
do
ffmpeg -i "$f" -c:v libx264 "${f%.*}_converted_noMetadata.mp4"
done


2) copy all metadata from the original (H265) file to the converted (H264) file:
Bash:
$ exiftool -tagsfromfile ORIGINAL.mov CONVERTED.mp4
$

I can also check to see if the CreationDate has been added:
Bash:
$ exiftool -a -G1 -s -CreationDate CONVERTED.mp4
$

And/or check all the time tags:
Bash:
$ exiftool -a -G1 -time:all CONVERTED.mp4
$


3) Finally, copy the CreationDate tag to all XMP date tags:
Bash:
$ exiftool -m -P -overwrite_original '-XMP:AllDates<CreationDate' CONVERTED.mp4
$


@!!! : How should I modify your script in post #7 to include the above? I'm especially concerned about the syntax of step 2 (copying from the original file). Is this just a matter of using the "$f" string again?
 
Last edited:
@!!! : How should I modify your script in post #7 to include the above? I'm especially concerned about the syntax of step 2 (copying from the original file). Is this just a matter of using the "$f" string again?

Bash:
#!/usr/bin/env bash
export PATH="/opt/local/bin:/usr/local/bin:$PATH"

for original in "$@"
do
    if [ "$(ffprobe -v error -select_streams v:0 -show_entries stream=codec_name -of default=noprint_wrappers=1:nokey=1 "$original")" != "h264" ]; then
        converted="${original%.*}_CONVERTED.mp4"
      
        ffmpeg -i "$original" -c:v libx264 -crf 18 -preset slow -c:a copy "$converted"
        exiftool -tagsfromfile "$original" "$converted"
        exiftool -m -P -overwrite_original '-XMP:AllDates<CreationDate' "$converted"
      
    else
        echo "File is H.264, not converting."
    fi
done
This should work. I set up variable names to hopefully make things a bit easier to understand.
 
Looking good! 👍
I'm learning a lot from this -especially the syntax in a script.

OK, so I've given it a go with multiple H265 videos and your script appears to nail it!
The only thing I've changed is add -overwrite_original to the first "exiftool" line (exiftool -tagsfromfile "$original" -overwrite_original "$converted")

The script appears to skip converting when the file(s) selected are already H264
or the H265 file(s) have already been converted to H264, but there's no alert showing.
No biggie, but while those H265 files that have already been converted to H264 skip and don't go through the entire converting process again, those H264 files still have their MacOS "Date added", "Date created" and "Date modified" updated.

There was supposed to be an alert popping up whenever these two situations come up, right? (echo "File is H.264, not converting."), but this doesn't happen. Does it rely on the 3rd party software discussed earlier for progress alerts etc?
I suppose adding a "Run AppleScript" action to the Automator Quick Action is fine for an ending dialog (which I've done before) as a sequential running of actions, but perhaps not in this case when there's an "else" condition?
 
Last edited:
No biggie, but while those H265 files that have already been converted to H264 skip and don't go through the entire converting process again, those H264 files still have their MacOS "Date added", "Date created" and "Date modified" updated.
When it gets re-run on a file that's already been converted, ffmpeg fails and does not overwrite the file. exiftool, however, still gets run, which ends up modifying the files. I've fixed this below.
There was supposed to be an alert popping up whenever these two situations come up, right?
No. Automator by default does not do anything with the output of shell scripts. You can use the "Set Value of Variable" block after the Run Shell Script to get the text inside a variable. Then, you're on your own if you want to devise an AppleScript to handle that. You'll probably want to add the filename into the "not converting" message, and you'll want to ignore the output of exiftool, since it will output messages as well. To be honest it's a lot of work to do in a system that's not really designed for that kind of complexity.

What's your end-goal here? If it's just a few files, I don't think it's all that difficult to see which files have been converted, if you're in Finder's list view they will appear just above or below and have a modification date of today/now. If it's many files you could tag the ones that have been converted (there's a third-party macports package called tag that adds macOS Tags to files). Or if you're just wanting to get rid of the files there's again a third-party command called trash which will trash the converted files (I say trash instead of rm, as I presume you'll want to verify everything went well?).

Bash:
#!/usr/bin/env bash
export PATH="/opt/local/bin:/usr/local/bin:$PATH"

for original in "$@"
do
    if [ "$(ffprobe -v error -select_streams v:0 -show_entries stream=codec_name -of default=noprint_wrappers=1:nokey=1 "$original")" != "h264" ]; then
        converted="${original%.*}_CONVERTED.mp4"
        if [ ! -f "$converted" ]; then
            ffmpeg -i "$original" -c:v libx264 -crf 18 -preset slow -c:a copy "$converted"
            if [[ $? != 0 ]]; then echo "File $original was not converted successfully!"; fi
            exiftool -tagsfromfile "$original" -overwrite_original "$converted"
            exiftool -m -P -overwrite_original '-XMP:AllDates<CreationDate' "$converted"
        else
            echo "Skipping $original: already converted!"
        fi
    else
        echo "Skipping $original: already H.264!"
    fi
done

I added code to check if the file is already converted, and made the echos more clear about which file they were erroring out on. I also added a check to see if the ffmpeg command fails, which would be useful if you want error alerts.
 
When it gets re-run on a file that's already been converted, ffmpeg fails and does not overwrite the file. exiftool, however, still gets run, which ends up modifying the files. I've fixed this below.
I see. Yes, that makes sense since the exiftool lines are next in the script.


No. Automator by default does not do anything with the output of shell scripts. You can use the "Set Value of Variable" block after the Run Shell Script to get the text inside a variable. Then, you're on your own if you want to devise an AppleScript to handle that. You'll probably want to add the filename into the "not converting" message, and you'll want to ignore the output of exiftool, since it will output messages as well. To be honest it's a lot of work to do in a system that's not really designed for that kind of complexity.
Yes, sounds like a lot of work and experimentation.
So in which instances does the "echo......" lines display an alert? Is that when it's run via the Terminal?


What's your end-goal here?
Good question. I might have gotten a little carried away and nitpicky while working on this o_O

The end goal is to convert iPhone-generated "High efficiency" (Camera app "Formats" setting) MOV videos and HEIC "Live Photos" to the more compatible H.264 MP4 format and simultaneously keep the time/date-tag correct.
I also wanted to share the Automator Quick Action with others when done, with a nice user-experience, but I'm sure people will be happy as long as it works, even if the user-interface isn't perfect.

However, I think I've found a good solution regarding alerts:
I'm keeping the AppleScript dialog at the end of the Automator action which gives a final "Done -videos have been converted" alert. With perhaps hundreds of videos needing converting this is very useful, while the skipping of already converted or H264 videos can be done silently.


I added code to check if the file is already converted, and made the echos more clear about which file they were erroring out on. I also added a check to see if the ffmpeg command fails, which would be useful if you want error alerts.
Thanks. Great work!
It all seems to work very well now.
Strangely the FFMPEG -c:a copy option causes problems. It's supposed to just copy the audio tracks as is, but for some reason causes the converted video unreadable (I thought it worked before, but I might have just been lucky with some test files). I solved it by changed it to -c:a aac.

I might also need to set some options regarding the resolution because for some reason the video size is changed during conversion (according to what I've read, FFMPEG attempts to keep the resolution as long as it's not explicitly told to resize).
For some reason there are two resolutions shown when opening the video in QuickTime Viewer, and the converted video appears to adapt the resolution which the original file has in parenthesis:
Screenshot 2025-09-21 at 19.47.06.png
Screenshot 2025-09-21 at 19.49.06.png


As far as I can see, this only applies to the converted HEIC (HEIF) iPhone "Live Photos" and not regular videos.
Before running them through this script they need to get converted to videos by first importing them to the Photos app, and then exported (FILE-EXPORT-EXPORT UNMODIFIED ORIGINAL) which exports (H.265) .MOV files.

UPDATE: setting aside the resolution question above for a while, I proceeded to convert a sizeable batch of iPhone-created H.265 videos which was smooth sailing.
But working on another iPhone-generated batch I all of a sudden ran into problems (with just about all of them). Seemingly, the script worked without a hitch, but the converted videos had a generic "MP4" icon (not a frame-preview icon of the video) and it wouldn't open up in Quicktime viewer. In VLC however it worked fine.
To simplify things and troubleshoot better I decided to convert the file(s) in question using the same FFMPEG command but in the MacOS Terminal, as I would be bound to see error messages/alerts there. I didn't get any error messages at all o_O

I did some further research and found out that Apple, in their wisdow, again decided to do things their way, and several forum discussions tell people to add -pix_fmt yuv420p to the ffmpeg command, which I understand sets the pixel format and colour space correctly for Quicktime Player to read the file correctly.
This appeared to solve my issue, but then I keep reading that some people, even though they're using that option are still having problems, like here. There was no proper reply to that question unfortunately. I've also read about others in a similar sutuation.
Does anyone know more about this? Are there any other ffmpeg extensions I should keep in mind so as not to run into any more surprises?
 
Last edited:
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.