diff 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
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/split-aac.py	Sat Mar 07 18:04:10 2026 -0500
@@ -0,0 +1,28 @@
+# We want to split the files, preserving their original compression with as few possible clicks.
+# This means we have to align all of our track offsets as frames.
+
+import sys
+
+
+def get_closest_aligned_time(target_time: float, sample_rate: float) -> int:
+	# Convert target time into an exact amount of samples first.
+	# We obviously can't have a fraction of a sample.
+	samples = int(round(target_time * sample_rate))
+
+	# Round to the nearest frame multiple. Note that AAC frames are
+	# *usually* (but not always) 1024 samples in size.
+	frames = samples - samples % 1024
+
+	return frames / sample_rate
+
+
+# sample rate is first argument
+sample_rate = float(sys.argv[1])
+
+# rest of the arguments are the times to align.
+# Hopefully giving these values as microseconds will help
+# ffmpeg realize it should cut along frame boundaries.
+for i in sys.argv[2:]:
+	x = get_closest_aligned_time(float(i), sample_rate)
+	print("%f\n" % x, end="")
+	print("%f," % x, end="")