A small utility to extract gpx track from StreetGuardian video, merge video clips, generate subtitles and more.

rollei

New Member
Joined
Jul 29, 2023
Messages
2
Reaction score
0
Location
Beijing
Country
China
I wrote a small program called stgrack for processing StreetGuardian videos. It has the following main capabilities:
  • Extract GPX tracks from videos based on user-specified clip range
  • Concatenate multiple video clips selected by user into one long video
  • Generate subtitles with speed and motion info for the concatenated video in .ssa or .srt format
  • output gps records in txt format for the merged video, including seconds from the start of the video, timestamp, latitude and longitude coordinates, and motion direction.
 

Attachments

  • sgtrack-macos-x64.zip
    843.6 KB · Views: 1
  • sgtrack-macos-arm64.zip
    781.7 KB · Views: 1
  • sgtrack-windows-x64.zip
    825.6 KB · Views: 1
sgtrack has two subcommands, scan and range. The scan subcommand scans StreetGuardian footage to help figure out which journeys the clips on the TF card contain, and the start and end points of each journey represented by which files. This facilitates further processing using the range subcommand.

The scan subcommand is used like: sgtrack scan [directory] [minutes per clip]

If no directory or minutes per clip are specified, it will scan the current directory and assume 2 minutes per clip (my own SGGCX2PRO+ is set to 2 minutes per clip).

For example, if the StreetGuardian TF card directory is F:, dir F:/d gives:

[.] 2021_0127_131529_230.MP4 2021_0302_155330_461.MP4
[..] 2021_0127_131728_231.MP4 2021_0302_155530_462.MP4
2021_0123_150519_001.MP4 2021_0127_131928_232.MP4 2021_0302_155730_463.MP4
2021_0125_070115_002.MP4 2021_0127_132128_233.MP4 2021_0302_155930_464.MP4
2021_0125_070316_003.MP4 2021_0127_132328_234.MP4 2021_0302_160130_465.MP4
2021_0125_071706_004.MP4 2021_0127_132528_235.MP4 2021_0302_160329_466.MP4
...
...
...
2021_0127_124145_226.MP4 2021_0302_154530_457.MP4 2021_0304_164513_688.MP4
2021_0127_124345_227.MP4 2021_0302_154730_458.MP4 2021_0304_164713_689.MP4
2021_0127_124545_228.MP4 2021_0302_154930_459.MP4
2021_0127_124745_229.MP4 2021_0302_155130_460.MP4
689 Files 183,053,229,351 Bytes


The sgtrack scan command can discern which journeys these files belong to:
sgtrack scan f:\

It outputs:

2021_0123_150519_001.MP4 1 1 slices 8M 2021-01-23 (Sat) 15:05:19 - 15:05:19
2021_0125_070115_002.MP4 3 2 slices 392M 2021-01-25 (Mon) 07:01:15 - 07:03:16
2021_0125_071706_004.MP4 37 34 slices 8631M 2021-01-25 (Mon) 07:17:06 - 08:23:06
2021_0125_140905_038.MP4 38 1 slices 1M 2021-01-25 (Mon) 14:09:05 - 14:09:05
2021_0125_141547_039.MP4 72 34 slices 8616M 2021-01-25 (Mon) 14:15:47 - 15:21:50
2021_0125_200003_073.MP4 93 21 slices 5410M 2021-01-25 (Mon) 20:00:03 - 20:40:02
2021_0126_074547_094.MP4 124 31 slices 7926M 2021-01-26 (Tue) 07:45:47 - 08:45:50
2021_0126_114903_125.MP4 134 10 slices 2352M 2021-01-26 (Tue) 11:49:03 - 12:07:04
2021_0126_125614_135.MP4 194 60 slices 15464M 2021-01-26 (Tue) 12:56:14 - 14:54:13
2021_0127_113942_195.MP4 229 35 slices 9113M 2021-01-27 (Wed) 11:39:42 - 12:47:45
2021_0127_131529_230.MP4 243 14 slices 3407M 2021-01-27 (Wed) 13:15:29 - 13:41:28
2021_0127_145943_244.MP4 246 3 slices 604M 2021-01-27 (Wed) 14:59:43 - 15:03:43
2021_0226_193431_247.MP4 270 24 slices 6006M 2021-02-26 (Fri) 19:34:31 - 20:20:13
2021_0226_202326_271.MP4 271 1 slices 1M 2021-02-26 (Fri) 20:23:26 - 20:23:26
2021_0226_202638_272.MP4 272 1 slices 28M 2021-02-26 (Fri) 20:26:38 - 20:26:38
2021_0228_141632_273.MP4 279 7 slices 1794M 2021-02-28 (Sun) 14:16:32 - 14:28:34
2021_0228_143039_280.MP4 280 1 slices 13M 2021-02-28 (Sun) 14:30:39 - 14:30:39
2021_0228_143426_281.MP4 285 5 slices 1229M 2021-02-28 (Sun) 14:34:26 - 14:42:25
2021_0301_072623_286.MP4 289 4 slices 800M 2021-03-01 (Mon) 07:26:23 - 07:32:26
2021_0301_073451_290.MP4 319 30 slices 7544M 2021-03-01 (Mon) 07:34:51 - 08:32:54
2021_0301_200305_320.MP4 334 15 slices 3827M 2021-03-01 (Mon) 20:03:05 - 20:31:08
2021_0301_210934_335.MP4 355 21 slices 5279M 2021-03-01 (Mon) 21:09:34 - 21:49:33
2021_0302_110721_356.MP4 415 60 slices 15474M 2021-03-02 (Tue) 11:07:21 - 13:05:21
2021_0302_142328_416.MP4 467 52 slices 13507M 2021-03-02 (Tue) 14:23:28 - 16:05:29
2021_0303_104823_468.MP4 489 22 slices 5698M 2021-03-03 (Wed) 10:48:23 - 11:30:24
2021_0303_163141_490.MP4 513 24 slices 6087M 2021-03-03 (Wed) 16:31:41 - 17:17:42
2021_0304_101849_514.MP4 555 42 slices 10926M 2021-03-04 (Thu) 10:18:49 - 11:40:50
2021_0304_115842_556.MP4 587 32 slices 8138M 2021-03-04 (Thu) 11:58:42 - 13:00:42
2021_0304_130528_588.MP4 612 25 slices 6380M 2021-03-04 (Thu) 13:05:28 - 13:53:29
2021_0304_140719_613.MP4 613 1 slices 216M 2021-03-04 (Thu) 14:07:19 - 14:07:19
2021_0304_141024_614.MP4 645 32 slices 8266M 2021-03-04 (Thu) 14:10:24 - 15:12:25
2021_0304_152112_646.MP4 689 44 slices 11421M 2021-03-04 (Thu) 15:21:12 - 16:47:13


The first column is the starting filename of each journey, the second column is the sequence number of the last clip in the journey, the sequence number is the 3 digits before .MP4 in each filename, which facilitates quickly selecting the range to process in the range subcommand. The third column is the number of clips in the journey, the fourth column is the total disk space of the journey. The remaining columns are clearly date and start/end times. Note the last column is the start time of the last clip, not the end time.
Looking at the output, the starting filename of the first journey is 2021_0123_150519_001.MP4, it contains only 1 clip, so its end clip is the same as the start, with sequence number 001, hence 1 is displayed. The starting filename of the third journey is 2021_0125_071706_004.MP4, its last clip sequence number is _037, and it contains a total of 34 clips.

In addition to specifying a directory, sgtrack scan can also specify the recording length of each clip. It actually relies on this length to discern each journey, assuming clips separated by more than the specified length belong to different journeys. As mentioned earlier, if not specified, it defaults to 2 minutes. sgtrack scan only superficially analyzes the file list without looking into each file, so identifying journeys completely depends on the start times and length settings of the clips. If the per clip length is not set correctly, the output will not be accurate.

Now we use the sgtrack range subcommand to extract a GPX track for the third journey:
sgtrack range 2021_0125_071706_004.MP4 37 -g travel

This will generate a track file travel.gpx in the current directory.

The usage of sgtrack range is:
sgtrack range start_filename end_clip_seq output_filename [-output_format]

If the 3rd, 4th and 5th journeys identified by sgtrack scan are actually one journey separated by parking breaks, it's easy to merge them:
sgtrack range 2021_0125_071706_004.MP4 72 -g travel

The sequence number of the last clip of the fifth journey is _072, so we just need to specify 72 as the end sequence number.


sgtrack range supports the following output options:

-m, --mp4 output MP4
-g, --gpx output GPX
-s, --ssa output SSA
-t, --txt output TXT
-r, --srt output SRT
-c, --compass output Compass data for Davinci Resolve


-g and --gpx are equivalent, and they can be combined, e.g. -mgr , which is equivalent to --mp4 --gpx --srt.


The output filename does not need a suffix specified. Any suffix provided by the user will be ignored. sgtrack will append the appropriate suffix based on the output option.

Note: MP4 output with -mp4 does not contain audio, because my SGGCX2PRO+ never enables audio recording. However, sgtrack has a hidden option -f (--ffmpeg) which will generate video with audio, but requires ffmpeg installed, and will be slower. I'm the sole user of sgtrack for a long time, so it's not surprising if this option does not work well :p

-c / --compass is designed for myself to generate a sequence of numbers for controlling the compass effect overlay in Davinci Resolve.

Note the direction angle generated by sgtrack is the instantaneous moving direction of the StreetGuardian device, not the heading of the vehicle. It coincides with the vehicle heading only when the vehicle is moving straight forward. This angle is referenced to true north, and represents the instant direction output by the StreetGuardian GPS, calculated from Doppler shifts in the satellite signals.

The reason for outputting two subtitle formats is that .ssa is easy to use in media players, while .srt is more easily accepted by video editing software.


When using -r and -c together, the .srt subtitles will only show speed and direction (without ESWN legends), while .srt with -r and -c will only display latitude and longitude.
 
Back
Top