How to copy GPS location from original MP4 video header to new encoded MP4 file?

Started by pstein, June 06, 2024, 11:32:21 AM

Previous topic - Next topic

pstein

When I encode an existing MP4 video file orig.mp4 into a new MP4 video file result.mp4 then unfortunately the
GPS location (longitude + latitude) from original MP4 video file is NOT copied by the converter tool (Avidemux).

So I am searching for a workaround to copy the header tags manually.

Is this possible with exiftool?

How should the cmdline command look like for orig.mp4 and result.mp4 ?

Phil Harvey

The command line depends on where the information is stored.  Use this command to determine where it is stored:

exiftool -location:all -G1 -s FILE

Then, if the GPS is in Keys:GPSPosition for example, you would copy it from one file to another for all files in 2 directories like this (assuming the files have the same name)"

exiftool -tagsfromfile ORIGINAL_DIR/%f.%e -keys:gpsposition -ext mp4 ENCODED_DIR

- Phil
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux/PowerShell, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

StarGeek

You should also note that if there's a GPS track or EXIF data embedded in the file, that cannot be copied. If such data is important to you, then you should keep the original file.
* Did you read FAQ #3 and use the command listed there?
* Please use the Code button for exiftool code/output.
 
* Please include your OS, Exiftool version, and type of file you're processing (MP4, JPG, etc).

pstein

Hmm, when I look into the header fields of the source mp4 video then I found the following GPS values:

keystocopy.png

As you can see
- its in a separate group "UserData" which does not exist in the destination mp4 video any more
- has a different keyname "GPScoordinates" and not "gpsposition"
- it is unclear if this is a "embedded" value "which cannot be copied" or not

I tried the following:
exiftool.exe -tagsfromfile src.mp4 -keys:GPScoordinates dest.mp4
and got the following output from exiftool:

Warning: No writable tags set from D:\todo\test\src.mp4
    0 image files updated
    1 image files unchanged

So whats wrong?

An additional problem is that a src exif header value should not only be copied into an existing header field in dest. Instead the header field GPScoordinates must be created at first and that under a (new) group "UserData". How can I achieve this?


Phil Harvey

...where DIR is the name of a directory/folder containing the images.  On Mac/Linux/PowerShell, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

StarGeek

Quote from: pstein on June 07, 2024, 12:19:49 AM- its in a separate group "UserData" which does not exist in the destination mp4 video any more

The UserData group will be created when you copy the data.

Quote- has a different keyname "GPScoordinates" and not "gpsposition"

That was a typo in Phil's post.  GPSCoordinates is the embedded tag and can appear in the Keys, ItemList, and UserData tags (which are all sub-groups of Quicktime tags). This is the madness of video metadata, where the same tag can appear in multiple locations.

GPSPosition is a Composite tags which will write to the GPSLatitude/GPSLongitude tags at the same time.

QuoteAn additional problem is that a src exif header value

Minor nitpick, this is Quicktime data, not EXIF data. All EXIF data is metadata, but not all metadata is EXIF data.
* Did you read FAQ #3 and use the command listed there?
* Please use the Code button for exiftool code/output.
 
* Please include your OS, Exiftool version, and type of file you're processing (MP4, JPG, etc).

Phil Harvey

...where DIR is the name of a directory/folder containing the images.  On Mac/Linux/PowerShell, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).


pstein

One more related question:

Assume I want to copy ALL header fields whose keynames contain the pattern *CreateDate (in several different groups) at once. Is this possible with wildcards?

In detail I want to copy all timestamps (if they exist in source video) from
Track1:TrackCreateDate
Track1:MediaCreateDate
Track2:TrackCreateDate
Track2:MediaCreateDate
QuickTime:CreateDate


-*.*CreateDate

does not work.

Similarly: How can I copy ALL header fields in group "UserData"?

simply use -UserData or -UserData:  instead of -UserData:GPSCoordinates does not work

Phil Harvey

Close.  You need a colon instead of a period after the group name: "-*:*CreateDate" or "-all:*CreateDate"

And "-userdata:*" or -userdata:all will copy all of the UserData tags.

I suggest you read and try to understand the -tagsFromFile documentation as this is a powerful feature with vast possibilities.

- Phil
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux/PowerShell, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

pstein

Everything works fine. Great!

However one minor problem remains:

In source video file a group "Samsung" exists with a key inside:
SamsungModel = SM-A528B

Similar to copying the whole UserData group I want to copy "Samsung" group too with the following parameter:

-"Samsung:all"

but it is not copied.
Again: -"UserData:all" works (even in the same command).

So I could imagine that exiftool copiess only pre-defined, well known groups but not unknown one.
Is this the reason?

StarGeek

The Samsung group are MakerNotes, which are a subset of the EXIF group. As I said above, EXIF data cannot be copied into another video. The reason for this is that there isn't a standard for doing so and every camera company does it in different ways.
* Did you read FAQ #3 and use the command listed there?
* Please use the Code button for exiftool code/output.
 
* Please include your OS, Exiftool version, and type of file you're processing (MP4, JPG, etc).

Phil Harvey

If you look at the Samsung smta Tags documentation, you will see that SamsungModel is not writable.

The good news is that basically nothing but ExifTool and maybe some Samsung software will read this.

- Phil
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux/PowerShell, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

StarGeek

* Did you read FAQ #3 and use the command listed there?
* Please use the Code button for exiftool code/output.
 
* Please include your OS, Exiftool version, and type of file you're processing (MP4, JPG, etc).