Skip to content

Instantly share code, notes, and snippets.

@ucnv
Created October 30, 2013 07:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ucnv/7228315 to your computer and use it in GitHub Desktop.
Save ucnv/7228315 to your computer and use it in GitHub Desktop.
require 'image_size'
require 'cocaine'
infile = ARGV.shift # must be png
size = ImageSize.path infile
png_yuv = 'tmp/' + File.basename(infile) + '.yuv'
cmd = Cocaine:: CommandLine.new 'convert', 'png::in -sampling-factor 4:2:0 -depth 8 :out'
cmd.run in: infile, out: png_yuv
yuv_hevc = png_yuv + '.hevc'
cmd = Cocaine::CommandLine.new 'TAppEncoder', '-c :config -wdt :width -hgt :height -i :in -fr 50 -f 1 --SEIDecodedPictureHash 0 -b :bitstream'
cmd.run config: 'encoder_intra_main.cfg', width: size.width.to_s, height: size.height.to_s, in: png_yuv, bitstream: yuv_hevc
v = open(yuv_hevc).read.b
hevc_glitched = yuv_hevc + '.g'
open(hevc_glitched, 'w') do |w|
v[rand(v.size/20)] = ('a'..'z').to_a.shuffle.first
w.write v
end
glitched_yuv = hevc_glitched + '.yuv'
cmd = Cocaine::CommandLine.new 'TAppDecoder', '-b :in -o :out' # this TAppDecoder is modified to avoid the checksum and some assertions
cmd.run in: hevc_glitched, out: glitched_yuv
yuv_png = glitched_yuv + '.png'
cmd = Cocaine::CommandLine.new 'convert', '-sampling-factor 4:2:0 -depth 8 -size :widthx:height yuv::in :out'
cmd.run width: size.width.to_s, height: size.height.to_s, in: glitched_yuv, out: yuv_png
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment