Script to extract GPS Data from Novatek MP4

SergeiF

Active Member
Joined
Dec 20, 2015
Messages
121
Reaction score
97
Country
New Zealand
As per my thread: https://dashcamtalk.com/forum/threads/a119-first-impressions.20258/ I needed a tool to extract the GPS data from MP4 files recorded by A119 camera.
The tool needed to be linux friendly, and as far as I knew there was none.

I have finished the script that exports the GPS Data from Novatek MP4 files.
At this stage it is very crude.
I only tested it in SE hemisphere, and only with A119 produced files (might work with A118 MOVs and possibly with other Novatek powered cameras). Also only tested in linux, but it should work in any environment that has python (it requires os,sys, struct and getopt libraries).

The script extracts the data in GPX format. Initially I wanted to use KML format (mostly out of ignorance), but after studying it I found it somewhat restricted (specifically there is no provision to store instantaneous speed for each waypoint).

The GPX format took a while to get it right (if it is right ;))... The MP4 container required a lot reading to understand internal structure. I wander why manufacturers use proprietary containers and not something like mkv.

I possibly screwed up and did everything/something in completely wrong way, but hey, you are welcome to do it better ;).

Please note: I am no programmer!

Here is the script:
http://sergei.nz/files/nvtk_mp42gpx.py

Future stuff:
better error handling.
test with other mapping software (only tested with google maps).
testing with other Novatek powered cameras.
testing in other hemispheres.
multiple input files (for continuous single output).

Thanks to @jokiin, @viofo and @traveler for pointing me in the right direction.
 
Last edited:

fubduck

New Member
Joined
May 15, 2016
Messages
29
Reaction score
17
Country
United States
Dash Cam
1xA119S,2xA119,Mobius,TT-CD05x2,TT-CD04,Yi Dashcam
Thanks for sharing. I'll check it out this weekend. Does it remove the GPS data from the video file or just make a copy of it and put it in a separate file?
 
OP
S

SergeiF

Active Member
Joined
Dec 20, 2015
Messages
121
Reaction score
97
Country
New Zealand
It simply extracts the GPS data without touching the original file. It puts into GPX formatted file that you specify as argument.
To remove the GPS data, all you need to do is repack the container.
You can use something like ffmpeg:
Code:
ffmpeg -i INPUT.MP4 -acodec copy -vcodec copy OUTPUT.MP4
 

fubduck

New Member
Joined
May 15, 2016
Messages
29
Reaction score
17
Country
United States
Dash Cam
1xA119S,2xA119,Mobius,TT-CD05x2,TT-CD04,Yi Dashcam
awesome thanks for that info.
 

Mtz

Well-Known Member
Joined
Nov 15, 2012
Messages
3,646
Reaction score
1,991
Location
Nice place
Country
Romania
Dash Cam
Viofo A119. WR1. SGGCX2. GitUp.
OK, but how to use it?

enjoy,
Mtz
 
OP
S

SergeiF

Active Member
Joined
Dec 20, 2015
Messages
121
Reaction score
97
Country
New Zealand
In Linux you should already have python installed so either run it like this (in terminal):
Code:
./nvtk_mp42gpx.py -i $INPUT_VIDEO.MP4 -o $GPS_TRACK.GPX
or like this:
Code:
 python nvtk_mp42gpx.py -i $INPUT_VIDEO.MP4 -o $GPS_TRACK.GPX
Where $INPUT_VIDEO.MP4 is replaced by your video file you want to extract the GPS data from, and $GPS_TRACK.GPX is your file name of choice of GPX file (the result). The -i is for input file, -o is for output file, and -f is for overwriting output file.
Running from OSX is pretty much the same as Linux expect you might need to install python. I am 99% certain the script will work in OSX (as long as you have python installed).

Note: the target is python2.7 but I don't think there should be any problems running in python3.

In Windows? Why would you use such crappy OS ;)? You will need to install python and I think you can run the script from abortion of shell that is the cmd.exe in similar fashion:
Code:
 python.exe nvtk_mp42gpx.py -i $INPUT_VIDEO.MP4 -o $GPS_TRACK.GPX
As far as I know there is nothing Unix/Linux specific in my script so it should run OK in a bastard of OS that is Windows.

I hope that helps.
 

Mtz

Well-Known Member
Joined
Nov 15, 2012
Messages
3,646
Reaction score
1,991
Location
Nice place
Country
Romania
Dash Cam
Viofo A119. WR1. SGGCX2. GitUp.
Most of widows users like to have a GUI. I was searching on internet about how to obtain a GUI for python, there is some method but not created the desired GUI.
I am sure you made the hardest work and GUI creation is more simple, but you will help us with some GUI. Is like having a Christmas Tree: is hard to grow it, but mounting in a room just the tree is like not having Christmas.
I hope you understand what I want to say.

Of course the best possible hack is to make Registrator Viewer working also with GPS with new novatek MP4.
Another interesting thing is if is possible to create a subtitle file, SRT for example, so when watching the video to see also the subtitle.

enjoy,
Mtz
 
OP
S

SergeiF

Active Member
Joined
Dec 20, 2015
Messages
121
Reaction score
97
Country
New Zealand
Most of widows users like to have a GUI. I was searching on internet about how to obtain a GUI for python, there is some method but not created the desired GUI.
I am sure you made the hardest work and GUI creation is more simple, but you will help us with some GUI. Is like having a Christmas Tree: is hard to grow it, but mounting in a room just the tree is like not having Christmas.
I hope you understand what I want to say.

Of course the best possible hack is to make Registrator Viewer working also with GPS with new novatek MP4.
Another interesting thing is if is possible to create a subtitle file, SRT for example, so when watching the video to see also the subtitle.

enjoy,
Mtz
Actually bolting on GUI to that script is not as simple. For starters GUI has a lot of baggage (in form of libraries and frameworks). Choosing correct GUI to make it cross platform is even more complicated.
For cross platform anything Windows specific goes out of the window.
So the choices are QT, GTK, wxWidgets etc. All of them are fairly large frameworks and require additional libraries/dependencies. My tiny 5.7kByte script will become multi megabyte monster if you include all the libs required for GUI.

For one task scripts (like above) it is best not to have a GUI at all. All it takes input and output file as parameter, which you will still have to type or pick from file picker widget (slow!) if it was in GUI.

For example you could use a small bash loop to automate my script, or call it from a web page on your NAS, or run it from a headless rPi. If it was GUI app none of that would be possible without purposely building in CLI mode.

GUI is one of the reason why Windows sucks under the hood (those bright sparks at Microsoft run the window manager at ring 0!).
As Linux engineer I can manage hundreds, thousands or even tens of thousands Linux machines, simply because of power of shell (no, not powershell ;)) combined with SSH. Doing same on windows requires some custom solution that either has to be written in house or bought as 3rd party tool, and still will require a large team of windows "engineers" to support it.

When I wrote the script the functionality of Registrator Viewer was last thing on my mind. The main reason was creating a tool to extract GPS data in a portable format for Linux. Sometimes I want to embed data in google maps and there was nothing out there that could do that.
As for Registrator Viewer, perhaps you can contact them regarding the support of new Novatek chipsets? If I figured it out, then I am sure it would be trivial for them (since they already build support for previous versions).

Think of this script as a lego block, by itself is nothing significant but combining it with other lego blocks the possibilities are endless.

Going back to the GUI for the script, obviously it will look something like this:

Code:
.----------------------------------[?][_][X].
|  [ input file            ]  [browse...]   |
|  [ output file           ]  [browse...]   |
|  [ Extract .. ]                [ Quit ]   |
' ------------------------------------------'
I might look into the simplest (ugly) way of achieving that in cross-platform fashion...
 

Mtz

Well-Known Member
Joined
Nov 15, 2012
Messages
3,646
Reaction score
1,991
Location
Nice place
Country
Romania
Dash Cam
Viofo A119. WR1. SGGCX2. GitUp.
Thank you for the reply!
I remember some programs are without a GUI but easy to use just because of using drag&drop over that file.
With your idea is not possible to use drag&drop? Is even more simple than working with a GUI.

enjoy,
Mtz
 

Sutton

Active Member
Joined
Aug 31, 2016
Messages
712
Reaction score
228
Country
Canada
Dash Cam
One SG9665gc.. Two Viofo A119.. Three A119S
As per my thread: https://dashcamtalk.com/forum/threads/a119-first-impressions.20258/ I needed a tool to extract the GPS data from MP4 files recorded by A119 camera.
The tool needed to be linux friendly, and as far as I knew there was none.

I have finished the script that exports the GPS Data from Novatek MP4 files.
At this stage it is very crude.
I only tested it in SE hemisphere, and only with A119 produced files (might work with A118 MOVs and possibly with other Novatek powered cameras). Also only tested in linux, but it should work in any environment that has python (it requires os,sys, struct and getopt libraries).

The script extracts the data in GPX format. Initially I wanted to use KML format (mostly out of ignorance), but after studying it I found it somewhat restricted (specifically there is no provision to store instantaneous speed for each waypoint).

The GPX format took a while to get it right (if it is right ;))... The MP4 container required a lot reading to understand internal structure. I wander why manufacturers use proprietary containers and not something like mkv.

I possibly screwed up and did everything/something in completely wrong way, but hey, you are welcome to do it better ;).

Please note: I am no programmer!

Here is the script:
http://sergei.nz/files/nvtk_mp42gpx.py

Future stuff:
better error handling.
test with other mapping software (only tested with google maps).
testing with other Novatek powered cameras.
testing in other hemispheres.
multiple input files (for continuous single output).

Thanks to @jokiin, @viofo and @traveler for pointing me in the right direction.
Never was able to view any type of map with the A119 plus GPS I tested it with a few different viewers and all I ever got was the MPH and the coordinates But with my SG I do get mapping I don't think the A119 is capable to show any mapping
 

jokiin

Well-Known Member
Manufacturer
Joined
Jan 27, 2013
Messages
47,645
Reaction score
26,126
Location
Sydney, Australia ~ Shenzhen, China
Country
Australia
Dash Cam
Too many ¯\_(ツ)_/¯
As for Registrator Viewer, perhaps you can contact them regarding the support of new Novatek chipsets? If I figured it out, then I am sure it would be trivial for them (since they already build support for previous versions).
.
had the developer of Registrator Viewer not been killed in an accident last year I'm sure the new models would have already been supported long ago
 
OP
S

SergeiF

Active Member
Joined
Dec 20, 2015
Messages
121
Reaction score
97
Country
New Zealand
Thank you for the reply!
I remember some programs are without a GUI but easy to use just because of using drag&drop over that file.
With your idea is not possible to use drag&drop? Is even more simple than working with a GUI.

enjoy,
Mtz
You realize that you can drag and drop into CLI, right? Even craptastic cmd.exe supports it:
 
OP
S

SergeiF

Active Member
Joined
Dec 20, 2015
Messages
121
Reaction score
97
Country
New Zealand
had the developer of Registrator Viewer not been killed in an accident last year I'm sure the new models would have already been supported long ago
I am sorry to hear that :(
 
OP
S

SergeiF

Active Member
Joined
Dec 20, 2015
Messages
121
Reaction score
97
Country
New Zealand
Never was able to view any type of map with the A119 plus GPS I tested it with a few different viewers and all I ever got was the MPH and the coordinates But with my SG I do get mapping I don't think the A119 is capable to show any mapping
I don't quite follow... The A119 has sufficient GPS information to support mapping.
 

jokiin

Well-Known Member
Manufacturer
Joined
Jan 27, 2013
Messages
47,645
Reaction score
26,126
Location
Sydney, Australia ~ Shenzhen, China
Country
Australia
Dash Cam
Too many ¯\_(ツ)_/¯
I don't quite follow... The A119 has sufficient GPS information to support mapping.
I'd say his issues are just with the player, no support in Registrator Viewer and Dashcam Viewer seems to be a problem with this model for some users, not really any other option out there
 
OP
S

SergeiF

Active Member
Joined
Dec 20, 2015
Messages
121
Reaction score
97
Country
New Zealand
I'd say his issues are just with the player, no support in Registrator Viewer and Dashcam Viewer seems to be a problem with this model for some users, not really any other option out there
Right. Interesting there is no opensource viewer (unless I am misinformed). I guess dash cams are not very popular in general.

So is regstrator viewer is abandonware now? Or some 3rd party picked it up?
 

jokiin

Well-Known Member
Manufacturer
Joined
Jan 27, 2013
Messages
47,645
Reaction score
26,126
Location
Sydney, Australia ~ Shenzhen, China
Country
Australia
Dash Cam
Too many ¯\_(ツ)_/¯
Right. Interesting there is no opensource viewer (unless I am misinformed). I guess dash cams are not very popular in general.
nothing open source, I think people would gladly pay for something like Registrator Viewer, world wide there's a massive user base of potential customers but I guess no dev with the right skills has seen the need, right skills is the biggest issue I think as this is a lot more complex than most people appreciate, particularly to seamlessly support multiple cameras and all the nuances that come with that

So is regstrator viewer is abandonware now? Or some 3rd party picked it up?
I had someone tell me they were working on it but have yet to see any result, that was six months ago, I've lost count of the developers that have said how simple this is that have yet to produce anything, talk is cheap I guess
 
  • Like
Reactions: Mtz

Mtz

Well-Known Member
Joined
Nov 15, 2012
Messages
3,646
Reaction score
1,991
Location
Nice place
Country
Romania
Dash Cam
Viofo A119. WR1. SGGCX2. GitUp.
I expect that drag and drop the VIDEO.MP4 video over nvtk_mp42gpx.py to result in creating the VIDEO.GPX file.

enjoy,
Mtz
 
OP
S

SergeiF

Active Member
Joined
Dec 20, 2015
Messages
121
Reaction score
97
Country
New Zealand
I was thinking why all these dash cam viewers reinventing the wheel, when instead they can make a VLC plugin for dashcam specific stuff.
This way there is no need to come up with player UI and decoder.
 

jokiin

Well-Known Member
Manufacturer
Joined
Jan 27, 2013
Messages
47,645
Reaction score
26,126
Location
Sydney, Australia ~ Shenzhen, China
Country
Australia
Dash Cam
Too many ¯\_(ツ)_/¯
I was thinking why all these dash cam viewers reinventing the wheel, when instead they can make a VLC plugin for dashcam specific stuff.
This way there is no need to come up with player UI and decoder.
Although it doesn't need VLC I think Registrator Viewer worked in a similar way using existing playback software on the PC, one of the reasons it is able to do what it does in such a lightweight program, finding someone with the required skillset is the challenge
 
Thread starter Similar threads Forum Replies Date
RobTrehy A119 138

Similar threads


Top