title: Exact mp4 framerate (synchronisation issues)
body: <p>I'm writing an audio stretcher to convert audio from 24p to PAL video.
  24p is 24000 / 1001 ~= 23.976 fps
  PAL is exactly 25 fps.</p>
  
  <p>The algorithm I use is very simple. If 'm' is the output sample number and 'n' is the input sample number, then m = floor(f(n + 0.5)), where f is the speed factor. In this case f = 25 / (24000 / 1001) = 1001 / 960 . Yes am basically dropping samples every 30 or so samples, but the audio should be in sync, plus you will a ringing of around 2kHz.</p>
  
  <p>However, in the resulting video, I am out of a/v sync by probably 0.1 - 0.3 secs 1.5 hours into the film.</p>
  
  <p>I tried increase the precision of calculation by using long doubles instead of doubles, but I get the same audio offset. Anyways, this should not be a factor as long as you have you have >9 sig figs becuase there are 345 600 000 samples in a 2hr film sampled at 48kHz.</p>
  
  <p>I don't think I am missing out of some magic syncing data, as when I split the original video into a video and wav file and play them together, they stay completely in sync.</p>
  
  <p>I realised that media containers / streams, probably don't store the frame rate as a rational number, i.e. 24000 / 1001 , (correct me if I am wrong!) they would use a decimal. If so, my speed up factor is incorrect.</p>
  
  <p>I tried getting the fps from various players: ffmpeg 23.98, vlc 23.976023. But I really need to know the <em>exact</em> framerate of the original video. By the looks of it takes it to 5 decimal places (0.2s / 2hrs). I tried plugging in vlc's fps, but I was still out by a bit.</p>
  
  <p>So all in all, is there any way to extract the exact framerate from an mp4 file?</p>
  
  <p>Or an I missing something here like interleaving that keeps the streams in sync.</p>
  
  <p>(The code is here <a href="https://raw.github.com/rhlee/speed-alpha/22c28ddcb357649efd3dedd099e159ff024657fe/speed.c" rel="nofollow noreferrer">https://raw.github.com/rhlee/speed-alpha/22c28ddcb357649efd3dedd099e159ff024657fe/speed.c</a> if anyone is interested.)</p>