Skip to content

Instantly share code, notes, and snippets.

@ucnv
Created July 28, 2009 09:28
Show Gist options
  • Save ucnv/157040 to your computer and use it in GitHub Desktop.
Save ucnv/157040 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
# Usage: ruby datamoshing-mp4.rb input.mp4 > output.mp4
def uint32 s
s.unpack("C4").reverse.each_with_index.inject(0) { |r, v| r += v[0] << (v[1] * 8) }
end
input = ARGV.shift
data = File.open(input).read
s = data.split(/([\s\S]{4}stss[\s\S]{8})/)
points = uint32(s[1].slice(12, 4)).times.collect do |i|
uint32(s[2].slice(i * 4, 4))
end
s = data.split(/([\s\S]{4}stco[\s\S]{8})/)
offsets = uint32(s[1].slice(12, 4)).times.collect do |i|
uint32(s[2].slice(i * 4, 4))
end
points.slice!(0) # save the first keyframe
points.each do |p|
b = offsets[p - 1]
e = offsets[p]
head = data.slice(0, b)
body = "\000" * (e - b)
tail = data.slice(e, data.size)
data = head + body + tail
end
print data
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment