Skip to content

Instantly share code, notes, and snippets.

@PythonTryHard
Last active September 19, 2024 12:03
Show Gist options
  • Save PythonTryHard/b38905b41b64786d86010d134d2400e8 to your computer and use it in GitHub Desktop.
Save PythonTryHard/b38905b41b64786d86010d134d2400e8 to your computer and use it in GitHub Desktop.
Bad Apple
(* Set current directory for sanity *)
SetDirectory["E:\\Development\\BadApple\\"];
(* Load the video in *)
badAppleVideo = Import["BadApple.mp4"];
frameList = ColorConvert[VideoFrameList[badAppleVideo, All], "Grayscale"];
(* This is dependent on how many CPU cores and RAM you have. *)
LaunchKernels[16];
ParallelDo[
Export[
(* Filename corresponds to frame number *)
ToString[StringForm["BadApple_f``.flac", i]],
(* Transform frame into an audio file... *)
Audio[
(* ...by treating the image as a spectrogram *)
InverseSpectrogram[
Part[frameList, i],
Automatic,
Automatic,
BartlettHannWindow, (* Seemingly the best window to minimise artefacts *)
MaxIterations -> 10000000
],
"Real64",
SampleRate -> 48000 (* Some weirdo might wanna listen to the thing *)
],
AudioEncoding -> "Integer24"
],
{i, Length[frameList]},
Method -> "FinestGrained"
] // AbsoluteTiming
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment