I'm trying to find the starting timecode stamp (in HR:MN:SS:FR format) of a broadcast wave chunk format. I believe I'm doing the right calculation, but my numbers are seconds off for some reason.
I'm taking the "time_reference" of the bext chunk (which is the samples from midnight...whatever that means) divided by the sample rate of the audio file (in my case, 44100, but this number is being pulled directly from the audio sample rate of the file using the wavinfo module)
I'm then doing a calculation to get the following string output:
def get_smpte_timecode(wave_file, framerate):
if os.path.exists(wave_file) == False:
return ""
wav = WavInfoReader(wave_file) #using wavinfo
bext = wav.bext
# Get the time_reference from the bext chunk
time_reference = bext.time_reference
totalSeconds = time_reference / wav.fmt.sample_rate
hours = int(totalSeconds / 3600)
minutes = int((totalSeconds / 60) % 60)
seconds = int(totalSeconds % 60)
frames = int((totalSeconds % 1) * framerate)
timecode = '{:02d}:{:02d}:{:02d}:{:02d}'.format(hours, minutes, seconds, frames)
print(timecode)
My framerate is 23.98. For some reason, I have a file that is returning 07:14:26:21, but the actual timecode that spots in pro tools/cubase is 7:14:00:20. I can NOT figure out why the seconds are wrong...and the seconds/frames are wrong across the board on all my other files, but at different rates for each file.
Can anyone add any insight into what I'm doing wrong? Thanks in advance!