title: How to read the bit rate information from a .mov video file header (QuickTime File Format)?
body: <p>I've been trying to read some values out of the metadata of a .mov file (QuickTime File Format) with limited success. I've been using the following link as a reference:</p>
  
  <blockquote>
    <p><a href="https://developer.apple.com/library/mac/documentation/QuickTime/QTFF/QTFFPreface/qtffPreface.html#//apple_ref/doc/uid/TP40000939-CH202-TPXREF101" rel="nofollow">Introduction to QuickTime File Format Specification</a>   </p>
  </blockquote>
  
  <p>I've managed to correctly locate and read out/calculate the media duration, but I can't seem to find which Atom the Bit Rate information is stored in. (Atoms are the internal blocks of metadata inside the file). </p>
  
  <p>If anyone can point me to the correct Atom to read, I'll be alright reading it... I just can't seem to find it in the documentation even. "Bit Rate" is only mentioned a couple of times in the whole document.</p>
  
  <hr>
  
  <p>UPDATE >>></p>
  
  <p>Going by the very limited information provided below by @szatmary, I have parsed the <em>Sample Size Atom</em> and the <em>Time to Sample Atom</em> from the relevant <em>Track Atom</em>, but am getting some bizarre values. For example, I keep getting a <em>Sample Size</em> value of <code>1</code> (when reading from multiple different single video .mov files with constant <em>Bit Rates</em>). The related documentation (from the above link) says:</p>
  
  <blockquote>
    <p>Sample size<br>
    A 32-bit integer specifying the sample size. If all the samples are the same size, this field contains that size value. If this field is set to 0, then the samples have different sizes, and those sizes are stored in the sample size table. </p>
  </blockquote>
  
  <p>So the field has the value of <code>1</code>, which means that all samples have the same size, and the <em>Number of entries</em> [in the <em>Sample Size Table</em>] field matches that of the <em>Sample Count</em> field in the single entry of the <em>Time to Sample Table</em> (some very large number). The documentation states this:</p>
  
  <blockquote>
    <p>... if a video media has a constant frame rate, this table would have one entry and the count would be equal to the number of samples. </p>
  </blockquote>
  
  <p>So the video has a constant Bit Rate. However, when reading the size entries from the <em>Sample Size Table</em>, they are all different and non-sensical... some are 0, while others are very large numbers up to around 40000. Why are they different if the video has a constant Bit Rate, or should I not be reading them in this case?</p>
  
  <p>Another issue that I have found is that the single entry in the <em>Time to Sample Table</em> of the <em>Time to Sample Atom</em> has the following values:</p>
  
  <blockquote>
    <p>Sample Count: <em>some very large number</em> (expected)<br>
    Sample Duration: 1</p>
  </blockquote>
  
  <p>Unfortunately the documentation (from the above link) is very light here:</p>
  
  <blockquote>
    <p>Time-to-sample table<br>
    A table that defines the duration of each sample in the media. Each table entry contains a count field and a duration field.</p>
  </blockquote>
  
  <p>So what units do these <code>1</code> values use (<em>Sample Duration</em> &amp; <em>Sample Size</em>)?</p>
  
  <p>Any further help with calculating the correct Bit Rate would be greatly appreciated. Please note that I have been taking the <em>Big-Endian-ness</em> of the file into consideration and reversing the bytes of each field value before reading them.</p>
  
  <hr>
  
  <p>UPDATE 2 >>> </p>
  
  <p>I have managed to work out that the Sampling Rate is calculated like this:</p>
  
  <blockquote>
    <p>Media Duration = Duration / Timescale (from the <em>Movie Header Atom</em> or <em>Track Header Atom</em>) 
    Sampling Rate = Sample Count (from the <em>Time-to-Sample Atom</em>) / Media Duration </p>
  </blockquote>
  
  <p>I just need to crack the <em>Bit Rate</em> now and further help is needed.</p>