Is there any way to add GPS location info into mp4 and mov video files?

Started by yogeshyadav, November 22, 2016, 05:35:58 AM

Previous topic - Next topic

yogeshyadav

Hello
I have a few videos taken using Sony camera which don't have GPS location info embedded (camera doesn't have GPS). I also have few videos shot using iPad 2 (with location access turned off) which don't have GPS location info embedded.
Is there any way to add location info into these video files?

Phil Harvey

ExifTool can write XMP GPS information to MP4 and MOV videos.

- 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 ($).

yogeshyadav

I know it is unrelated but do you know if Google Photos uses XMP location data? Also, can you give me an example of how to add this info using exiftool?

Thanks

Phil Harvey

I would be surprised if Google honoured XMP in MP4 videos, but I don't know for sure.

The command would be like this:

exiftool -xmp:gpslatitude=44.1234 -xmp:gpslongitude=-75.1234 FILE

- 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 ($).

yogeshyadav

Thanks. I successfully executed the command.
Sadly, Google Photos doesn't use XMP tags :(
Is it not possible to add/edit Quicktime location tags at all?
What if I re-encode the video? Is there any application which allows quicktime location tags to be added while re-encoding?

Phil Harvey

Pity.

I think there may be video utilities that can add Quicktime location tags, but ExifTool only has limited ability to write video.  If you search this forum you may find some solutions offered by others.

- 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 ($).

Fulco

You can use EditReady (Divergent Media) to edit the location tag and a lot of other QuickTime tags. This utility will rewrap the audio and video codec into a MOV-container. Another tool you can use for this purpose is QT Edit (Digital Rebellion). This tool can even add costum Quicktime tags to the video file. QT Edit doesn't rewrap the codecs.

- Fulco

Fribur

I ended up using https://www.bento4.com to transfer GPS information that got lost during re-encoding of videos from AVS (h.264) to HEVC (h.265).

Found out gps location information is inconsistently stored. My Android phone stores it in the [©xyz] atom, which is a member of  [udta] atom, which in turn is a member of the [moov] atom. iPhone or iPad stores it somewhere inside the numerous atoms that are part of the [meta] atom, which is a member of the [moov] atom . This is what these two options looks like in Mediainfo:
©xyz : <some coordinates>
com.apple.quicktime.location.ISO6709  : <some coordinates>


The ©xyz coordinates can be copied from input.mp4 to output.mp4 using those commands:
mp4extract.exe moov/udta/©xyz input.mp4 temp.txt
mp4edit.exe --insert moov:temp.txt output.mp4 output_gps.mp4


You could also copy the entire [udta] atom along with all the information that are in it.
(Note: the copyright sign is not part of the US codepage 437, a batch file containing ©xyz will fail. Change to code page that contain the copyright symbol first using chcp 1250. Just cost me an hour to find that out.)

The com.apple.quicktime.location.ISO6709 coordinates can be copied from input.mp4 to output.mp4 by by copying the entire meta atom along with the atom that contains the location (and others) using those commands:
mp4extract.exe moov/meta input.mp4 temp.txt
mp4edit.exe --insert moov:temp.txt output.mp4 output_gps.mp4


To get an overview over all available atoms and their path you can run
mp4dump.exe input.mp4

You can basically transfer any atom from input.mp4 to output.mp4, e.g. I also used it to maintain a 90 degree rotation that got lost during conversion by replacing the [tkhd] atom.

Be sure to do all this AFTER you packed tracks into a mp4 file using mp4box, as mp4box does not know some of these atoms (e.g. ©xyz) and you lose the information again.

I suppose AtomicParsley can do the same, but I am not sure. Also, AtomicParsley development appears to have stopped in 2006,  while Bento4 was last update 2016-12-27.

Hope this helps. Phil, perhaps even you can get the foundation for transfer of quicktime  tags from Bento4 (they have GNU 2.0 license)
Fribur



wildcowboy

Thanks a lot for posting the solution. It works as a charm on linux too.
I could not copy ©xyz atom from my videos created on Android though
ERROR: atom 'moov/udta/©xyz' not found
so I copied the whole udta instead.
Some tags got duplicated though
[Composite]     GPSLatitude                     : <coordinates>N
[Composite]     GPSLatitude                     : <coordinates>N
[Composite]     GPSLongitude                    : <coordinates>W
[Composite]     GPSLongitude                    : <coordinates>N

but looks like it does not hurt.
I sent the file back to the phone and was able to see the location on the map

Now I am wondering if there is a way to copy the coordinates from a JPG  or TXT /XMP file to an MP4 file. Any ideas?


wildcowboy

Fribur,

I can extract udta atom running a command in Linux terminal, e.g.
mp4extract moov/udta 'media/data/Family Pictures/2016/2016-10/20161030/20161030_174720.mp4' 'media/data/Family Pictures/2016/2016-10/20161030/20161030_174720.txt
but when I am trying to do the same using a bash script

cd "$sourcedir"
for filelist in *.mp4;
do
mp4extract moov/udta "$sourcedir/$filelist" "$sourcedir/${filelist%.*}.txt"
done


I get this error:

mp4extract version -r
mp4extract: unknown options specified, ignoring: /media/data/Family Pictures/2016/2016-10/20161030/20161030_174720.mp4 /media/data/Family Pictures/2016/2016-10/20161030/20161030_174720.txt
Open: open(moov/udta) failed (src/mp4file.cpp,398)


Am I doing anything wrong? Same code works for ffmpeg and other tools.
I am using a static build.

ToniW

Quote from: Fribur on February 13, 2017, 10:06:08 PM
I ended up using https://www.bento4.com to transfer GPS information that got lost during re-encoding of videos from AVS (h.264) to HEVC (h.265).

Thanks for tip!  8)

snaunton

I came across this post several times while trying to find a solution to setting the GPSPosition on videos for Google Photos (mostly to set the timezone because setting the date and time is woefully bad in google photos which will randomly mess up the order of your photos and videos). As I have found a solution I am posting this here so that hopefully it helps someone.

It requires transcoding, but as this is for Google Photos who cares(?).

FWIW, we have a load of happy snap AVI files from pre smart phone older cameras which do not have any form of GPS, and my wife has been rather slack at manually setting the time on them too. I could not figure out how to tag avis, so I am transcoding to mp4 and gzipping the original avi. This is on linux (debian testing/9), but you can get ffmpeg and exiftool on Windows too and the parameters are the same.

This is also Amazon Cloud Drive/Prime Photos (at least amazon.com.au flavour) friendly too.

Example steps:

1) To get the location I use google maps, find a random part of the country or whatever and lat and long can be gained from the "Share" url

https://www.google.com.au/maps/place/Vietnam/@15.0325356,107.9142184,10z/data=!4m5!3m4!1s0x31157a4d736a1e5f:0xb03bb0c9e2fe62be!8m2!3d14.058324!4d108.277199?hl=en

2) The GPSPosition is set with ffmpeg using -metadata location=<Latitude>+<Longitude> and -metadata location-eng=<Latitude>+<Longitude>

Below is a random location in Vietnam as per step 1.

-metadata location=15.0325356+107.9142184 -metadata location-eng=15.0325356+107.9142184

3) Transcode to mp4, including location metadata

ffmpeg -i DSCF7919.AVI -metadata location=15.0325356+107.9142184 -metadata location-eng=15.0325356+107.9142184 -c:a aac -b:a 128k -c:v libx264 -crf 23 DSCF7919.AVI.mp4

4) Set CreateDate and MediaCreateDate using exiftool (can't figure out how to do this during the transcodewith ffmpeg...?):

exiftool -CreateDate="2006:12:31 12:13:14" -MediaCreateDate="2006:12:31 12:13:14" DSCF7919.AVI.mp4

Et voila when uploaded to Google Photos via the web interface (I have not tried any other method), (EDIT: after a short time) video will be set to 2006-12-31 12:13:14 GMT+7 and have the correct GPS coords set with the location pointer pointing to the random location in Vietnam... and in the right order. Yay!

Another FWIW, I should be integrating this into my shotwell-export script (which deals with duplicates) soon https://github.com/snaunton/shotwell-export

icy


Here is a solution for Google Photos for videos and photos.
(Thanks to snaunton, I was able to replicate the data that ffmpeg wrote in the metadata.)

exiftool -GPSAltitude="0" -UserData:GPSCoordinates="-2.1129, -79.9034, 0" -Rotation="0" -XMP:GPSLatitude="-2.11293" -XMP:GPSLongitude="-79.903462" -GPSLongitudeRef="West" -GPSLatitudeRef="North" FILE

Required tags for GPS for videos on Google Photos:

  • GPSAltitude
  • UserData:GPSCoordinates (ONLY 4 DIGITS are allowed after each decimal point)
  • Rotation

These tags work for GPS for photos on Google Photos:

  • XMP:GPSLatitude
  • XMP:GPSLongitude
  • GPSLongitudeRef
  • GPSLatitudeRef

If the tags are combined, it still works.

StarGeek

The reference tags are not needed in this example as you are writing the references to the GPS tags in the EXIF block, but the actual coordinates to the XMP block.  And the XMP GPS tags don't need references as the reference direction is included in the tag.

For completeness, you could write the EXIF GPS tags at the same time by changing this
-GPSLongitudeRef="West" -GPSLatitudeRef="North"
into this
-GPSLongitude*=-2.11293 -GPSLatitude*=-79.903462

Also, your GPSLatitudeRef direction is incorrect based upon the numbers. A negative number is South.  Uploading an image with these numbers shows Google Photos uses only the XMP data and ignores the reference directions as they are not in the same group.

Due to the wildcard, this will write the EXIF coordinate tag and the reference direction at the same time.  Exiftool is smart enough to figure out what the reference direction is from the coordinate number

Example:
C:\>exiftool -P -overwrite_original -GPSLongitude*=-2.11293 -GPSLatitude*=-79.903462 y:\!temp\Test4.jpg
    1 image files updated

C:\>exiftool -g1 -a -s -gps* y:\!temp\Test4.jpg
---- GPS ----
GPSVersionID                    : 2.3.0.0
GPSLatitudeRef                  : South
GPSLatitude                     : 79 deg 54' 12.46"
GPSLongitudeRef                 : West
GPSLongitude                    : 2 deg 6' 46.55"
---- Composite ----
GPSLatitude                     : 79 deg 54' 12.46" S
GPSLongitude                    : 2 deg 6' 46.55" W
GPSPosition                     : 79 deg 54' 12.46" S, 2 deg 6' 46.55" W
* 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).