juanmcasillas / gopro2gpx

Parse the gpmd stream for GOPRO moov track (MP4) and extract the GPS info into a GPX (and kml) file.
GNU General Public License v3.0
194 stars 49 forks source link

Fix binary file generation #36

Closed stakita closed 1 year ago

stakita commented 1 year ago

This PR fixes an issue related to the introduction of multiple input file handling (#33). With the introduction of multiple input files, the output binary file gets overwritten multiple times as the same output file name is used for all input files in the stream.

The core issue is that the binary file generation is done as a side effect of the readFrom... methods in the Parser class. This class in the past used the output file information for the target bin file, however, this doesn't really work once we have to generate multiple bin files as the output information doesn't correlate to the input file set as it did when there was just one input file. The fact that the Parser class implicitly generates binaries as a side effect makes a bit awkward as input file information isn't available in this class.

To resolve this, this PR reorganizes the top-level loop in gopro2gpx.main_core to do the following:

  1. Pull the binary generation up to the top-level allowing for the binary generation to be based on input file information rather than output file specification
  2. Allow for all reading of input files to happen prior before any GPS generation occurs, aggregating the data into a single KLV block. This allows the data to be processed as a single contiguous block, which is more natural way of processing this data. This also eliminates the need to pass any information between invocations of BuildGPSPoints (e.g start_time) when processing multiple files.

In the gpmf.py module, the dependencies on the config.py class had been reduced to just the verbose variable, so this has been made an explicit parameter to the internals of this module. This should simplify testing. Inside the gpmf.py module, the Parser class has been broken out into the following code:

The README.md file and tests have been updated to match these changes