Mercurial > codedump
comparison split-aac.py @ 136:da4f7200665f default tip
buncha shit
| author | Paper <paper@tflc.us> |
|---|---|
| date | Sat, 07 Mar 2026 18:04:10 -0500 |
| parents | |
| children |
comparison
equal
deleted
inserted
replaced
| 135:0c3cd90e91f7 | 136:da4f7200665f |
|---|---|
| 1 # We want to split the files, preserving their original compression with as few possible clicks. | |
| 2 # This means we have to align all of our track offsets as frames. | |
| 3 | |
| 4 import sys | |
| 5 | |
| 6 | |
| 7 def get_closest_aligned_time(target_time: float, sample_rate: float) -> int: | |
| 8 # Convert target time into an exact amount of samples first. | |
| 9 # We obviously can't have a fraction of a sample. | |
| 10 samples = int(round(target_time * sample_rate)) | |
| 11 | |
| 12 # Round to the nearest frame multiple. Note that AAC frames are | |
| 13 # *usually* (but not always) 1024 samples in size. | |
| 14 frames = samples - samples % 1024 | |
| 15 | |
| 16 return frames / sample_rate | |
| 17 | |
| 18 | |
| 19 # sample rate is first argument | |
| 20 sample_rate = float(sys.argv[1]) | |
| 21 | |
| 22 # rest of the arguments are the times to align. | |
| 23 # Hopefully giving these values as microseconds will help | |
| 24 # ffmpeg realize it should cut along frame boundaries. | |
| 25 for i in sys.argv[2:]: | |
| 26 x = get_closest_aligned_time(float(i), sample_rate) | |
| 27 print("%f\n" % x, end="") | |
| 28 print("%f," % x, end="") |
