Author Topic: Generating/writing GPS data from MP4 file into video frames  (Read 1936 times)

haimat

  • Newbie
  • *
  • Posts: 2
Hello all,

I have never worked with ExifTool, but it seems this tool might help in my situation, so I would like to ask for your help. I have an MP4 video file from a GoPro camera. That video file contains a GPS data stream. What I want is to a) extract each frame from that video and save them as JPG images, and b) write the correct GPS/geolocation tags into each of these images. So far I was able to extract all GPS data from the video file into a GPX (XML) file.

There seems to be catch though: When I look into that GPX file I can see the time string under "metadata" in the header of the file = 2021-05-28T08:54:24Z. However, when I look at the MP4 file itself via ffprobe the creation_time = 2021-05-28T10:22:18.000000Z. Thus apparently the GPS time stamps and the video file time stamp are not in sync.

Now is there a way with ExifTool to achieve what I want? Can I extract the video frames as image files AND write the GPS/geodata information into each image AND take care of the time difference? It would be fine for me to use another tool like ffmpeg in order to extract all video frames into images as a first step, as long as my overall goal can be achieved. Is ExifTool the right tool for this job?

Thanks in advance for your help!

Phil Harvey

  • ExifTool Author
  • Administrator
  • ExifTool Freak
  • *****
  • Posts: 19187
    • ExifTool Home Page
Re: Generating/writing GPS data from MP4 file into video frames
« Reply #1 on: June 03, 2021, 09:52:08 AM »
Synchronization between the video and gps is difficult.  If you can determine the exact time of each video frame, you can use the exiftool -geotag and -geosync options to read the GPX file and geotag the extracted frames.  The problem is determining the proper -geosync time.  If you just need to be within a second, this should be easy.  But if you need sub-second accuracy, you'll need to devise some sort of calibration scheme.  All you need is one frame that was taken at a unique, known location to calibrate the entire video (assuming clock drift is small).  I did this for one of my videos by finding a picture when we passed a known landmark at high speed.

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

haimat

  • Newbie
  • *
  • Posts: 2
Re: Generating/writing GPS data from MP4 file into video frames
« Reply #2 on: June 03, 2021, 10:17:15 AM »
Hey Phil,

thank you very much for your quick reply. I could extract all frames from the video into a folder via ffmpeg. But I guess then each of these images would need the correct exif information within them in order for ExifTool to work correctly. What are the requirements here so that the -geotag and -geosync options work correctly - I guess each image needs the DateTimeOriginal exif flag, right? Is there anything else I need to take care of when extracting the video frames into images?

StarGeek

  • Global Moderator
  • ExifTool Freak
  • *****
  • Posts: 6493
Re: Generating/writing GPS data from MP4 file into video frames
« Reply #3 on: June 03, 2021, 12:31:27 PM »
The DateTimeOriginal tag would work by default but any time tag would work by explicitly setting the Geotime tag (see Geotime on the Geotagging with ExifTool page).
Troubleshooting hints:
* Did you read FAQ #3 and use the command listed there?
* When posting, include your OS, Exiftool version, and type of file you're processing (MP4, JPG, etc).
* Double all percent signs (%) in a Windows batch file.