Author Topic: Is there any way to add GPS location info into mp4 and mov video files?  (Read 12280 times)

yogeshyadav

  • Newbie
  • *
  • Posts: 3
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 Author
  • Administrator
  • ExifTool Freak
  • *****
  • Posts: 15492
    • ExifTool Home Page
Re: Is there any way to add GPS location info into mp4 and mov video files?
« Reply #1 on: November 22, 2016, 07:40:28 AM »
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, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

yogeshyadav

  • Newbie
  • *
  • Posts: 3
Re: Is there any way to add GPS location info into mp4 and mov video files?
« Reply #2 on: November 22, 2016, 08:09:35 AM »
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

  • ExifTool Author
  • Administrator
  • ExifTool Freak
  • *****
  • Posts: 15492
    • ExifTool Home Page
Re: Is there any way to add GPS location info into mp4 and mov video files?
« Reply #3 on: November 22, 2016, 08:18:50 AM »
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, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

yogeshyadav

  • Newbie
  • *
  • Posts: 3
Re: Is there any way to add GPS location info into mp4 and mov video files?
« Reply #4 on: November 22, 2016, 11:48:54 AM »
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

  • ExifTool Author
  • Administrator
  • ExifTool Freak
  • *****
  • Posts: 15492
    • ExifTool Home Page
Re: Is there any way to add GPS location info into mp4 and mov video files?
« Reply #5 on: November 22, 2016, 12:20:06 PM »
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, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

Fulco

  • Full Member
  • ***
  • Posts: 74
Re: Is there any way to add GPS location info into mp4 and mov video files?
« Reply #6 on: November 22, 2016, 08:27:14 PM »
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

  • Newbie
  • *
  • Posts: 1
Re: Is there any way to add GPS location info into mp4 and mov video files?
« Reply #7 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).

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


« Last Edit: February 13, 2017, 11:14:55 PM by Fribur »

wildcowboy

  • Jr. Member
  • **
  • Posts: 21
Re: Is there any way to add GPS location info into mp4 and mov video files?
« Reply #8 on: February 28, 2017, 12:26:14 AM »
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
Code: [Select]
ERROR: atom 'moov/udta/©xyz' not foundso I copied the whole udta instead.
Some tags got duplicated though
Code: [Select]
[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?

« Last Edit: February 28, 2017, 01:14:07 AM by wildcowboy »

wildcowboy

  • Jr. Member
  • **
  • Posts: 21
Fribur,

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

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

I get this error:

Code: [Select]
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

  • Newbie
  • *
  • Posts: 2
Re: Is there any way to add GPS location info into mp4 and mov video files?
« Reply #10 on: March 22, 2017, 06:23:16 AM »
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

  • Newbie
  • *
  • Posts: 1
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
« Last Edit: May 13, 2017, 05:53:40 AM by snaunton »