I'm working on a MacOS "Services" Quick Action for converting H.265 (HEVC) videos to H.264 (using FFMPEG), but I'm having some minor issues regarding file naming and file-location.
I've created a "Quick Action" in Automator which consists of a shell script and an Applescript.
The shell script looks like this:
Naming
When having selected the (H.265) videos in the Finder, right-clicked and chosen the Service I'm working on here I basically want the files to be copied, converted to H.264 and named using the same name as before, but "_converted" added to it (i.e. "video.mov" becomes "video_converted.mp4").
I'm not sure if FFMPEG understands .MOV files so based upon some online examples I found I chose to have it output to .MP4 instead. But I may be wrong and will take a further look into that later.
I also want to ensure that the script won't mess files up in case I mistakingly select some other file-types in the Finder, but I think I've taken care of that with the very first option in the workflow (Workflow receives current [movie files] in [Finder] -see screenshot above). Does it suffice?
File location
In addition to the output name I want it to end up in the same location as the original file. Currently it ends up in the root of my Mac-user folder for some reason.
Progress bar
When the Service runs it may take a while for long videos to get converted, and seemlingly nothing is going on (except for a tiny spinning cogwheel in the Finder's menu-bar). I've added an Applescript at the end of the process which confirms that the file has been converted, but that doesn't help the user see that something is going on until then.
Is there a way to add a progress bar or something similar?
FFMPEG -changes the datestamp
Perhaps slightly off-topic, but for some unknown reason the timestamp gets changes to exactly 2 hours behind the original file's timestamp.
This forum thread explains that the following (which I've used) keeps the time/date the same as the original file:
"-movflags use_metadata_tags -map_metadata 0"
An estimated guess would be that it has something to do with time-zones.
UPDATE: Using Exiftool to read all relevant EXIF info about a file (in the Terminal app: exiftool filename.mov), I compared an original video (H.265) with a converted copy (H.264) and found out that the converted copy had one tag added which the original didn't have at all:
Creation Time : 2023-05-17T10:07:48.000000Z
However, both files had the "creation date" tag with the exact same information:
Creation Date : 2023:05:17 12:07:48+02:00
As you can see, the "creation time" tag shows a time difference of exactly two hours, and it seems Lightroom (which is my go-to app for my photo organizing needs) uses that tag if it's available.
Perhaps I could solve the problem by having Exiftool remove it after FFMPEG is done with its thing, as part of the script (or better yet: tell FFMPEG somehow not to add that tag in the first place).
But I'm really just guessing here and would like to have things confirmed by more knowledgeable people than myself first.
I've created a "Quick Action" in Automator which consists of a shell script and an Applescript.
The shell script looks like this:
Code:
# set FFMPEG path
export PATH="$PATH:/usr/local/bin"
#!/bin/sh
for f in "$@"
do
ffmpeg -i "$f" -movflags use_metadata_tags -map_metadata 0 -c:v libx264 -profile:v high -preset slow -tune film -crf 18 "CONVERTED.mp4"
done
Naming
When having selected the (H.265) videos in the Finder, right-clicked and chosen the Service I'm working on here I basically want the files to be copied, converted to H.264 and named using the same name as before, but "_converted" added to it (i.e. "video.mov" becomes "video_converted.mp4").
I'm not sure if FFMPEG understands .MOV files so based upon some online examples I found I chose to have it output to .MP4 instead. But I may be wrong and will take a further look into that later.
I also want to ensure that the script won't mess files up in case I mistakingly select some other file-types in the Finder, but I think I've taken care of that with the very first option in the workflow (Workflow receives current [movie files] in [Finder] -see screenshot above). Does it suffice?
File location
In addition to the output name I want it to end up in the same location as the original file. Currently it ends up in the root of my Mac-user folder for some reason.
Progress bar
When the Service runs it may take a while for long videos to get converted, and seemlingly nothing is going on (except for a tiny spinning cogwheel in the Finder's menu-bar). I've added an Applescript at the end of the process which confirms that the file has been converted, but that doesn't help the user see that something is going on until then.
Is there a way to add a progress bar or something similar?
FFMPEG -changes the datestamp
Perhaps slightly off-topic, but for some unknown reason the timestamp gets changes to exactly 2 hours behind the original file's timestamp.
This forum thread explains that the following (which I've used) keeps the time/date the same as the original file:
"-movflags use_metadata_tags -map_metadata 0"
An estimated guess would be that it has something to do with time-zones.
UPDATE: Using Exiftool to read all relevant EXIF info about a file (in the Terminal app: exiftool filename.mov), I compared an original video (H.265) with a converted copy (H.264) and found out that the converted copy had one tag added which the original didn't have at all:
Creation Time : 2023-05-17T10:07:48.000000Z
However, both files had the "creation date" tag with the exact same information:
Creation Date : 2023:05:17 12:07:48+02:00
As you can see, the "creation time" tag shows a time difference of exactly two hours, and it seems Lightroom (which is my go-to app for my photo organizing needs) uses that tag if it's available.
Perhaps I could solve the problem by having Exiftool remove it after FFMPEG is done with its thing, as part of the script (or better yet: tell FFMPEG somehow not to add that tag in the first place).
But I'm really just guessing here and would like to have things confirmed by more knowledgeable people than myself first.
Last edited: