0

I'm trying to read the GPS data from a GoPro camera, and the "tracks" method on AVAsset only lists three tracks, while there are actually five, according to ffmpeg.

What can I do to see all the tracks? I'm particularly interested in the GPMF track that contains GPS data.

Here's what AVAsset produces:

    NSArray *trackA = asset.tracks;
    index = 0;
    for (AVAssetTrack *track in trackA) {
        XLog(@"%ld. trackID = %d", index, track.trackID);
        XLog(@"%ld. mediaType = %@", index, track.mediaType);
        XLog(@"%ld. data size = %@", index, NSStringFromSize(track.naturalSize));
        XLog(@"___________________________");
      index++;
    }

AVAsset creation date = 2022-11-13 13:33:57 +0000
AVAsset metadata = 2022-11-13 13:33:57 +0000
0. trackID = 1
0. mediaType = vide
0. data size = {3840, 2160}
___________________________
1. trackID = 2
1. mediaType = soun
1. data size = {0, 0}
___________________________
2. trackID = 3
2. mediaType = tmcd
2. data size = {0, 0}

while here is what ffmpeg produces.

ffmpeg -i GX010045.MP4

ffmpeg version 5.1.2 Copyright (c) 2000-2022 the FFmpeg developers
  built with Apple clang version 14.0.0 (clang-1400.0.29.202)

...

Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'GX010045.MP4':
  Metadata:
    major_brand     : mp41
    minor_version   : 538120216
    compatible_brands: mp41
    creation_time   : 2022-11-13T13:33:57.000000Z
    location        : +38.0357-122.5819/
    location-eng    : +38.0357-122.5819/
    firmware        : HD9.01.01.72.00
  Duration: 00:08:52.54, start: 0.000000, bitrate: 60206 kb/s
  Stream #0:0[0x1](eng): Video: hevc (Main) (hvc1 / 0x31637668), yuvj420p(pc, bt709), 3840x2160 [SAR 1:1 DAR 16:9], 59941 kb/s, 59.94 fps, 59.94 tbr, 60k tbn (default)
    Metadata:
      creation_time   : 2022-11-13T13:33:57.000000Z
      handler_name    : GoPro H.265
      vendor_id       : [0][0][0][0]
      encoder         : GoPro H.265 encoder
      timecode        : 13:33:09:07
  Stream #0:1[0x2](eng): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 189 kb/s (default)
    Metadata:
      creation_time   : 2022-11-13T13:33:57.000000Z
      handler_name    : GoPro AAC  
      vendor_id       : [0][0][0][0]
      timecode        : 13:33:09:07
  Stream #0:2[0x3](eng): Data: none (tmcd / 0x64636D74) (default)
    Metadata:
      creation_time   : 2022-11-13T13:33:57.000000Z
      handler_name    : GoPro TCD  
      timecode        : 13:33:09:07
  Stream #0:3[0x4](eng): Data: bin_data (gpmd / 0x646D7067), 48 kb/s (default)
    Metadata:
      creation_time   : 2022-11-13T13:33:57.000000Z
      handler_name    : GoPro MET  
  Stream #0:4[0x5](eng): Data: none (fdsc / 0x63736466), 13 kb/s (default)
    Metadata:
      creation_time   : 2022-11-13T13:33:57.000000Z
      handler_name    : GoPro SOS  
At least one output file must be specified

Steve Mykytyn
  • 73
  • 2
  • 7
  • 1
    You might have to search the file bytes yourself (unless Google search has an alternate library you can import into your app). Load the file into your app as an array and search each slot for the expected values. Find what is "expected values" by checking your short testing MP4 (eg: record 5 seconds), using a **hex editor**... If you want to do it yourself I can help you but you need to: **(1)** Put a test 5 second file online (you got a website? Dropbox? Google Drive? or any online storage?).. **(2)** You can use Arrays and While loops. – VC.One Mar 15 '23 at 10:28
  • Thanks. I am writing code to inspect the mp4 directly, but loading it into memory is not a good option. NSFileHandle (in Swift FileHandle) lets you read a chunk of bytes from selected offsets within the file as needed. That way I can find and process the other tracks without incurring a huge memory footprint. – Steve Mykytyn Mar 17 '23 at 17:03
  • _"AVAsset only lists three tracks, while there are actually five"_ We need a sample file. Can you record a few seconds (5 or less) so we have a 5-track MP4 bytes to study? You can record a wall or cover the lens or such... – VC.One Mar 17 '23 at 17:36

1 Answers1

0

AVAsset simply reports tracks that Apple is interested in. You have to write an .mp4 parser to find the tracks that other providers add (like GoPro).

Steve Mykytyn
  • 73
  • 2
  • 7