       logger.debug "[mp4:#{@filename}] already paused"
 
   sendVideoPacketsSinceLastKeyFrame: (endSeconds, callback) ->
+    if not @videoTrakBox?  # video trak does not exist
+      callback? null
+      return
+
     # Get next sample number
     stblBox = @videoTrakBox.child('mdia').child('minf').child('stbl')
     sttsBox = stblBox.child('stts') # TimeToSampleBox

    callback?()

  getNumVideoSamples: ->
    sttsBox = @videoTrakBox.find 'stts'
    return sttsBox.getTotalSamples()

  getNumAudioSamples: ->
    sttsBox = @audioTrakBox.find 'stts'
    return sttsBox.getTotalSamples()

  # Returns the timestamp of the last sample in the file
  getLastTimestamp: ->
    numVideoSamples = @getNumVideoSamples()
    sttsBox = @videoTrakBox.find 'stts'
    videoLastTimestamp = sttsBox.getDecodingTime(numVideoSamples).seconds

    numAudioSamples = @getNumAudioSamples()
    sttsBox = @audioTrakBox.find 'stts'
    audioLastTimestamp = sttsBox.getDecodingTime(numAudioSamples).seconds

    if audioLastTimestamp > videoLastTimestamp
      return audioLastTimestamp

      process.stdout.write box.dump 0, 2
    return

  hasVideo: ->
    return @videoTrakBox?

  hasAudio: ->
    return @audioTrakBox?

  getSPS: ->
    avcCBox = @videoTrakBox.find 'avcC'
    return avcCBox.sequenceParameterSets[0]
